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
class LoginFeature extends GivenWhenThenFeatureSpec with ShouldMatchers with OneInstancePerTest { | |
feature("Admin Login") { | |
scenario("Incorrect password") { | |
// You can provide the code for a step in a block | |
given("user visits", the[AdminHomePage]) { | |
startPage(pageClass) | |
} |
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
$ git clone [email protected]:dmcg/junit-quickcheck.git | |
Cloning into 'junit-quickcheck'... | |
remote: Counting objects: 4804, done. | |
remote: Compressing objects: 100% (1269/1269), done. | |
remote: Total 4804 (delta 2245), reused 4769 (delta 2215) | |
Receiving objects: 100% (4804/4804), 779.89 KiB | 452 KiB/s, done. | |
Resolving deltas: 100% (2245/2245), done. | |
~/Documents/Work/approvals | |
$ cd junit-quickcheck/ | |
~/Documents/Work/approvals/junit-quickcheck |
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
mockery.when(() -> servlet.process( | |
ImmutableMap.of( | |
"code", new String[]{ codeValue}, | |
"state", new String[]{ state }), | |
"http://rescyoume/oauth", | |
response)). | |
then(expect -> { | |
expect.oneOf(stravaAuthenticator).fetchDetails(codeValue, oAuthAccount, clientState, "http://rescyoume/oauth"); | |
expect.will(returnValue(oAuthDetails)); | |
expect.oneOf(db).save(oAuthDetails); |
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
public class StreamMatchers { | |
public static class StreamContainingInAnyOrderMatcher<T> extends DelegatingStreamMatcher<T> { | |
public StreamContainingInAnyOrderMatcher(T... items) { | |
super(org.hamcrest.Matchers.arrayContainingInAnyOrder(items), "Stream of "); | |
} | |
} | |
public static class EmptyStreamMatcher<T> extends DelegatingStreamMatcher<T> { | |
public EmptyStreamMatcher() { | |
super(Matchers.emptyArray(), "Stream like "); |
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
public class TransformingMatcher<U, T> extends TypeSafeMatcher<U> { | |
private final Matcher<T> base; | |
private final Function<? super U, ? extends T> function; | |
public TransformingMatcher(Matcher<T> base, Function<? super U, ? extends T> function) { | |
this.base = base; | |
this.function = function; | |
} | |
@Override |
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
@Value public class User { | |
public final Optional<String> id; | |
public final DateTime createdDate; | |
public final String firstName; | |
public final String lastName; | |
@Wither public final Country country; | |
@Wither public final PhoneNumber phoneNumber; | |
@Wither public final String email; | |
@Wither public final Optional<String> stravaId; |
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
@Test | |
public void saves_results() throws IOException { | |
ImmutableList<Associate> associates = ImmutableList.of( | |
new Associate("id1", "fn1", "ln2"), | |
new Associate("id2", "fn1", "ln2")); | |
mockery.given((given) -> { | |
given.oneOf(source).findAssociates("token"); | |
given.will(returnValue(associates.stream())); | |
}); |
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
String user = "{" + | |
"isAccountNonLocked : true," + | |
"isEnabled : true," + | |
"isAccountNonExpired : true," + | |
"isPasswordProvided : true," + | |
"isCredentialsNonExpired : true," + | |
"}"; | |
mockery.checking(new JsonExpectations(user)); |
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
private User activeUser(Customer customer) { | |
return mock(User.class, | |
"isAccountNonLocked", true, | |
"isEnabled", true, | |
"isAccountNonExpired", true, | |
"isPasswordProvided", true, | |
"isCredentialsNonExpired", true, | |
"getCustomer", customer, | |
"getAuthorities", ImmutableList.of() | |
); |
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
private User activeUser(final Customer customer) { | |
return mock(User.class, | |
new Object() { | |
boolean isAccountNonLocked = true; | |
boolean isEnabled = true; | |
boolean isAccountNonExpired = true; | |
boolean isPasswordProvided = true; | |
boolean isCredentialsNonExpired = true; | |
Customer getCustomer = customer; | |
ImmutableList<?> getAuthorities = ImmutableList.of(); |
OlderNewer