Skip to content

Instantly share code, notes, and snippets.

@nilswloka
Created October 4, 2012 11:41
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nilswloka/3833108 to your computer and use it in GitHub Desktop.
Save nilswloka/3833108 to your computer and use it in GitHub Desktop.
Example for Java Quickcheck
@Test
public void equally_named_categories_should_be_equal() {
forAll(names(), new AbstractCharacteristic<String>() {
@Override
protected void doSpecify(String name) throws Throwable {
Category thisCategory = new Category(name);
Category thatCategory = new Category(name);
assertEquals(thisCategory, thatCategory);
}
});
}
@Test
public void equal_categories_should_have_equal_hashCodes() {
forAll(pairsOfEqualCategories(), new AbstractCharacteristic<Pair<Category, Category>>() {
@Override
protected void doSpecify(Pair<Category, Category> categoryPair) throws Throwable {
assertEquals(categoryPair.getFirst().hashCode(), categoryPair.getSecond().hashCode());
}
});
}
private Generator<Pair<Category, Category>> pairsOfEqualCategories() {
final Generator<String> names = names();
return new Generator<Pair<Category, Category>>() {
@Override
public Pair<Category, Category> next() {
String name = names.next();
return new Pair(new Category(name), new Category(name));
}
};
}
private Generator<String> names() {
return strings();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment