Commit db45700a authored by William Billingsley's avatar William Billingsley
Browse files

Added log4j and a basic test class

parent 204ac68c
......@@ -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.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
public void testTestSuiteRuns() {"Dummy test to show the test suite runs");
// FIXME: You need to write tests for the two known bugs in the code.
<?xml version="1.0" encoding="UTF-8"?>
<Configuration status="WARN">
<Console name="Console" target="SYSTEM_OUT">
<PatternLayout pattern="%d{HH:mm:ss.SSS} [%t] %-5level %logger{36} - %msg%n"/>
<Root level="debug">
<AppenderRef ref="Console"/>
\ 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