refactoring and test java