diff --git a/build.gradle b/build.gradle index fd455a2615f39ce2c9073170b2ef4a71c444fb2f..5705373c7f0724928eb4cbaed9cd028179e1239a 100644 --- a/build.gradle +++ b/build.gradle @@ -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' } diff --git a/src/main/java/dotsandboxes/DotsAndBoxesUI.java b/src/main/java/dotsandboxes/DotsAndBoxesUI.java index 154cb8826db5cf89be1bf5644a4c53e431f82614..66010e3938d422d2418c50f1962ed1c3d6f33050 100644 --- a/src/main/java/dotsandboxes/DotsAndBoxesUI.java +++ b/src/main/java/dotsandboxes/DotsAndBoxesUI.java @@ -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)); diff --git a/src/main/java/module-info.java b/src/main/java/module-info.java index c99b9f2c53cf1c71fd4aeb0775c7f0b1fd697e1e..eb9361f159b402160086de3fe6b01b1272ab53b0 100644 --- a/src/main/java/module-info.java +++ b/src/main/java/module-info.java @@ -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 diff --git a/src/test/java/dotsandboxes/DotsAndBoxesGridTest.java b/src/test/java/dotsandboxes/DotsAndBoxesGridTest.java new file mode 100644 index 0000000000000000000000000000000000000000..1946beda974d180686c65c0259a7b881e9a4eb5a --- /dev/null +++ b/src/test/java/dotsandboxes/DotsAndBoxesGridTest.java @@ -0,0 +1,31 @@ +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. +} diff --git a/src/test/resources/log4j2.xml b/src/test/resources/log4j2.xml new file mode 100644 index 0000000000000000000000000000000000000000..32c8f6bc729bb2d82f81583fb3215b7c669b4f32 --- /dev/null +++ b/src/test/resources/log4j2.xml @@ -0,0 +1,13 @@ +<?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