Skip to content
Snippets Groups Projects
Commit 623d4c3c authored by Goik Martin's avatar Goik Martin
Browse files

Replacing try ... catch in favor of CLI tst execution

parent 11c15c2d
No related branches found
No related tags found
No related merge requests found
......@@ -11,8 +11,6 @@ public class
A_PaymentTest extends ExaminationTestDefaults {
static public final String DEBUG_TEST_HINT =
"Test error: Wanna set a breakpoint next line to start debugging?";
public static final Logger log = LogManager.getLogger();
......@@ -48,17 +46,16 @@ A_PaymentTest extends ExaminationTestDefaults {
static private void test(final double expectedCosts, final double amount, int paymentDelay) {
final String message = "An order worth of " + amount + "€ and payment at day " + paymentDelay +
" results in total costs of " + expectedCosts + "€";
try {
Assert.assertEquals(
message, expectedCosts,
A_Payment.getBillingAmount(amount, paymentDelay), DOUBLE_TEST_PRECISION_LIMIT);
} catch (final AssertionError e) {
log.error(DEBUG_TEST_HINT);
final double actualCosts = A_Payment.getBillingAmount(amount, paymentDelay);
if (DOUBLE_TEST_PRECISION_LIMIT < Math.abs(actualCosts - expectedCosts) ) {
final String message = "Order amount=" + amount + "€, payment delay=" + paymentDelay +
". Wanna set a breakpoint to start debugging?";
Assert.assertEquals(
message, expectedCosts,
A_Payment.getBillingAmount(amount, paymentDelay), DOUBLE_TEST_PRECISION_LIMIT);
}
}
}
......@@ -2,19 +2,12 @@ package de.hdm_stuttgart.mi.sd1.task1;
import de.hdm_stuttgart.mi.exam.unitmarking.ExaminationTestDefaults;
import de.hdm_stuttgart.mi.exam.unitmarking.Marking;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.junit.Assert;
import org.junit.Test;
import static de.hdm_stuttgart.mi.sd1.task1.B_Irrigation.irrigationIsActive;
import static de.hdm_stuttgart.mi.sd1.task1.A_PaymentTest.DEBUG_TEST_HINT;
public class B_IrrigationTest extends ExaminationTestDefaults {
public static final Logger log = LogManager.getLogger();
static private void test(final boolean expectedIrrigationState,
final int fromHour, final int toHour,
final int fromMinute,
......@@ -22,15 +15,14 @@ public class B_IrrigationTest extends ExaminationTestDefaults {
for (int hour = fromHour; hour <= toHour; hour++) {
for (int minute = fromMinute; minute <= toMinute; minute++) {
try {
Assert.assertEquals("At " + hour + ":" + minute + " Irrigation is supposed to be " +
(expectedIrrigationState ? "active" : "inactive"),
expectedIrrigationState, irrigationIsActive(hour, minute));
} catch (final AssertionError e) {
log.error(DEBUG_TEST_HINT);
Assert.assertEquals("At " + hour + ":" + minute + " Irrigation is supposed to be " +
(expectedIrrigationState ? "active" : "inactive"),
expectedIrrigationState, irrigationIsActive(hour, minute));
final String msg = "At " + hour + ":" + minute + " Irrigation is supposed to be " +
(expectedIrrigationState ? "active" : "inactive") + ". Wanna set a breakpoint to start debugging?";
final boolean actualIrrigationState = irrigationIsActive(hour, minute);
if (expectedIrrigationState != actualIrrigationState) {
Assert.assertEquals(msg, expectedIrrigationState, actualIrrigationState);
}
}
}
......@@ -40,10 +32,6 @@ public class B_IrrigationTest extends ExaminationTestDefaults {
final int fromHour, final int toHour) {
test(expectedIrrigationState, fromHour, toHour, 0, 59);
}
static private void test(final boolean expectedIrrigationState,
final int hour) {
test(expectedIrrigationState, hour, hour, 0, 59);
}
static private void test(final boolean expectedIrrigationState,
final int hour,
......@@ -57,7 +45,7 @@ public class B_IrrigationTest extends ExaminationTestDefaults {
public void testIrrigation () {
test(false, 0, 4); // 0:00 till 4:59
test(true, 5); // 5:00 till 5:59
test(true, 5, 5); // 5:00 till 5:59
test(true, 6, 0, 30); // 6:00 till 6:30
test(false, 6, 31, 59); // 6:31 till 6:59
test(false, 7, 20); // 7:00 till 20:59
......@@ -65,11 +53,6 @@ public class B_IrrigationTest extends ExaminationTestDefaults {
test(true, 21, 30, 59); // 21:30 till 21:59
test(true, 22, 0, 30); // 22:00 till 22:30
test(false, 22, 31, 59); // 22:31 till 22:59
test(false, 23); // 23:00 till 23:59
}
private String getErrorMessage(final boolean expectedIrrigationState, final int hour, final int minute) {
return "At " + hour + ":" + minute + " Irrigation is supposed to be "+
(expectedIrrigationState ? "active" : "inactive");
test(false, 23, 23); // 23:00 till 23:59
}
}
......@@ -12,8 +12,7 @@ import org.junit.runners.MethodSorters;
@FixMethodOrder(MethodSorters.NAME_ASCENDING)
public class C_WebUrlTest extends ExaminationTestDefaults {
static public final String DEBUG_TEST_HINT =
"Test error: Wanna set a breakpoint next line to start debugging?";
static public final String DEBUG_TEST_HINT = "Wanna set a breakpoint to start debugging?";
public static final Logger log = LogManager.getLogger();
......@@ -38,15 +37,12 @@ public class C_WebUrlTest extends ExaminationTestDefaults {
}
static private void test(final String expectedUrl, final String inputUrl, final boolean tlsSupport) {
try {
Assert.assertEquals(expectedUrl, C_WebUrl.amendWebAddress(inputUrl, tlsSupport));
} catch (final AssertionError e) {
final String msg = "\nMethod parameter inputUrl='" + inputUrl + "' and tlsSupport=" + tlsSupport;
log.error(DEBUG_TEST_HINT);
Assert.assertEquals(
msg,
expectedUrl,
C_WebUrl.amendWebAddress(inputUrl, tlsSupport));
final String actualUrl = C_WebUrl.amendWebAddress(inputUrl, tlsSupport);
if (!expectedUrl.equals(actualUrl)) {
final String msg = DEBUG_TEST_HINT;
Assert.assertEquals(msg, expectedUrl, actualUrl);
}
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment