@Test(expected = IllegalArgumentException.class) public void saveNew_notNullId() { WhitelistedSite site = Mockito.mock(WhitelistedSite.class); Mockito.when(site.getId()).thenReturn(12345L); service.saveNew(site); }
@Override public WhitelistedSite saveNew(WhitelistedSite whitelistedSite) { if (whitelistedSite.getId() != null) { throw new IllegalArgumentException("A new whitelisted site cannot be created with an id value already set: " + whitelistedSite.getId()); } return repository.save(whitelistedSite); }
DefaultWhitelistedSiteService implements WhitelistedSiteService { @Override public WhitelistedSite saveNew(WhitelistedSite whitelistedSite) { if (whitelistedSite.getId() != null) { throw new IllegalArgumentException("A new whitelisted site cannot be created with an id value already set: " + whitelistedSite.getId()); } return repository.save(whitelistedSite); } }
DefaultWhitelistedSiteService implements WhitelistedSiteService { @Override public WhitelistedSite saveNew(WhitelistedSite whitelistedSite) { if (whitelistedSite.getId() != null) { throw new IllegalArgumentException("A new whitelisted site cannot be created with an id value already set: " + whitelistedSite.getId()); } return repository.save(whitelistedSite); }  }
DefaultWhitelistedSiteService implements WhitelistedSiteService { @Override public WhitelistedSite saveNew(WhitelistedSite whitelistedSite) { if (whitelistedSite.getId() != null) { throw new IllegalArgumentException("A new whitelisted site cannot be created with an id value already set: " + whitelistedSite.getId()); } return repository.save(whitelistedSite); }  @Override WhitelistedSite getById(Long id); @Override void remove(WhitelistedSite whitelistedSite); @Override WhitelistedSite saveNew(WhitelistedSite whitelistedSite); @Override Collection<WhitelistedSite> getAll(); @Override WhitelistedSite getByClientId(String clientId); @Override Collection<WhitelistedSite> getByCreator(String creatorId); @Override WhitelistedSite update(WhitelistedSite oldWhitelistedSite, WhitelistedSite whitelistedSite); }
DefaultWhitelistedSiteService implements WhitelistedSiteService { @Override public WhitelistedSite saveNew(WhitelistedSite whitelistedSite) { if (whitelistedSite.getId() != null) { throw new IllegalArgumentException("A new whitelisted site cannot be created with an id value already set: " + whitelistedSite.getId()); } return repository.save(whitelistedSite); }  @Override WhitelistedSite getById(Long id); @Override void remove(WhitelistedSite whitelistedSite); @Override WhitelistedSite saveNew(WhitelistedSite whitelistedSite); @Override Collection<WhitelistedSite> getAll(); @Override WhitelistedSite getByClientId(String clientId); @Override Collection<WhitelistedSite> getByCreator(String creatorId); @Override WhitelistedSite update(WhitelistedSite oldWhitelistedSite, WhitelistedSite whitelistedSite);  }