### Question:
PoulpeAuthPlugin extends StatefullPlugin implements AuthenticationPlugin, RegistrationPlugin { @Override public Map<String, String> registerUser(UserDto userDto, Long pluginId) throws NoConnectionException, UnexpectedErrorException { return registerOrValidate(userDto, false); }  @Override Map<String, String> registerUser(UserDto userDto, Long pluginId); @Override Map<String, String> validateUser(UserDto userDto, Long pluginId); @Override String getHtml(HttpServletRequest request, String pluginId, Locale locale); @Override Map<String, String> authenticate(String login, String password); @Override void activate(String username); @Override boolean supportsJCommuneVersion(String version); @Override String getName(); @Override List<PluginProperty> getConfiguration(); @Override List<PluginProperty> getDefaultConfiguration(); @Override String translateLabel(String code, Locale locale);  }### Answer:
@Test public void userShouldNotBeRegisteredIfSomeErrorOccurred() throws JAXBException, IOException, NoConnectionException, UnexpectedErrorException { UserDto userDto = createUserDto("user", "", ""); Map<String, String> errors = new HashMap<>(); errors.put("email", "Invalid email"); errors.put("password", "Invalid password"); when(service.registerUser(userDto, false)).thenReturn(errors); Map<String, String> result = plugin.registerUser(userDto, null); assertEquals(result.size(), 2, "User with incorrect parameters shouldn't be registered."); }
@Test public void userWithCorrectParametersShouldBeRegistered() throws UnexpectedErrorException, NoConnectionException, IOException, JAXBException { UserDto userDto = createUserDto("user", "1234", "email@email.em"); when(service.registerUser(userDto, true)).thenReturn(new HashMap<String, String>()); Map<String, String> result = plugin.registerUser(userDto, null); assertEquals(result.size(), 0, "User with correct parameters should be registered."); }
@Test(expectedExceptions = NoConnectionException.class) public void registerUserShouldThrowNoConnectionExceptionIfPoulpeUnavailable() throws UnexpectedErrorException, NoConnectionException, IOException, JAXBException { UserDto userDto = createUserDto("user", "1234", "email@email.em"); when(service.registerUser(userDto, false)).thenThrow(new NoConnectionException()); plugin.registerUser(userDto, null); }
@Test(expectedExceptions = UnexpectedErrorException.class) public void registerUserShouldThrowUnexpectedErrorExceptionIfSomeErrorOccurred() throws UnexpectedErrorException, NoConnectionException, IOException, JAXBException { UserDto userDto = createUserDto("user", "1234", "email@email.em"); when(service.registerUser(userDto, false)).thenThrow(new JAXBException("")); plugin.registerUser(userDto, null); }