RegistrationService { public boolean register(User user) throws IllegalArgumentException { String email = user.getEmail(); if (getByEMail(email) != null) { log.info(String.format("User with email=%s already registered", email)); return false; } if (!validEMailAdress(email)) { log.info(String.format("email=%s invalid", email)); throw new IllegalArgumentException("Invalid EMail Adress!"); } jdbcTemplate.update( "INSERT INTO T_USER(firstname, name, email) VALUES (?, ?, ?)", user.getFirstname(), user.getName(), email); log.info(String.format("Registered firstname=%s name=%s email=%s", user.getFirstname(), user.getName(), email)); return true; }  boolean register(User user); boolean validEMailAdress(String email); User getByEMail(String email); void reset(); void unregister(String email); void clean();  }
@Test(expected=IllegalArgumentException.class) public void avoidInvalidEMail() { User user = new User("Eberhard","Wolff","HURZ!"); registrationService.register(user); }
@Test public void avoidDoubleRegistrations() { User user = new User("Eberhard","Wolff","eberhard.wolff@gmail.com"); assertTrue(registrationService.register(user)); assertFalse(registrationService.register(user)); }