Created
May 3, 2015 14:27
-
-
Save mike-rogers/2a238278a67e51627970 to your computer and use it in GitHub Desktop.
TDD in Java using JUnit Theories
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@DataPoints | |
public static String[] usernames() { | |
return new String[] { | |
"user1", "user2", "user3", "user4", "user5", "", null | |
}; | |
} | |
@Theory | |
public void shouldDenyAccessToUsersWhenExceptionsAreUnspecified(String username) { | |
FeatureFilter featureFilter = FeatureFilter | |
.describeFeature() | |
.addFeatureRef("myFeature", | |
thatIsAvailable() | |
.atEndpoint("/myEndpoint") | |
.andDisable()); | |
assumeThat("Username should not be null nor empty", username, not(isEmptyOrNullString())); | |
assertThat(featureFilter.isAllowed("/myEndpoint", username, "myFeature"), is(false)); | |
} | |
@Theory | |
public void shouldAllowAccessToUserWhenExceptionIsSpecified(String username) { | |
FeatureFilter featureFilter = FeatureFilter | |
.describeFeature() | |
.addFeatureRef("myFeature", | |
thatIsAvailable() | |
.atEndpoint("/myEndpoint") | |
.andDisable() | |
.exceptForUser(username)); | |
assumeThat("Username should not be null nor empty", username, not(isEmptyOrNullString())); | |
assertThat(featureFilter.isAllowed("/myEndpoint", username, "myFeature"), is(true)); | |
} | |
@Theory | |
public void shouldDisallowAccessToInvalidUserWhenExceptionIsSpecified(String validUser, String invalidUser) { | |
FeatureFilter featureFilter = FeatureFilter | |
.describeFeature() | |
.addFeatureRef("myFeature", | |
thatIsAvailable() | |
.atEndpoint("/myEndpoint") | |
.andDisable() | |
.exceptForUser(validUser)); | |
assumeThat("Username should not be null nor empty", validUser, not(isEmptyOrNullString())); | |
assumeThat("Username should not be null nor empty", invalidUser, not(isEmptyOrNullString())); | |
assumeThat("Users should be different", validUser, not(equalTo(invalidUser))); | |
assertThat(featureFilter.isAllowed("/myEndpoint", invalidUser, "myFeature"), is(false)); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment