### Question:
PoulpeAuthPlugin extends StatefullPlugin implements AuthenticationPlugin, RegistrationPlugin { @Override public Map<String, String> authenticate(String login, String password) throws UnexpectedErrorException, NoConnectionException { try { return service.authenticate(login, password); } catch (IOException | JAXBException e) { LOGGER.error("Parse response error", e); throw new UnexpectedErrorException(e); } catch (NoConnectionException e) { LOGGER.error("Can't connect to Poulpe: {}", e.getMessage()); throw e; } }  @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 userShouldNotBeAuthenticatedIfSomeErrorOccurred() throws JAXBException, IOException, NoConnectionException, UnexpectedErrorException { String username = "user"; String password = ""; when(service.authenticate(username, password)).thenReturn(Collections.<String, String>emptyMap()); Map<String, String> result = plugin.authenticate(username, password); assertEquals(result.size(), 0, "User with incorrect parameters shouldn't be authenticated."); }
@Test public void userWithCorrectParametersShouldBeAuthenticated() throws UnexpectedErrorException, NoConnectionException, IOException, JAXBException { String username = "user"; String password = "1234"; Map<String, String> authInfo = new HashMap<>(); authInfo.put("username", "user"); authInfo.put("password", "1234"); authInfo.put("email", "email@email.em"); when(service.authenticate(username, password)).thenReturn(authInfo); Map<String, String> result = plugin.authenticate(username, password); assertEquals(result.size(), 3, "User with correct parameters should be authenticated."); }
@Test(expectedExceptions = NoConnectionException.class) public void authenticateShouldThrowNoConnectionExceptionIfPoulpeUnavailable() throws UnexpectedErrorException, NoConnectionException, IOException, JAXBException { String username = "user"; String password = "1234"; when(service.authenticate(username, password)).thenThrow(new NoConnectionException()); plugin.authenticate(username, password); }
@Test(expectedExceptions = UnexpectedErrorException.class) public void authenticateShouldThrowUnexpectedErrorExceptionIfSomeErrorOccurred() throws UnexpectedErrorException, NoConnectionException, IOException, JAXBException { String username = "user"; String password = "1234"; when(service.authenticate(username, password)).thenThrow(new JAXBException("")); plugin.authenticate(username, password); }