Created
October 7, 2010 20:36
-
-
Save chbaranowski/615836 to your computer and use it in GitHub Desktop.
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
package swqs.quicksort; | |
import static org.junit.Assert.*; | |
import org.junit.After; | |
import org.junit.AfterClass; | |
import org.junit.Before; | |
import org.junit.BeforeClass; | |
import org.junit.Test; | |
public class QuicksortTest { | |
Quicksort<Integer> quicksortSUT; | |
@BeforeClass | |
public static void beforeClass() { | |
// Wird genau einmal vor allen Tests und | |
// der setUp Methode aufgerufen. | |
} | |
@Before | |
public void setUp() { | |
// Phase 1.) Die setUp Methode, wird vor jedem Test aufgerufen | |
quicksortSUT = new Quicksort<Integer>(new IntComperator()); | |
} | |
@Test | |
public void testSort() throws Exception { | |
// Phase 2.) execute SUT | |
Integer[] values = new Integer[] { 5, 8, 2, 4, 7 }; | |
quicksortSUT.sort(values); | |
// Phase 3.) verify | |
Integer[] expectedOrder = new Integer[] { 2, 4, 5, 7, 8 }; | |
assertArrayEquals(expectedOrder, values); | |
} | |
@After | |
public void tearDown(){ | |
// Phase 4.) tear down (clean up) close test | |
// database connection etc. | |
quicksortSUT = null; | |
} | |
@AfterClass | |
public static void afterClass() { | |
// Wird genau einmal nach allen Tests und | |
// nach der tearDown Methode aufgerufen. | |
} | |
@Test | |
public void testSort_WithOneElement() throws Exception { | |
// Phase 2.) execute SUT | |
Integer[] values = new Integer[] { 5 }; | |
quicksortSUT.sort(values); | |
// Phase 3.) verify | |
assertArrayEquals(new Integer[] { 5 }, values); | |
} | |
@Test | |
public void testSort_WithEmptyArray() throws Exception { | |
// Phase 2.) execute SUT | |
Integer[] values = new Integer[] { }; | |
quicksortSUT.sort(values); | |
// Phase 3.) verify | |
assertArrayEquals(new Integer[] { }, values); | |
} | |
// Phase 3.) verify durch annotation es wird | |
// eine NullPointerException erwartet | |
@Test(expected = NullPointerException.class) | |
public void testSort_null() throws Exception { | |
// Phase 2.) execute SUT | |
Integer[] values = new Integer[] { }; | |
quicksortSUT.sort(null); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment