Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Migrating to JUnit5
  • Loading branch information
charlesfinley committed Mar 4, 2021
commit 15ae2f63b9ac6777b2d2b237888cfb3ccfdda221
4 changes: 0 additions & 4 deletions double-buffer/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,6 @@
<artifactId>double-buffer</artifactId>

<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
</dependency>
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-lang3</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,14 @@

package com.iluwatar.doublebuffer;

import org.junit.Test;

import static org.junit.jupiter.api.Assertions.assertDoesNotThrow;

import org.junit.jupiter.api.Test;

/**
* App unit test.
*/
public class AppTest {
class AppTest {

/**
* Issue: Add at least one assertion to this test case.
Expand All @@ -40,7 +40,7 @@ public class AppTest {
*/

@Test
public void shouldExecuteApplicationWithoutException() {
void shouldExecuteApplicationWithoutException() {
assertDoesNotThrow(() -> App.main(new String[]{}));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,17 +23,19 @@

package com.iluwatar.doublebuffer;

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.fail;

import java.util.Arrays;
import org.junit.Assert;
import org.junit.Test;
import org.junit.jupiter.api.Test;

/**
* FrameBuffer unit test.
*/
public class FrameBufferTest {
class FrameBufferTest {

@Test
public void testClearAll() {
void testClearAll() {
try {
var field = FrameBuffer.class.getDeclaredField("pixels");
var pixels = new Pixel[FrameBuffer.HEIGHT * FrameBuffer.WIDTH];
Expand All @@ -43,14 +45,14 @@ public void testClearAll() {
field.setAccessible(true);
field.set(frameBuffer, pixels);
frameBuffer.clearAll();
Assert.assertEquals(Pixel.WHITE, frameBuffer.getPixels()[0]);
assertEquals(Pixel.WHITE, frameBuffer.getPixels()[0]);
} catch (NoSuchFieldException | IllegalAccessException e) {
Assert.fail("Fail to modify field access.");
fail("Fail to modify field access.");
}
}

@Test
public void testClear() {
void testClear() {
try {
var field = FrameBuffer.class.getDeclaredField("pixels");
var pixels = new Pixel[FrameBuffer.HEIGHT * FrameBuffer.WIDTH];
Expand All @@ -60,21 +62,21 @@ public void testClear() {
field.setAccessible(true);
field.set(frameBuffer, pixels);
frameBuffer.clear(0, 0);
Assert.assertEquals(Pixel.WHITE, frameBuffer.getPixels()[0]);
assertEquals(Pixel.WHITE, frameBuffer.getPixels()[0]);
} catch (NoSuchFieldException | IllegalAccessException e) {
Assert.fail("Fail to modify field access.");
fail("Fail to modify field access.");
}
}

@Test
public void testDraw() {
void testDraw() {
var frameBuffer = new FrameBuffer();
frameBuffer.draw(0, 0);
Assert.assertEquals(Pixel.BLACK, frameBuffer.getPixels()[0]);
assertEquals(Pixel.BLACK, frameBuffer.getPixels()[0]);
}

@Test
public void testGetPixels() {
void testGetPixels() {
try {
var field = FrameBuffer.class.getDeclaredField("pixels");
var pixels = new Pixel[FrameBuffer.HEIGHT * FrameBuffer.WIDTH];
Expand All @@ -83,9 +85,9 @@ public void testGetPixels() {
var frameBuffer = new FrameBuffer();
field.setAccessible(true);
field.set(frameBuffer, pixels);
Assert.assertEquals(pixels, frameBuffer.getPixels());
assertEquals(pixels, frameBuffer.getPixels());
} catch (NoSuchFieldException | IllegalAccessException e) {
Assert.fail("Fail to modify field access.");
fail("Fail to modify field access.");
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,17 +23,19 @@

package com.iluwatar.doublebuffer;

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.fail;

import java.util.ArrayList;
import org.junit.Assert;
import org.junit.Test;
import org.junit.jupiter.api.Test;

/**
* Scene unit tests.
*/
public class SceneTest {
class SceneTest {

@Test
public void testGetBuffer() {
void testGetBuffer() {
try {
var scene = new Scene();
var field1 = Scene.class.getDeclaredField("current");
Expand All @@ -46,14 +48,14 @@ public void testGetBuffer() {
var field2 = Scene.class.getDeclaredField("frameBuffers");
field2.setAccessible(true);
field2.set(scene, frameBuffers);
Assert.assertEquals(frameBuffer, scene.getBuffer());
assertEquals(frameBuffer, scene.getBuffer());
} catch (NoSuchFieldException | IllegalAccessException e) {
Assert.fail("Fail to access private field.");
fail("Fail to access private field.");
}
}

@Test
public void testDraw() {
void testDraw() {
try {
var scene = new Scene();
var field1 = Scene.class.getDeclaredField("current");
Expand All @@ -63,10 +65,10 @@ public void testDraw() {
field2.setAccessible(true);
field2.set(scene, 1);
scene.draw(new ArrayList<>());
Assert.assertEquals(1, field1.get(scene));
Assert.assertEquals(0, field2.get(scene));
assertEquals(1, field1.get(scene));
assertEquals(0, field2.get(scene));
} catch (NoSuchFieldException | IllegalAccessException e) {
Assert.fail("Fail to access private field");
fail("Fail to access private field");
}
}
}