Skip to content

Commit 7ca3fc3

Browse files
committed
add assertj depdendency & assertEquals to assertThat
1 parent 34cb93b commit 7ca3fc3

File tree

10 files changed

+44
-49
lines changed

10 files changed

+44
-49
lines changed

build.gradle

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,4 +14,5 @@ dependencies {
1414
compile('com.google.guava:guava:23.0')
1515
compile('ch.qos.logback:logback-classic:1.2.3')
1616
testCompile('junit:junit:4.12')
17+
testCompile('org.assertj:assertj-core:3.9.0')
1718
}

pom.xml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,12 @@
4444
<version>4.12</version>
4545
<scope>test</scope>
4646
</dependency>
47+
<dependency>
48+
<groupId>org.assertj</groupId>
49+
<artifactId>assertj-core</artifactId>
50+
<version>3.9.0</version>
51+
<scope>test</scope>
52+
</dependency>
4753
</dependencies>
4854
<build>
4955
<plugins>

src/test/java/next/exception/PositionTest.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,22 @@
11
package next.exception;
22

3-
import static org.junit.Assert.*;
3+
import static org.assertj.core.api.Assertions.assertThat;
44

55
import org.junit.Test;
66

77
public class PositionTest {
88
@Test
99
public void create_00() {
1010
Position p = new Position("a1");
11-
assertEquals(0, p.getX());
12-
assertEquals(0, p.getY());
11+
assertThat(p.getX()).isEqualTo(0);
12+
assertThat(p.getY()).isEqualTo(0);
1313
}
1414

1515
@Test
1616
public void create_77() {
1717
Position p = new Position("h8");
18-
assertEquals(7, p.getX());
19-
assertEquals(7, p.getY());
18+
assertThat(p.getX()).isEqualTo(7);
19+
assertThat(p.getY()).isEqualTo(7);
2020
}
2121

2222
@Test (expected = InValidPositionException.class)

src/test/java/next/fp/CarTest.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
package next.fp;
22

3-
import org.junit.Test;
3+
import static org.assertj.core.api.Assertions.assertThat;
44

5-
import static org.junit.Assert.assertEquals;
5+
import org.junit.Test;
66

77
public class CarTest {
88
@Test
@@ -14,7 +14,7 @@ public boolean isMovable() {
1414
return true;
1515
}
1616
});
17-
assertEquals(new Car("pobi", 1), actual);
17+
assertThat(actual).isEqualTo(new Car("pobi", 1));
1818
}
1919

2020
@Test
@@ -26,6 +26,6 @@ public boolean isMovable() {
2626
return false;
2727
}
2828
});
29-
assertEquals(new Car("pobi", 0), actual);
29+
assertThat(actual).isEqualTo(new Car("pobi", 0));
3030
}
3131
}

src/test/java/next/fp/LambdaTest.java

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,13 @@
11
package next.fp;
22

3-
import static org.junit.Assert.*;
3+
import static org.assertj.core.api.Assertions.assertThat;
44

55
import java.util.Arrays;
66
import java.util.List;
77

88
import org.junit.Before;
99
import org.junit.Test;
1010

11-
import next.fp.Lambda;
12-
1311
public class LambdaTest {
1412
private List<Integer> numbers;
1513

@@ -36,18 +34,18 @@ public void runThread() throws Exception {
3634
@Test
3735
public void sumAll() throws Exception {
3836
int sum = Lambda.sumAll(numbers);
39-
assertEquals(21, sum);
37+
assertThat(sum).isEqualTo(21);
4038
}
4139

4240
@Test
4341
public void sumAllEven() throws Exception {
4442
int sum = Lambda.sumAllEven(numbers);
45-
assertEquals(12, sum);
43+
assertThat(sum).isEqualTo(12);
4644
}
4745

4846
@Test
4947
public void sumAllOverThree() throws Exception {
5048
int sum = Lambda.sumAllOverThree(numbers);
51-
assertEquals(15, sum);
49+
assertThat(sum).isEqualTo(15);
5250
}
5351
}

src/test/java/next/fp/StreamStudyTest.java

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,13 @@
11
package next.fp;
22

3-
import static org.junit.Assert.*;
3+
import static org.assertj.core.api.Assertions.assertThat;
44

55
import java.util.Arrays;
66
import java.util.List;
77

88
import org.junit.Before;
99
import org.junit.Test;
1010

11-
import next.fp.StreamStudy;
12-
1311
public class StreamStudyTest {
1412
private List<Integer> numbers;
1513

@@ -38,13 +36,13 @@ public void map() throws Exception {
3836
@Test
3937
public void sumAll() throws Exception {
4038
long sum = StreamStudy.sumAll(numbers);
41-
assertEquals(21, sum);
39+
assertThat(sum).isEqualTo(21);
4240
}
4341

4442
@Test
4543
public void sumOverThreeAndDouble() throws Exception {
4644
numbers = Arrays.asList(3, 1, 6, 2, 4, 8);
4745
long sum = StreamStudy.sumOverThreeAndDouble(numbers);
48-
assertEquals(36, sum);
46+
assertThat(sum).isEqualTo(36);
4947
}
5048
}
Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,9 @@
11
package next.optional;
22

3-
import static org.junit.Assert.*;
3+
import static org.assertj.core.api.Assertions.assertThat;
44

55
import org.junit.Test;
66

7-
import next.optional.Computer;
8-
import next.optional.ComputerStore;
97
import next.optional.Computer.Soundcard;
108
import next.optional.Computer.USB;
119

@@ -16,23 +14,23 @@ public void getVersion() {
1614
String version = "pobi's usb";
1715
Soundcard soundcard = new Soundcard(new USB(version));
1816
Computer computer = new Computer(soundcard);
19-
assertEquals(version, ComputerStore.getVersion(computer));
17+
assertThat(ComputerStore.getVersion(computer)).isEqualTo(version);
2018
}
2119

2220
@Test
2321
public void getVersionWhenComputerIsNull() throws Exception {
24-
assertEquals(ComputerStore.UNKNOWN_VERSION, ComputerStore.getVersion(null));
22+
assertThat(ComputerStore.getVersion(null)).isEqualTo(ComputerStore.UNKNOWN_VERSION);
2523
}
2624

2725
@Test
2826
public void getVersionWhenSoundcardIsNull() throws Exception {
2927
Computer computer = new Computer(null);
30-
assertEquals(ComputerStore.UNKNOWN_VERSION, ComputerStore.getVersion(computer));
28+
assertThat(ComputerStore.getVersion(computer)).isEqualTo(ComputerStore.UNKNOWN_VERSION);
3129
}
3230

3331
@Test
3432
public void getVersionWhenUSBIsNull() throws Exception {
3533
Computer computer = new Computer(new Soundcard(null));
36-
assertEquals(ComputerStore.UNKNOWN_VERSION, ComputerStore.getVersion(computer));
34+
assertThat(ComputerStore.getVersion(computer)).isEqualTo(ComputerStore.UNKNOWN_VERSION);
3735
}
3836
}

src/test/java/next/optional/ExpressionTest.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,14 @@
11
package next.optional;
22

3-
import static org.junit.Assert.*;
3+
import static org.assertj.core.api.Assertions.assertThat;
44

55
import org.junit.Test;
66

7-
import next.optional.Expression;
87

98
public class ExpressionTest {
109
@Test
1110
public void of() {
12-
assertTrue(Expression.PLUS == Expression.of("+"));
11+
assertThat(Expression.PLUS == Expression.of("+")).isTrue();
1312
}
1413

1514
@Test (expected = IllegalArgumentException.class)
Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,26 @@
11
package next.optional;
22

33
import static next.optional.User.*;
4-
import static org.junit.Assert.*;
4+
import static org.assertj.core.api.Assertions.assertThat;
55

66
import org.junit.Test;
77

8-
import next.optional.User;
9-
108
public class UserTest {
119
@Test
1210
public void whenFiltersWithoutOptional_thenCorrect() {
13-
assertTrue(ageIsInRange1(new User("crong", 35)));
14-
assertFalse(ageIsInRange1(new User("crong", 48)));
15-
assertFalse(ageIsInRange1(new User("crong", null)));
16-
assertFalse(ageIsInRange1(new User("crong", 29)));
17-
assertFalse(ageIsInRange1(null));
11+
assertThat(ageIsInRange1(new User("crong", 35))).isTrue();
12+
assertThat(ageIsInRange1(new User("crong", 48))).isFalse();
13+
assertThat(ageIsInRange1(new User("crong", null))).isFalse();
14+
assertThat(ageIsInRange1(new User("crong", 29))).isFalse();
15+
assertThat(ageIsInRange1(null)).isFalse();
1816
}
1917

2018
@Test
2119
public void whenFiltersWithOptional_thenCorrect() {
22-
assertTrue(ageIsInRange2(new User("crong", 35)));
23-
assertFalse(ageIsInRange2(new User("crong", 48)));
24-
assertFalse(ageIsInRange2(new User("crong", null)));
25-
assertFalse(ageIsInRange2(new User("crong", 29)));
26-
assertFalse(ageIsInRange2(null));
20+
assertThat(ageIsInRange2(new User("crong", 35))).isTrue();
21+
assertThat(ageIsInRange2(new User("crong", 48))).isFalse();
22+
assertThat(ageIsInRange2(new User("crong", null))).isFalse();
23+
assertThat(ageIsInRange2(new User("crong", 29))).isFalse();
24+
assertThat(ageIsInRange2(null)).isFalse();
2725
}
2826
}
Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,21 @@
11
package next.optional;
22

3-
import static org.junit.Assert.*;
3+
import static org.assertj.core.api.Assertions.assertThat;
44

55
import org.junit.Test;
66

7-
import next.optional.User;
8-
import next.optional.Users;
9-
107
public class UsersTest {
118

129
@Test
1310
public void getUser() {
1411
Users users = new Users();
15-
assertEquals(new User("crong", 35), users.getUser("crong"));
12+
assertThat(users.getUser("crong")).isEqualTo(new User("crong", 35));
1613
}
1714

1815

1916
@Test
2017
public void getDefaultUser() {
2118
Users users = new Users();
22-
assertEquals(Users.DEFAULT_USER, users.getUser("codesquard"));
19+
assertThat(users.getUser("codesquard")).isEqualTo(Users.DEFAULT_USER);
2320
}
2421
}

0 commit comments

Comments
 (0)