Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Updates tests to use assertThat instead of assertEquals #2511

Merged
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
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import org.junit.Ignore;
import org.junit.Test;

import static org.junit.Assert.assertEquals;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.withPrecision;

public class ComplexNumberTest {

Expand All @@ -12,7 +13,7 @@ public class ComplexNumberTest {
private void assertDoublesEqual(double d1, double d2, String numberPart) {
String errorMessage = "While testing " + numberPart + " part of number,";

assertEquals(errorMessage, d1, d2, DOUBLE_EQUALITY_TOLERANCE);
assertThat(d1).withFailMessage(errorMessage).isCloseTo(d2, withPrecision(DOUBLE_EQUALITY_TOLERANCE));
}

private void assertComplexNumbersEqual(ComplexNumber c1, ComplexNumber c2) {
Expand Down
18 changes: 11 additions & 7 deletions exercises/practice/etl/src/test/java/EtlTest.java
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
import org.junit.Test;
import org.junit.Ignore;
import org.junit.Test;

import java.util.*;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import static org.junit.Assert.assertEquals;
import static org.assertj.core.api.Assertions.assertThat;


public class EtlTest {
Expand All @@ -25,7 +29,7 @@ public void testTransformOneValue() {
};
expected = Collections.unmodifiableMap(expected);

assertEquals(expected, etl.transform(old));
assertThat(etl.transform(old)).isEqualTo(expected);
}

@Ignore("Remove to run test")
Expand All @@ -49,7 +53,7 @@ public void testTransformMoreValues() {
};
expected = Collections.unmodifiableMap(expected);

assertEquals(expected, etl.transform(old));
assertThat(etl.transform(old)).isEqualTo(expected);
}

@Ignore("Remove to run test")
Expand All @@ -73,7 +77,7 @@ public void testMoreKeys() {
};
expected = Collections.unmodifiableMap(expected);

assertEquals(expected, etl.transform(old));
assertThat(etl.transform(old)).isEqualTo(expected);
}

@Ignore("Remove to run test")
Expand Down Expand Up @@ -124,6 +128,6 @@ public void testFullDataset() {
};
expected = Collections.unmodifiableMap(expected);

assertEquals(expected, etl.transform(old));
assertThat(etl.transform(old)).isEqualTo(expected);
}
}
51 changes: 23 additions & 28 deletions exercises/practice/flatten-array/src/test/java/FlattenerTest.java
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
import org.junit.Before;
import org.junit.Test;
import org.junit.Ignore;
import org.junit.Test;

import static java.util.Arrays.asList;
import static java.util.Collections.emptyList;
import static java.util.Collections.singletonList;
import static org.junit.Assert.assertEquals;
import static org.assertj.core.api.Assertions.assertThat;

public class FlattenerTest {

Expand All @@ -18,67 +17,63 @@ public void setUp() {

@Test
public void testFlatListIsPreserved() {
assertEquals(asList(0, '1', "two"), flattener.flatten(asList(0, '1', "two")));
assertThat(flattener.flatten(asList(0, '1', "two")))
.containsExactly(0, '1', "two");
}

@Ignore("Remove to run test")
@Test
public void testASingleLevelOfNestingWithNoNulls() {
assertEquals(
asList(1, '2', 3, 4, 5, "six", "7", 8),
flattener.flatten(asList(1, asList('2', 3, 4, 5, "six", "7"), 8)));
assertThat(flattener.flatten(asList(1, asList('2', 3, 4, 5, "six", "7"), 8)))
.containsExactly(1, '2', 3, 4, 5, "six", "7", 8);
}

@Ignore("Remove to run test")
@Test
public void testFiveLevelsOfNestingWithNoNulls() {
assertEquals(
asList(0, '2', 2, "three", '8', 100, "four", 50, "-2"),
flattener.flatten(asList(0,
assertThat(flattener.flatten(asList(0,
'2',
asList(asList(2, "three"),
'8',
100,
"four",
singletonList(singletonList(singletonList(50)))), "-2")));
singletonList(singletonList(singletonList(50)))), "-2")))
.containsExactly(0, '2', 2, "three", '8', 100, "four", 50, "-2");
}

@Ignore("Remove to run test")
@Test
public void testSixLevelsOfNestingWithNoNulls() {
assertEquals(
asList("one", '2', 3, '4', 5, "six", 7, "8"),
flattener.flatten(asList("one",
asList('2',
assertThat(flattener.flatten(asList("one",
asList('2',
singletonList(singletonList(3)),
asList('4',
singletonList(singletonList(5))), "six", 7), "8")));
asList('4',
singletonList(singletonList(5))), "six", 7), "8")))
.containsExactly("one", '2', 3, '4', 5, "six", 7, "8");
}

@Ignore("Remove to run test")
@Test
public void testSixLevelsOfNestingWithNulls() {
assertEquals(
asList("0", 2, "two", '3', "8", "one hundred", "negative two"),
flattener.flatten(asList("0",
assertThat(flattener.flatten(asList("0",
2,
asList(asList("two", '3'),
"8",
singletonList(singletonList("one hundred")),
null,
singletonList(singletonList(null))),
"negative two")));
null,
singletonList(singletonList(null))),
"negative two")))
.containsExactly("0", 2, "two", '3', "8", "one hundred", "negative two");
}

@Ignore("Remove to run test")
@Test
public void testNestedListsFullOfNullsOnly() {
assertEquals(emptyList(),
flattener.flatten(asList(null,
assertThat(flattener.flatten(asList(null,
singletonList(singletonList(singletonList(null))),
null,
null,
asList(asList(null, null), null), null)));
null,
null,
asList(asList(null, null), null), null))).isEmpty();
}

}
24 changes: 12 additions & 12 deletions exercises/practice/food-chain/src/test/java/FoodChainTest.java
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import org.junit.Before;
import org.junit.Test;
import org.junit.Ignore;
import org.junit.Test;

import static org.junit.Assert.assertEquals;
import static org.assertj.core.api.Assertions.assertThat;

public class FoodChainTest {
private FoodChain foodChain;
Expand All @@ -18,7 +18,7 @@ public void fly() {
String expected = "I know an old lady who swallowed a fly.\n" +
"I don't know why she swallowed the fly. Perhaps she'll die.";

assertEquals(expected, foodChain.verse(verse));
assertThat(foodChain.verse(verse)).isEqualTo(expected);
}

@Test
Expand All @@ -30,7 +30,7 @@ public void spider() {
"She swallowed the spider to catch the fly.\n" +
"I don't know why she swallowed the fly. Perhaps she'll die.";

assertEquals(expected, foodChain.verse(verse));
assertThat(foodChain.verse(verse)).isEqualTo(expected);
}

@Test
Expand All @@ -44,7 +44,7 @@ public void bird() {
"She swallowed the spider to catch the fly.\n" +
"I don't know why she swallowed the fly. Perhaps she'll die.";

assertEquals(expected, foodChain.verse(verse));
assertThat(foodChain.verse(verse)).isEqualTo(expected);
}

@Test
Expand All @@ -59,7 +59,7 @@ public void cat() {
"She swallowed the spider to catch the fly.\n" +
"I don't know why she swallowed the fly. Perhaps she'll die.";

assertEquals(expected, foodChain.verse(verse));
assertThat(foodChain.verse(verse)).isEqualTo(expected);
}


Expand All @@ -76,7 +76,7 @@ public void dog() {
"She swallowed the spider to catch the fly.\n" +
"I don't know why she swallowed the fly. Perhaps she'll die.";

assertEquals(expected, foodChain.verse(verse));
assertThat(foodChain.verse(verse)).isEqualTo(expected);
}

@Test
Expand All @@ -93,7 +93,7 @@ public void goat() {
"She swallowed the spider to catch the fly.\n" +
"I don't know why she swallowed the fly. Perhaps she'll die.";

assertEquals(expected, foodChain.verse(verse));
assertThat(foodChain.verse(verse)).isEqualTo(expected);
}

@Test
Expand All @@ -111,7 +111,7 @@ public void cow() {
"She swallowed the spider to catch the fly.\n" +
"I don't know why she swallowed the fly. Perhaps she'll die.";

assertEquals(expected, foodChain.verse(verse));
assertThat(foodChain.verse(verse)).isEqualTo(expected);
}

@Test
Expand All @@ -121,7 +121,7 @@ public void horse() {
String expected = "I know an old lady who swallowed a horse.\n" +
"She's dead, of course!";

assertEquals(expected, foodChain.verse(verse));
assertThat(foodChain.verse(verse)).isEqualTo(expected);
}


Expand All @@ -145,7 +145,7 @@ public void multipleVerses() {
"She swallowed the spider to catch the fly.\n" +
"I don't know why she swallowed the fly. Perhaps she'll die.";

assertEquals(expected, foodChain.verses(startVerse, endVerse));
assertThat(foodChain.verses(startVerse, endVerse)).isEqualTo(expected);
}


Expand Down Expand Up @@ -210,6 +210,6 @@ public void wholeSong() {
"I know an old lady who swallowed a horse.\n" +
"She's dead, of course!";

assertEquals(expected, foodChain.verses(startVerse, endVerse));
assertThat(foodChain.verses(startVerse, endVerse)).isEqualTo(expected);
}
}
14 changes: 7 additions & 7 deletions exercises/practice/gigasecond/src/test/java/GigasecondTest.java
Original file line number Diff line number Diff line change
@@ -1,50 +1,50 @@
import org.junit.Test;
import org.junit.Ignore;
import org.junit.Test;

