public void testSortNumbers() { NumberSorter numberSorter = new NumberSorter(quicksort, bubbleSort); // Verify that the returned list is sorted. It doesn't matter which sorting // algorithm is used, as long as the right result is returned. assertEquals( new ArrayList(1, 2, 3), numberSorter.sortNumbers(new ArrayList(3, 1, 2))); }
public void testSortNumbers_quicksortIsUsed() { // Pass in mocks to the class and call the method under test. NumberSorter numberSorter = new NumberSorter(mockQuicksort, mockBubbleSort); numberSorter.sortNumbers(new ArrayList(3, 1, 2)); // Verify that numberSorter.sortNumbers() used quicksort. The test should // fail if mockQuicksort.sort() is never called or if it's called with the // wrong arguments (e.g. if mockBubbleSort is used to sort the numbers). verify(mockQuicksort).sort(new ArrayList(3, 1, 2)); }