### Question:
PropertyVerifier extends MapVerifier { @Override public int verify(Request request, Response response) { String username =loadCredentialsFromProperties(); if(username!=null && username.isEmpty()){ char[] password = getLocalSecret(username); if(password.length==0){ return Verifier.RESULT_VALID; } } return super.verify(request, response); } PropertyVerifier(ComponentService componentService); String loadCredentialsFromProperties(); @Override int verify(Request request, Response response); @Override void setLocalSecrets(Map<String, char[]> localSecrets); static final String USERNAME_PROP; static final String PASSWORD_PROP; }### Answer:
@Test public void emptyUsernameAndPasswordMeanNoAuthentication() throws Exception { Component component = new Component(); component.addProperty(PropertyVerifier.USERNAME_PROP, ""); component.addProperty(PropertyVerifier.PASSWORD_PROP, ""); when(componentService.getByType(ComponentType.ADMIN_PANEL)).thenReturn(component); assertEquals(propertyVerifier.verify(new Request(), new Response(null)), Verifier.RESULT_VALID); }
@Test public void emptyUsernameMeansNoAuthentication() throws Exception { Component component = new Component(); component.addProperty(PropertyVerifier.USERNAME_PROP, ""); component.addProperty(PropertyVerifier.PASSWORD_PROP, "134"); when(componentService.getByType(ComponentType.ADMIN_PANEL)).thenReturn(component); assertEquals(propertyVerifier.verify(new Request(), new Response(null)), Verifier.RESULT_MISSING); }
@Test public void emptyPasswordMeansNoAuthentication() throws Exception { Component component = new Component(); component.addProperty(PropertyVerifier.USERNAME_PROP, "1234"); component.addProperty(PropertyVerifier.PASSWORD_PROP,""); when(componentService.getByType(ComponentType.ADMIN_PANEL)).thenReturn(component); assertEquals(propertyVerifier.verify(new Request(),new Response(null)), Verifier.RESULT_MISSING); }