Commit 6e002aef authored by William Billingsley's avatar William Billingsley Committed by nreeves5
Browse files

Added log4j and a basic test class

parent 8a5345d8
......@@ -25,6 +25,10 @@ repositories {
}
dependencies {
// Log4J does logging. We'll meet it properly in a later week...
implementation 'org.apache.logging.log4j:log4j-api:2.12.0'
implementation 'org.apache.logging.log4j:log4j-core:2.12.0'
testImplementation 'org.junit.jupiter:junit-jupiter-api:5.7.0'
testRuntimeOnly 'org.junit.jupiter:junit-jupiter-engine:5.7.0'
}
......
......@@ -79,6 +79,10 @@ public class DotsAndBoxesUI {
grid.drawHorizontal(x, y, grid.getPlayer());
} catch (IllegalStateException ex) {
// do nothing
// This is a little artificial, as normally we'd implement this with a check that the line isn't
// already "drawn" and then not calling the function. But for the exercise, we wanted students
// to write a test that would ensure an exception is thrown, so we're relying on an exception
// being thrown!
}});
AnchorPane.setLeftAnchor(line, 0.0 + gap + dotDiameter + col * (gap + lineLength + gap + dotDiameter));
......
......@@ -14,5 +14,6 @@
module dotsAndBoxes {
requires javafx.graphics;
requires javafx.controls;
requires org.apache.logging.log4j;
exports dotsandboxes;
}
\ No newline at end of file
package dotsandboxes;
import org.junit.jupiter.api.*;
import static org.junit.jupiter.api.Assertions.*;
import static org.junit.jupiter.api.Assumptions.*;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
public class DotsAndBoxesGridTest {
/*
* Because Test classes are classes, they can have fields, and can have static fields.
* This field is a logger. Loggers are like a more advanced println, for writing messages out to the console or a log file.
*/
private static final Logger logger = LogManager.getLogger(DotsAndBoxesGridTest.class);
/*
* Tests are functions that have an @Test annotation before them.
* The typical format of a test is that it contains some code that does something, and then one
* or more assertions to check that a condition holds.
*
* This is a dummy test just to show that the test suite itself runs
*/
@Test
public void testTestSuiteRuns() {
logger.info("Dummy test to show the test suite runs");
assertTrue(true);
}
// FIXME: You need to write tests for the two known bugs in the code.
}
<?xml version="1.0" encoding="UTF-8"?>
<Configuration status="WARN">
<Appenders>
<Console name="Console" target="SYSTEM_OUT">
<PatternLayout pattern="%d{HH:mm:ss.SSS} [%t] %-5level %logger{36} - %msg%n"/>
</Console>
</Appenders>
<Loggers>
<Root level="debug">
<AppenderRef ref="Console"/>
</Root>
</Loggers>
</Configuration>
\ No newline at end of file
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment