https://gist.github.com/2306009
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
mit dem Matcher können komplexere Vergleiche mit "assertThat" getestet werden, hier ein einfaches Beispiel, | |
welches testet, dass zwei Daten am gleichen Tag sind. | |
import org.hamcrest.BaseMatcher; | |
import org.hamcrest.Description; | |
import org.hamcrest.Matcher; | |
... | |
class TerminTestUtils ... | |
.... | |
public static Matcher<Date> gleicherTag(final Object dateSoll) { | |
final SimpleDateFormat df = new SimpleDateFormat("dd.MM.yyyy"); | |
return new BaseMatcher<Date>() { | |
public void describeTo(Description desc) { | |
desc.appendText(df.format(dateSoll)); | |
} | |
public boolean matches(Object dateIst) { | |
if (dateIst == null || dateSoll == null) { | |
return false; | |
} | |
return df.format(dateIst).equals(df.format(dateSoll)); | |
} | |
}; | |
} | |
wird im JUnit-Test benutzt mit: | |
assertThat("Testfall " + testvektor.nr + ": Termin: ", businessFunctionK3 | |
.getAgendaNotizFaelligkeitZeitpunkt(), TerminTestUtils.gleicherTag(testvektor.termindatum)); |
Siehe auch:
und:
Keine Kommentare:
Kommentar veröffentlichen