Skip to content

Commit

Permalink
Clarified test method names.
Browse files Browse the repository at this point in the history
  • Loading branch information
fickludd authored and henriknyman committed Sep 7, 2016
1 parent 170777f commit 15a7b8c
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 34 deletions.
Expand Up @@ -73,13 +73,13 @@ public void shouldNotCacheAuthenticationInfo() throws InvalidAuthTokenException
{
// Given
authManager.login( authToken( "mike", "123" ) );
assertThat( "Test realm did not receive a call", testRealm.wasAuthenticated(), is( true ) );
assertThat( "Test realm did not receive a call", testRealm.takeAuthenticationFlag(), is( true ) );

// When
authManager.login( authToken( "mike", "123" ) );

// Then
assertThat( "Test realm did not receive a call", testRealm.wasAuthenticated(), is( true ) );
assertThat( "Test realm did not receive a call", testRealm.takeAuthenticationFlag(), is( true ) );
}

@Test
Expand All @@ -88,31 +88,31 @@ public void shouldNotCacheAuthorizationInfo() throws InvalidAuthTokenException
// Given
EnterpriseAuthSubject mike = authManager.login( authToken( "mike", "123" ) );
mike.allowsReads();
assertThat( "Test realm did not receive a call", testRealm.wasAuthorized(), is( true ) );
assertThat( "Test realm did not receive a call", testRealm.takeAuthorizationFlag(), is( true ) );

// When
mike.allowsWrites();

// Then
assertThat( "Test realm did not receive a call", testRealm.wasAuthorized(), is( true ) );
assertThat( "Test realm did not receive a call", testRealm.takeAuthorizationFlag(), is( true ) );
}

private class TestRealm extends InternalFlatFileRealm
{
private boolean authenticated = false;
private boolean authorized = false;
private boolean authenticationFlag = false;
private boolean authorizationFlag = false;

boolean wasAuthenticated()
boolean takeAuthenticationFlag()
{
boolean t = authenticated;
authenticated = false;
boolean t = authenticationFlag;
authenticationFlag = false;
return t;
}

boolean wasAuthorized()
boolean takeAuthorizationFlag()
{
boolean t = authorized;
authorized = false;
boolean t = authorizationFlag;
authorizationFlag = false;
return t;
}

Expand All @@ -137,14 +137,14 @@ public boolean supports( AuthenticationToken token )
@Override
protected AuthenticationInfo doGetAuthenticationInfo( AuthenticationToken token ) throws AuthenticationException
{
authenticated = true;
authenticationFlag = true;
return super.doGetAuthenticationInfo( token );
}

@Override
protected AuthorizationInfo doGetAuthorizationInfo( PrincipalCollection principals )
{
authorized = true;
authorizationFlag = true;
return super.doGetAuthorizationInfo( principals );
}
}
Expand Down
Expand Up @@ -98,13 +98,13 @@ public void shouldCacheAuthenticationInfo() throws InvalidAuthTokenException
{
// Given
authManager.login( authToken( "mike", "123" ) );
assertThat( "Test realm did not receive a call", testRealm.wasAuthenticated(), is( true ) );
assertThat( "Test realm did not receive a call", testRealm.takeAuthenticationFlag(), is( true ) );

// When
authManager.login( authToken( "mike", "123" ) );

// Then
assertThat( "Test realm received a call", testRealm.wasAuthenticated(), is( false ) );
assertThat( "Test realm received a call", testRealm.takeAuthenticationFlag(), is( false ) );
}

@Test
Expand All @@ -113,13 +113,13 @@ public void shouldCacheAuthorizationInfo() throws InvalidAuthTokenException
// Given
EnterpriseAuthSubject mike = authManager.login( authToken( "mike", "123" ) );
mike.allowsReads();
assertThat( "Test realm did not receive a call", testRealm.wasAuthorized(), is( true ) );
assertThat( "Test realm did not receive a call", testRealm.takeAuthorizationFlag(), is( true ) );

// When
mike.allowsWrites();

// Then
assertThat( "Test realm received a call", testRealm.wasAuthorized(), is( false ) );
assertThat( "Test realm received a call", testRealm.takeAuthorizationFlag(), is( false ) );
}

@Test
Expand All @@ -128,21 +128,21 @@ public void shouldInvalidateAuthorizationCacheAfterTTL() throws InvalidAuthToken
// Given
EnterpriseAuthSubject mike = authManager.login( authToken( "mike", "123" ) );
mike.allowsReads();
assertThat( "Test realm did not receive a call", testRealm.wasAuthorized(), is( true ) );
assertThat( "Test realm did not receive a call", testRealm.takeAuthorizationFlag(), is( true ) );

// When
fakeTicker.advance( 99, TimeUnit.MILLISECONDS );
mike.allowsWrites();

// Then
assertThat( "Test realm received a call", testRealm.wasAuthorized(), is( false ) );
assertThat( "Test realm received a call", testRealm.takeAuthorizationFlag(), is( false ) );

// When
fakeTicker.advance( 2, TimeUnit.MILLISECONDS );
mike.allowsWrites();

// Then
assertThat( "Test realm did not received a call", testRealm.wasAuthorized(), is( true ) );
assertThat( "Test realm did not received a call", testRealm.takeAuthorizationFlag(), is( true ) );
}

@Test
Expand All @@ -151,39 +151,39 @@ public void shouldInvalidateAuthenticationCacheAfterTTL() throws InvalidAuthToke
// Given
Map<String,Object> mike = authToken( "mike", "123" );
authManager.login( mike );
assertThat( "Test realm did not receive a call", testRealm.wasAuthenticated(), is( true ) );
assertThat( "Test realm did not receive a call", testRealm.takeAuthenticationFlag(), is( true ) );

// When
fakeTicker.advance( 99, TimeUnit.MILLISECONDS );
authManager.login( mike );

// Then
assertThat( "Test realm received a call", testRealm.wasAuthenticated(), is( false ) );
assertThat( "Test realm received a call", testRealm.takeAuthenticationFlag(), is( false ) );

// When
fakeTicker.advance( 2, TimeUnit.MILLISECONDS );
authManager.login( mike );

// Then
assertThat( "Test realm did not received a call", testRealm.wasAuthenticated(), is( true ) );
assertThat( "Test realm did not received a call", testRealm.takeAuthenticationFlag(), is( true ) );
}

private class TestRealm extends LdapRealm
{
private boolean authenticated = false;
private boolean authorized = false;
private boolean authenticationFlag = false;
private boolean authorizationFlag = false;

boolean wasAuthenticated()
boolean takeAuthenticationFlag()
{
boolean t = authenticated;
authenticated = false;
boolean t = authenticationFlag;
authenticationFlag = false;
return t;
}

boolean wasAuthorized()
boolean takeAuthorizationFlag()
{
boolean t = authorized;
authorized = false;
boolean t = authorizationFlag;
authorizationFlag = false;
return t;
}

Expand All @@ -209,7 +209,7 @@ public boolean supports( AuthenticationToken token )
@Override
protected AuthenticationInfo doGetAuthenticationInfo( AuthenticationToken token ) throws AuthenticationException
{
authenticated = true;
authenticationFlag = true;
return new AuthenticationInfo()
{
@Override
Expand All @@ -229,7 +229,7 @@ public Object getCredentials()
@Override
protected AuthorizationInfo doGetAuthorizationInfo( PrincipalCollection principals )
{
authorized = true;
authorizationFlag = true;
return new AuthorizationInfo()
{
@Override
Expand Down

0 comments on commit 15a7b8c

Please sign in to comment.