Category: unit tests

  • Navigating (Searching) Collections

    Update: this article has been crossposted to the Transylvania JUG blog. The Java collections framework includes the concept of NavigableSets / NavigableMaps. The principle behind these interfaces is that taking a SortedSet/SortedMap you can use a subset of it. Some examples: Given the following set: @Before public void setUp() { set = new TreeSet(); set.addAll(Arrays.asList(1,…

  • How to test for the implementation of toString()

    Update: This entry has been crossposted to the transylvania-jug blog. Problem statement: you have some value objects for which you implemented toString() (for debugging purposes) and now you would like to test using a unit test that these implementations exist. Possible solutions: Use reflection to detect the existence of the method: boolean hasToStringViaReflection(Class clazz) {…