Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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
4 changes: 2 additions & 2 deletions arrange-act-assert/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,8 @@
<artifactId>arrange-act-assert</artifactId>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-engine</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,11 @@

package com.iluwatar.arrangeactassert;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertTrue;

import org.junit.Test;
import org.junit.jupiter.api.Test;

/**
* Arrange/Act/Assert (AAA) is a pattern for organizing unit tests. It is a way to structure your
Expand All @@ -51,10 +51,11 @@
* change and one reason to fail. In a large and complicated code base, tests that honor the single
* responsibility principle are much easier to troubleshoot.
*/
public class CashAAATest {

class CashAAATest {

@Test
public void testPlus() {
void testPlus() {
//Arrange
var cash = new Cash(3);
//Act
Expand All @@ -64,7 +65,7 @@ public void testPlus() {
}

@Test
public void testMinus() {
void testMinus() {
//Arrange
var cash = new Cash(8);
//Act
Expand All @@ -75,7 +76,7 @@ public void testMinus() {
}

@Test
public void testInsufficientMinus() {
void testInsufficientMinus() {
//Arrange
var cash = new Cash(1);
//Act
Expand All @@ -86,7 +87,7 @@ public void testInsufficientMinus() {
}

@Test
public void testUpdate() {
void testUpdate() {
//Arrange
var cash = new Cash(5);
//Act
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,23 +23,24 @@

package com.iluwatar.arrangeactassert;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertTrue;

import org.junit.Test;
import org.junit.jupiter.api.Test;

/**
* ({@link CashAAATest}) is an anti-example of AAA pattern. This test is functionally correct, but
* with the addition of new feature, it needs refactoring. There are an awful lot of steps in that
* with the addition of a new feature, it needs refactoring. There are an awful lot of steps in that
* test method, but it verifies the class' important behavior in just eleven lines. It violates the
* single responsibility principle. If this test method failed after a small code change, it might
* take some digging to discover why.
*/
public class CashAntiAAATest {

class CashAntiAAATest {

@Test
public void testCash() {
void testCash() {
//initialize
var cash = new Cash(3);
//test plus
Expand Down
5 changes: 0 additions & 5 deletions async-method-invocation/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -45,11 +45,6 @@
<artifactId>mockito-core</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<plugins>
Expand Down
6 changes: 0 additions & 6 deletions combinator/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -34,12 +34,6 @@

<artifactId>combinator</artifactId>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<scope>test</scope>
</dependency>

<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-engine</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,11 @@

package com.iluwatar.combinator;

import org.junit.Test;

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

public class CombinatorAppTest {
import org.junit.jupiter.api.Test;

class CombinatorAppTest {

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

@Test
public void shouldExecuteApplicationWithoutException() {
void shouldExecuteApplicationWithoutException() {
assertDoesNotThrow(() -> CombinatorApp.main(new String[]{}));
}
}
}
17 changes: 7 additions & 10 deletions combinator/src/test/java/com/iluwatar/combinator/FinderTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,22 +23,19 @@

package com.iluwatar.combinator;

import org.junit.Assert;
import org.junit.Test;
import static org.junit.jupiter.api.Assertions.assertEquals;

import java.util.List;
import org.junit.jupiter.api.Test;

import static org.junit.Assert.*;

public class FinderTest {
class FinderTest {

@Test
public void contains() {
void contains() {
var example = "the first one \nthe second one \n";

var result = Finder.contains("second").find(example);
Assert.assertEquals(result.size(),1);
Assert.assertEquals(result.get(0),"the second one ");
assertEquals(1, result.size());
assertEquals("the second one ", result.get(0));
}

}
}
44 changes: 22 additions & 22 deletions combinator/src/test/java/com/iluwatar/combinator/FindersTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,44 +23,44 @@

package com.iluwatar.combinator;

import org.junit.Assert;
import org.junit.Test;
import static com.iluwatar.combinator.Finders.advancedFinder;
import static com.iluwatar.combinator.Finders.expandedFinder;
import static com.iluwatar.combinator.Finders.filteredFinder;
import static com.iluwatar.combinator.Finders.specializedFinder;
import static org.junit.jupiter.api.Assertions.assertEquals;

import java.util.List;
import org.junit.jupiter.api.Test;

import static com.iluwatar.combinator.Finders.*;
import static org.junit.Assert.*;

public class FindersTest {
class FindersTest {

@Test
public void advancedFinderTest() {
void advancedFinderTest() {
var res = advancedFinder("it was","kingdom","sea").find(text());
Assert.assertEquals(res.size(),1);
Assert.assertEquals(res.get(0),"It was many and many a year ago,");
assertEquals(1, res.size());
assertEquals("It was many and many a year ago,", res.get(0));
}

@Test
public void filteredFinderTest() {
void filteredFinderTest() {
var res = filteredFinder(" was ", "many", "child").find(text());
Assert.assertEquals(res.size(),1);
Assert.assertEquals(res.get(0),"But we loved with a love that was more than love-");
assertEquals(1, res.size());
assertEquals("But we loved with a love that was more than love-", res.get(0));
}

@Test
public void specializedFinderTest() {
void specializedFinderTest() {
var res = specializedFinder("love","heaven").find(text());
Assert.assertEquals(res.size(),1);
Assert.assertEquals(res.get(0),"With a love that the winged seraphs of heaven");
assertEquals(1, res.size());
assertEquals("With a love that the winged seraphs of heaven", res.get(0));
}

@Test
public void expandedFinderTest() {
void expandedFinderTest() {
var res = expandedFinder("It was","kingdom").find(text());
Assert.assertEquals(res.size(),3);
Assert.assertEquals(res.get(0),"It was many and many a year ago,");
Assert.assertEquals(res.get(1),"In a kingdom by the sea,");
Assert.assertEquals(res.get(2),"In this kingdom by the sea;");
assertEquals(3, res.size());
assertEquals("It was many and many a year ago,", res.get(0));
assertEquals("In a kingdom by the sea,", res.get(1));
assertEquals("In this kingdom by the sea;", res.get(2));
}


Expand All @@ -80,4 +80,4 @@ private String text(){
+ "Coveted her and me.";
}

}
}
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
Loading