### Question:
RateLimitedAuthenticationStrategy implements AuthenticationStrategy { @Override public AuthenticationResult authenticate( User user, byte[] password ) { AuthenticationMetadata authMetadata = authMetadataFor( user.name() ); if ( !authMetadata.authenticationPermitted() ) { return AuthenticationResult.TOO_MANY_ATTEMPTS; } if ( user.credentials().matchesPassword( password ) ) { authMetadata.authSuccess(); return AuthenticationResult.SUCCESS; } else { authMetadata.authFailed(); return AuthenticationResult.FAILURE; } } RateLimitedAuthenticationStrategy( Clock clock, Config config );   RateLimitedAuthenticationStrategy( Clock clock, Duration lockDuration, int maxFailedAttempts ); @Override AuthenticationResult authenticate( User user, byte[] password );  }### Answer:
@Test public void shouldReturnSuccessForValidAttempt() { FakeClock clock = getFakeClock(); AuthenticationStrategy authStrategy = newAuthStrategy( clock, 3 ); User user = new User.Builder( "user", LegacyCredential.forPassword( "right" ) ).build(); assertThat( authStrategy.authenticate( user, password( "right" ) ), equalTo( AuthenticationResult.SUCCESS ) ); }
@Test public void shouldReturnFailureForInvalidAttempt() { FakeClock clock = getFakeClock(); AuthenticationStrategy authStrategy = newAuthStrategy( clock, 3 ); User user = new User.Builder( "user", LegacyCredential.forPassword( "right" ) ).build(); assertThat( authStrategy.authenticate( user, password( "wrong" ) ), equalTo( AuthenticationResult.FAILURE ) ); }
@Test public void shouldNotSlowRequestRateOnLessThanMaxFailedAttempts() { FakeClock clock = getFakeClock(); AuthenticationStrategy authStrategy = newAuthStrategy( clock, 3 ); User user = new User.Builder( "user", LegacyCredential.forPassword( "right" ) ).build(); assertThat( authStrategy.authenticate( user, password( "wrong" ) ), equalTo( AuthenticationResult.FAILURE ) ); assertThat( authStrategy.authenticate( user, password( "wrong" ) ), equalTo( AuthenticationResult.FAILURE ) ); assertThat( authStrategy.authenticate( user, password( "right" ) ), equalTo( AuthenticationResult.SUCCESS )); }