dependencies: Refactor unit tests without depending on Guava (#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 <20912167+robertvolkmann@users.noreply.github.com>

* Update repository/src/test/java/com/iluwatar/repository/AnnotationBasedRepositoryTest.java

Co-authored-by: Robert Volkmann <20912167+robertvolkmann@users.noreply.github.com>

Co-authored-by: Ilkka Seppälä <iluwatar@users.noreply.github.com>
Co-authored-by: Robert Volkmann <20912167+robertvolkmann@users.noreply.github.com>
This commit is contained in:
authored and GitHub committed 2022-12-04 11:25:57 +02:00
1 parent ce5605b4d5
commit 2d309b8928
11 files changed
+14 -50

No files matched your search

-4
View File
@@ -39,10 +39,6 @@
<artifactId>junit-jupiter-engine</artifactId> <artifactId>junit-jupiter-engine</artifactId>
<scope>test</scope> <scope>test</scope>
</dependency> </dependency>
<dependency>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
</dependency>
</dependencies> </dependencies>
<build> <build>
<plugins> <plugins>
-4
View File
@@ -34,10 +34,6 @@
<modelVersion>4.0.0</modelVersion> <modelVersion>4.0.0</modelVersion>
<artifactId>filterer</artifactId> <artifactId>filterer</artifactId>
<dependencies> <dependencies>
<dependency>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
</dependency>
<dependency> <dependency>
<groupId>org.junit.jupiter</groupId> <groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-api</artifactId> <artifactId>junit-jupiter-api</artifactId>
-7
View File
@@ -37,7 +37,6 @@
<version>1.26.0-SNAPSHOT</version> <version>1.26.0-SNAPSHOT</version>
<properties> <properties>
<zk.version>9.0.0</zk.version> <zk.version>9.0.0</zk.version>
<guava.version>19.0</guava.version>
<jetty-maven-plugin.version>9.4.28.v20200408</jetty-maven-plugin.version> <jetty-maven-plugin.version>9.4.28.v20200408</jetty-maven-plugin.version>
<maven-war-plugin.version>3.3.2</maven-war-plugin.version> <maven-war-plugin.version>3.3.2</maven-war-plugin.version>
<maven-assembly-plugin.version>2.2</maven-assembly-plugin.version> <maven-assembly-plugin.version>2.2</maven-assembly-plugin.version>
@@ -84,12 +83,6 @@
<artifactId>junit-jupiter-engine</artifactId> <artifactId>junit-jupiter-engine</artifactId>
<scope>test</scope> <scope>test</scope>
</dependency> </dependency>
<dependency>
<groupId>com.google.guava</groupId>
<artifactId>guava-testlib</artifactId>
<version>${guava.version}</version>
<scope>test</scope>
</dependency>
</dependencies> </dependencies>
<build> <build>
<finalName>${project.artifactId}</finalName> <finalName>${project.artifactId}</finalName>
@@ -24,18 +24,15 @@
*/ */
package com.iluwatar.model.view.viewmodel; package com.iluwatar.model.view.viewmodel;
import static org.hamcrest.CoreMatchers.is;
import static org.hamcrest.CoreMatchers.not;
import static org.junit.Assert.assertThat;
import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse; import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertNotEquals;
import static org.junit.jupiter.api.Assertions.assertNotNull; import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertNull; import static org.junit.jupiter.api.Assertions.assertNull;
import static org.junit.jupiter.api.Assertions.assertTrue; import static org.junit.jupiter.api.Assertions.assertTrue;
import java.util.List; import java.util.List;
import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test; import org.junit.jupiter.api.Test;
import com.google.common.testing.EqualsTester;
class BookTest { class BookTest {
@@ -67,13 +64,13 @@ class BookTest {
@Test @Test
void testEquals() { void testEquals() {
new EqualsTester().addEqualityGroup(testBook, testBookTwo).testEquals(); assertEquals(testBook, testBookTwo);
} }
@Test @Test
void testToString() { void testToString() {
assertThat(testBook.toString(), is(testBookTwo.toString())); assertEquals(testBook.toString(), testBookTwo.toString());
assertThat(testBook.toString(), is(not(testBookThree.toString()))); assertNotEquals(testBook.toString(), testBookThree.toString());
} }
@Test @Test
-6
View File
@@ -40,7 +40,6 @@
<spring-boot.version>2.7.5</spring-boot.version> <spring-boot.version>2.7.5</spring-boot.version>
<jacoco.version>0.8.8</jacoco.version> <jacoco.version>0.8.8</jacoco.version>
<commons-dbcp.version>1.4</commons-dbcp.version> <commons-dbcp.version>1.4</commons-dbcp.version>
<guava.version>19.0</guava.version>
<htmlunit.version>2.66.0</htmlunit.version> <htmlunit.version>2.66.0</htmlunit.version>
<guice.version>4.0</guice.version> <guice.version>4.0</guice.version>
<system-lambda.version>1.1.0</system-lambda.version> <system-lambda.version>1.1.0</system-lambda.version>
@@ -223,11 +222,6 @@
<artifactId>commons-dbcp</artifactId> <artifactId>commons-dbcp</artifactId>
<version>${commons-dbcp.version}</version> <version>${commons-dbcp.version}</version>
</dependency> </dependency>
<dependency>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
<version>${guava.version}</version>
</dependency>
<dependency> <dependency>
<groupId>net.sourceforge.htmlunit</groupId> <groupId>net.sourceforge.htmlunit</groupId>
<artifactId>htmlunit</artifactId> <artifactId>htmlunit</artifactId>
-4
View File
@@ -55,10 +55,6 @@
<artifactId>junit-jupiter-engine</artifactId> <artifactId>junit-jupiter-engine</artifactId>
<scope>test</scope> <scope>test</scope>
</dependency> </dependency>
<dependency>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
</dependency>
<dependency> <dependency>
<groupId>javax.xml.bind</groupId> <groupId>javax.xml.bind</groupId>
<artifactId>jaxb-api</artifactId> <artifactId>jaxb-api</artifactId>
@@ -24,6 +24,7 @@
*/ */
package com.iluwatar.repository; package com.iluwatar.repository;
import java.util.List;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor; import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.repository.CrudRepository; import org.springframework.data.repository.CrudRepository;
import org.springframework.stereotype.Repository; import org.springframework.stereotype.Repository;
@@ -36,4 +37,6 @@ public interface PersonRepository
extends CrudRepository<Person, Long>, JpaSpecificationExecutor<Person> { extends CrudRepository<Person, Long>, JpaSpecificationExecutor<Person> {
Person findByName(String name); Person findByName(String name);
List<Person> findAll();
} }
@@ -28,7 +28,6 @@ import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNull; import static org.junit.jupiter.api.Assertions.assertNull;
import static org.junit.jupiter.api.Assertions.assertTrue; import static org.junit.jupiter.api.Assertions.assertTrue;
import com.google.common.collect.Lists;
import java.util.List; import java.util.List;
import javax.annotation.Resource; import javax.annotation.Resource;
import org.junit.jupiter.api.AfterEach; import org.junit.jupiter.api.AfterEach;
@@ -66,7 +65,7 @@ class AnnotationBasedRepositoryTest {
@Test @Test
void testFindAll() { void testFindAll() {
var actuals = Lists.newArrayList(repository.findAll()); var actuals = repository.findAll();
assertTrue(actuals.containsAll(persons) && persons.containsAll(actuals)); assertTrue(actuals.containsAll(persons) && persons.containsAll(actuals));
} }
@@ -28,7 +28,6 @@ import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNull; import static org.junit.jupiter.api.Assertions.assertNull;
import static org.junit.jupiter.api.Assertions.assertTrue; import static org.junit.jupiter.api.Assertions.assertTrue;
import com.google.common.collect.Lists;
import java.util.List; import java.util.List;
import javax.annotation.Resource; import javax.annotation.Resource;
import org.junit.jupiter.api.AfterEach; import org.junit.jupiter.api.AfterEach;
@@ -66,7 +65,7 @@ class RepositoryTest {
@Test @Test
void testFindAll() { void testFindAll() {
var actuals = Lists.newArrayList(repository.findAll()); var actuals = repository.findAll();
assertTrue(actuals.containsAll(persons) && persons.containsAll(actuals)); assertTrue(actuals.containsAll(persons) && persons.containsAll(actuals));
} }
-6
View File
@@ -34,12 +34,6 @@
</parent> </parent>
<artifactId>value-object</artifactId> <artifactId>value-object</artifactId>
<dependencies> <dependencies>
<dependency>
<groupId>com.google.guava</groupId>
<artifactId>guava-testlib</artifactId>
<version>23.0</version>
<scope>test</scope>
</dependency>
<dependency> <dependency>
<groupId>org.junit.jupiter</groupId> <groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-engine</artifactId> <artifactId>junit-jupiter-engine</artifactId>
@@ -24,11 +24,9 @@
*/ */
package com.iluwatar.value.object; package com.iluwatar.value.object;
import static org.hamcrest.CoreMatchers.is; import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.hamcrest.CoreMatchers.not; import static org.junit.jupiter.api.Assertions.assertNotEquals;
import static org.junit.Assert.assertThat;
import com.google.common.testing.EqualsTester;
import org.junit.jupiter.api.Test; import org.junit.jupiter.api.Test;
/** /**
@@ -47,7 +45,7 @@ class HeroStatTest {
void testEquals() { void testEquals() {
var heroStatA = HeroStat.valueOf(3, 9, 2); var heroStatA = HeroStat.valueOf(3, 9, 2);
var heroStatB = HeroStat.valueOf(3, 9, 2); var heroStatB = HeroStat.valueOf(3, 9, 2);
new EqualsTester().addEqualityGroup(heroStatA, heroStatB).testEquals(); assertEquals(heroStatA, heroStatB);
} }
/** /**
@@ -59,9 +57,8 @@ class HeroStatTest {
var heroStatA = HeroStat.valueOf(3, 9, 2); var heroStatA = HeroStat.valueOf(3, 9, 2);
var heroStatB = HeroStat.valueOf(3, 9, 2); var heroStatB = HeroStat.valueOf(3, 9, 2);
var heroStatC = HeroStat.valueOf(3, 9, 8); var heroStatC = HeroStat.valueOf(3, 9, 8);
assertEquals(heroStatA.toString(), heroStatB.toString());
assertThat(heroStatA.toString(), is(heroStatB.toString())); assertNotEquals(heroStatA.toString(), heroStatC.toString());
assertThat(heroStatA.toString(), is(not(heroStatC.toString())));
} }
} }