@Test public void shouldBeAbleToConvertAnAccountRepresentationIntoAnExistingAccount() { Role role1 = role().save(); Role role2 = role().save(); Role role3 = role().save(); AccountRepresentation representation = AccountDSL.account().withUsername("foo").withPassword("foo").withRoles(roleConversionService.convert(role3)).build(); Account account = account().withRole(role1).withRole(role2).build(); Account updated = accountConversionService.convert(representation, account); assertThat(updated.getId()).isEqualTo(account.getId()); assertThat(updated.getCreated()).isEqualTo(account.getCreated()); assertThat(updated.getUpdated()).isEqualTo(account.getUpdated()); assertThat(updated.getRoles()).hasSize(1); assertThat(updated.getRoles()).contains(role3); assertThat(updated.getUsername()).isEqualTo(account.getUsername()); assertThat(updated.getPassword()).isEqualTo(account.getPassword()); assertThat(updated.isLocked()).isEqualTo(account.isLocked()); }
public AccountRepresentation convert(Account account) { AccountRepresentation representation = new AccountRepresentation(); representation.setId(account.getId()); representation.setCreated(account.getCreated()); representation.setUpdated(account.getUpdated()); representation.setUsername(account.getUsername()); representation.setLocked(account.isLocked()); representation.setRoles(account.getRoles().stream().map(role -> roleConversionService.convert(role)).collect(Collectors.toSet())); return representation; }
AccountConversionService { public AccountRepresentation convert(Account account) { AccountRepresentation representation = new AccountRepresentation(); representation.setId(account.getId()); representation.setCreated(account.getCreated()); representation.setUpdated(account.getUpdated()); representation.setUsername(account.getUsername()); representation.setLocked(account.isLocked()); representation.setRoles(account.getRoles().stream().map(role -> roleConversionService.convert(role)).collect(Collectors.toSet())); return representation; } }
AccountConversionService { public AccountRepresentation convert(Account account) { AccountRepresentation representation = new AccountRepresentation(); representation.setId(account.getId()); representation.setCreated(account.getCreated()); representation.setUpdated(account.getUpdated()); representation.setUsername(account.getUsername()); representation.setLocked(account.isLocked()); representation.setRoles(account.getRoles().stream().map(role -> roleConversionService.convert(role)).collect(Collectors.toSet())); return representation; } @Autowired  AccountConversionService(RoleService roleService, RoleConversionService roleConversionService); }
AccountConversionService { public AccountRepresentation convert(Account account) { AccountRepresentation representation = new AccountRepresentation(); representation.setId(account.getId()); representation.setCreated(account.getCreated()); representation.setUpdated(account.getUpdated()); representation.setUsername(account.getUsername()); representation.setLocked(account.isLocked()); representation.setRoles(account.getRoles().stream().map(role -> roleConversionService.convert(role)).collect(Collectors.toSet())); return representation; } @Autowired  AccountConversionService(RoleService roleService, RoleConversionService roleConversionService); AccountRepresentation convert(Account account); Account convert(AccountRepresentation representation); Account convert(AccountRepresentation representation, Account account); }
AccountConversionService { public AccountRepresentation convert(Account account) { AccountRepresentation representation = new AccountRepresentation(); representation.setId(account.getId()); representation.setCreated(account.getCreated()); representation.setUpdated(account.getUpdated()); representation.setUsername(account.getUsername()); representation.setLocked(account.isLocked()); representation.setRoles(account.getRoles().stream().map(role -> roleConversionService.convert(role)).collect(Collectors.toSet())); return representation; } @Autowired  AccountConversionService(RoleService roleService, RoleConversionService roleConversionService); AccountRepresentation convert(Account account); Account convert(AccountRepresentation representation); Account convert(AccountRepresentation representation, Account account);  }