I am currently testing a method, let me call it testedMethod()
.
The body of the method looks like this
private testedMethod(List<Protocoll> protocolList) {
//so something with the protocolList
if (something) && (somethingElse) {
Assert.isFalse(areTheProtocollsCorrect(p1, p2), "Error, the protocols are wrong");
}
if (somethingCompeletlyElse) && (somethingElse) {
Assert.isFalse(areTheProtocollsExactlyTheSame(p1, p2), "Error, the protocols are the same");
}
}
Additional code from the Assert.class
:
isFalse:
public static void isFalse(boolean condition, String descr) {
isTrue(!condition, descr);
}
isTrue:
public static void isTrue(boolean condition, String descr) {
if (!condition) {
fail(descr);
}
}
fail:
public static void fail(String descr) {
LOGGER.fatal("Assertion failed: " + descr);
throw new AssertException(descr);
}
Testing what the method should do correctly is allready done. But I would like to test those assertions. This assertions are an important part of the code, and I would like to see if the method is throwing those errors when I provide wrong data to it. How can I do it using JUnit?