Skip to content

Commit 2d309b8

Browse files
kongleong86iluwatarrobertvolkmann
authored
dependencies: Refactor unit tests without depending on Guava (iluwatar#2181)
* Refactor unit tests without depending on Guava * Remove redundant casts. * Move import up * Update repository/src/test/java/com/iluwatar/repository/RepositoryTest.java Co-authored-by: Robert Volkmann <[email protected]> * Update repository/src/test/java/com/iluwatar/repository/AnnotationBasedRepositoryTest.java Co-authored-by: Robert Volkmann <[email protected]> Co-authored-by: Ilkka Seppälä <[email protected]> Co-authored-by: Robert Volkmann <[email protected]>
1 parent ce5605b commit 2d309b8

File tree

11 files changed

+14
-50
lines changed

11 files changed

+14
-50
lines changed

Diff for: converter/pom.xml

-4
Original file line numberDiff line numberDiff line change
@@ -39,10 +39,6 @@
3939
<artifactId>junit-jupiter-engine</artifactId>
4040
<scope>test</scope>
4141
</dependency>
42-
<dependency>
43-
<groupId>com.google.guava</groupId>
44-
<artifactId>guava</artifactId>
45-
</dependency>
4642
</dependencies>
4743
<build>
4844
<plugins>

Diff for: filterer/pom.xml

-4
Original file line numberDiff line numberDiff line change
@@ -34,10 +34,6 @@
3434
<modelVersion>4.0.0</modelVersion>
3535
<artifactId>filterer</artifactId>
3636
<dependencies>
37-
<dependency>
38-
<groupId>com.google.guava</groupId>
39-
<artifactId>guava</artifactId>
40-
</dependency>
4137
<dependency>
4238
<groupId>org.junit.jupiter</groupId>
4339
<artifactId>junit-jupiter-api</artifactId>

Diff for: model-view-viewmodel/pom.xml

-7
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,6 @@
3737
<version>1.26.0-SNAPSHOT</version>
3838
<properties>
3939
<zk.version>9.0.0</zk.version>
40-
<guava.version>19.0</guava.version>
4140
<jetty-maven-plugin.version>9.4.28.v20200408</jetty-maven-plugin.version>
4241
<maven-war-plugin.version>3.3.2</maven-war-plugin.version>
4342
<maven-assembly-plugin.version>2.2</maven-assembly-plugin.version>
@@ -84,12 +83,6 @@
8483
<artifactId>junit-jupiter-engine</artifactId>
8584
<scope>test</scope>
8685
</dependency>
87-
<dependency>
88-
<groupId>com.google.guava</groupId>
89-
<artifactId>guava-testlib</artifactId>
90-
<version>${guava.version}</version>
91-
<scope>test</scope>
92-
</dependency>
9386
</dependencies>
9487
<build>
9588
<finalName>${project.artifactId}</finalName>

Diff for: model-view-viewmodel/src/test/java/com/iluwatar/model/view/viewmodel/BookTest.java

+4-7
Original file line numberDiff line numberDiff line change
@@ -24,18 +24,15 @@
2424
*/
2525
package com.iluwatar.model.view.viewmodel;
2626

27-
import static org.hamcrest.CoreMatchers.is;
28-
import static org.hamcrest.CoreMatchers.not;
29-
import static org.junit.Assert.assertThat;
3027
import static org.junit.jupiter.api.Assertions.assertEquals;
3128
import static org.junit.jupiter.api.Assertions.assertFalse;
29+
import static org.junit.jupiter.api.Assertions.assertNotEquals;
3230
import static org.junit.jupiter.api.Assertions.assertNotNull;
3331
import static org.junit.jupiter.api.Assertions.assertNull;
3432
import static org.junit.jupiter.api.Assertions.assertTrue;
3533
import java.util.List;
3634
import org.junit.jupiter.api.BeforeEach;
3735
import org.junit.jupiter.api.Test;
38-
import com.google.common.testing.EqualsTester;
3936

4037
class BookTest {
4138

@@ -67,13 +64,13 @@ void testBookModel() {
6764

6865
@Test
6966
void testEquals() {
70-
new EqualsTester().addEqualityGroup(testBook, testBookTwo).testEquals();
67+
assertEquals(testBook, testBookTwo);
7168
}
7269

7370
@Test
7471
void testToString() {
75-
assertThat(testBook.toString(), is(testBookTwo.toString()));
76-
assertThat(testBook.toString(), is(not(testBookThree.toString())));
72+
assertEquals(testBook.toString(), testBookTwo.toString());
73+
assertNotEquals(testBook.toString(), testBookThree.toString());
7774
}
7875

7976
@Test

Diff for: pom.xml

-6
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,6 @@
4040
<spring-boot.version>2.7.5</spring-boot.version>
4141
<jacoco.version>0.8.8</jacoco.version>
4242
<commons-dbcp.version>1.4</commons-dbcp.version>
43-
<guava.version>19.0</guava.version>
4443
<htmlunit.version>2.66.0</htmlunit.version>
4544
<guice.version>4.0</guice.version>
4645
<system-lambda.version>1.1.0</system-lambda.version>
@@ -223,11 +222,6 @@
223222
<artifactId>commons-dbcp</artifactId>
224223
<version>${commons-dbcp.version}</version>
225224
</dependency>
226-
<dependency>
227-
<groupId>com.google.guava</groupId>
228-
<artifactId>guava</artifactId>
229-
<version>${guava.version}</version>
230-
</dependency>
231225
<dependency>
232226
<groupId>net.sourceforge.htmlunit</groupId>
233227
<artifactId>htmlunit</artifactId>

Diff for: repository/pom.xml

-4
Original file line numberDiff line numberDiff line change
@@ -55,10 +55,6 @@
5555
<artifactId>junit-jupiter-engine</artifactId>
5656
<scope>test</scope>
5757
</dependency>
58-
<dependency>
59-
<groupId>com.google.guava</groupId>
60-
<artifactId>guava</artifactId>
61-
</dependency>
6258
<dependency>
6359
<groupId>javax.xml.bind</groupId>
6460
<artifactId>jaxb-api</artifactId>

Diff for: repository/src/main/java/com/iluwatar/repository/PersonRepository.java

+3
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
*/
2525
package com.iluwatar.repository;
2626

27+
import java.util.List;
2728
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
2829
import org.springframework.data.repository.CrudRepository;
2930
import org.springframework.stereotype.Repository;
@@ -36,4 +37,6 @@ public interface PersonRepository
3637
extends CrudRepository<Person, Long>, JpaSpecificationExecutor<Person> {
3738

3839
Person findByName(String name);
40+
41+
List<Person> findAll();
3942
}

Diff for: repository/src/test/java/com/iluwatar/repository/AnnotationBasedRepositoryTest.java

+1-2
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@
2828
import static org.junit.jupiter.api.Assertions.assertNull;
2929
import static org.junit.jupiter.api.Assertions.assertTrue;
3030

31-
import com.google.common.collect.Lists;
3231
import java.util.List;
3332
import javax.annotation.Resource;
3433
import org.junit.jupiter.api.AfterEach;
@@ -66,7 +65,7 @@ void setup() {
6665

6766
@Test
6867
void testFindAll() {
69-
var actuals = Lists.newArrayList(repository.findAll());
68+
var actuals = repository.findAll();
7069
assertTrue(actuals.containsAll(persons) && persons.containsAll(actuals));
7170
}
7271

Diff for: repository/src/test/java/com/iluwatar/repository/RepositoryTest.java

+1-2
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@
2828
import static org.junit.jupiter.api.Assertions.assertNull;
2929
import static org.junit.jupiter.api.Assertions.assertTrue;
3030

31-
import com.google.common.collect.Lists;
3231
import java.util.List;
3332
import javax.annotation.Resource;
3433
import org.junit.jupiter.api.AfterEach;
@@ -66,7 +65,7 @@ void setup() {
6665

6766
@Test
6867
void testFindAll() {
69-
var actuals = Lists.newArrayList(repository.findAll());
68+
var actuals = repository.findAll();
7069
assertTrue(actuals.containsAll(persons) && persons.containsAll(actuals));
7170
}
7271

Diff for: value-object/pom.xml

-6
Original file line numberDiff line numberDiff line change
@@ -34,12 +34,6 @@
3434
</parent>
3535
<artifactId>value-object</artifactId>
3636
<dependencies>
37-
<dependency>
38-
<groupId>com.google.guava</groupId>
39-
<artifactId>guava-testlib</artifactId>
40-
<version>23.0</version>
41-
<scope>test</scope>
42-
</dependency>
4337
<dependency>
4438
<groupId>org.junit.jupiter</groupId>
4539
<artifactId>junit-jupiter-engine</artifactId>

Diff for: value-object/src/test/java/com/iluwatar/value/object/HeroStatTest.java

+5-8
Original file line numberDiff line numberDiff line change
@@ -24,11 +24,9 @@
2424
*/
2525
package com.iluwatar.value.object;
2626

27-
import static org.hamcrest.CoreMatchers.is;
28-
import static org.hamcrest.CoreMatchers.not;
29-
import static org.junit.Assert.assertThat;
27+
import static org.junit.jupiter.api.Assertions.assertEquals;
28+
import static org.junit.jupiter.api.Assertions.assertNotEquals;
3029

31-
import com.google.common.testing.EqualsTester;
3230
import org.junit.jupiter.api.Test;
3331

3432
/**
@@ -47,7 +45,7 @@ class HeroStatTest {
4745
void testEquals() {
4846
var heroStatA = HeroStat.valueOf(3, 9, 2);
4947
var heroStatB = HeroStat.valueOf(3, 9, 2);
50-
new EqualsTester().addEqualityGroup(heroStatA, heroStatB).testEquals();
48+
assertEquals(heroStatA, heroStatB);
5149
}
5250

5351
/**
@@ -59,9 +57,8 @@ void testToString() {
5957
var heroStatA = HeroStat.valueOf(3, 9, 2);
6058
var heroStatB = HeroStat.valueOf(3, 9, 2);
6159
var heroStatC = HeroStat.valueOf(3, 9, 8);
62-
63-
assertThat(heroStatA.toString(), is(heroStatB.toString()));
64-
assertThat(heroStatA.toString(), is(not(heroStatC.toString())));
60+
assertEquals(heroStatA.toString(), heroStatB.toString());
61+
assertNotEquals(heroStatA.toString(), heroStatC.toString());
6562
}
6663

6764
}

0 commit comments

Comments
 (0)