Created
October 4, 2012 11:41
-
-
Save nilswloka/3833108 to your computer and use it in GitHub Desktop.
Example for Java Quickcheck
This file contains hidden or 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 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