import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.Month;

import static org.junit.Assert.assertEquals;
import static org.assertj.core.api.Assertions.assertThat;

public class GigasecondTest {

@Test
public void modernTime() {
Gigasecond gigaSecond = new Gigasecond(LocalDate.of(2011, Month.APRIL, 25));

assertEquals(LocalDateTime.of(2043, Month.JANUARY, 1, 1, 46, 40), gigaSecond.getDateTime());
assertThat(gigaSecond.getDateTime()).isEqualTo(LocalDateTime.of(2043, Month.JANUARY, 1, 1, 46, 40));
}

@Ignore("Remove to run test")
@Test
public void afterEpochTime() {
Gigasecond gigaSecond = new Gigasecond(LocalDate.of(1977, Month.JUNE, 13));

assertEquals(LocalDateTime.of(2009, Month.FEBRUARY, 19, 1, 46, 40), gigaSecond.getDateTime());
assertThat(gigaSecond.getDateTime()).isEqualTo(LocalDateTime.of(2009, Month.FEBRUARY, 19, 1, 46, 40));
}

@Ignore("Remove to run test")
@Test
public void beforeEpochTime() {
Gigasecond gigaSecond = new Gigasecond(LocalDate.of(1959, Month.JULY, 19));

assertEquals(LocalDateTime.of(1991, Month.MARCH, 27, 1, 46, 40), gigaSecond.getDateTime());
assertThat(gigaSecond.getDateTime()).isEqualTo(LocalDateTime.of(1991, Month.MARCH, 27, 1, 46, 40));
}

@Ignore("Remove to run test")
@Test
public void withFullTimeSpecified() {
Gigasecond gigaSecond = new Gigasecond(LocalDateTime.of(2015, Month.JANUARY, 24, 22, 0, 0));

assertEquals(LocalDateTime.of(2046, Month.OCTOBER, 2, 23, 46, 40), gigaSecond.getDateTime());
assertThat(gigaSecond.getDateTime()).isEqualTo(LocalDateTime.of(2046, Month.OCTOBER, 2, 23, 46, 40));
}

@Ignore("Remove to run test")
@Test
public void withFullTimeSpecifiedAndDayRollover() {
Gigasecond gigaSecond = new Gigasecond(LocalDateTime.of(2015, Month.JANUARY, 24, 23, 59, 59));

assertEquals(LocalDateTime.of(2046, Month.OCTOBER, 3, 1, 46, 39), gigaSecond.getDateTime());
assertThat(gigaSecond.getDateTime()).isEqualTo(LocalDateTime.of(2046, Month.OCTOBER, 3, 1, 46, 39));
}
}
Loading