Fixed a bug on JDialog + refactoring + unit tests