From 178aa8829681cdbc58c11c110aa7d09663405e31 Mon Sep 17 00:00:00 2001 From: priyeshmashelkar Date: Fri, 6 Jul 2018 12:46:26 +0100 Subject: [PATCH 1/2] Moved code from spring-boot to testing-modules/mockito --- testing-modules/mockito/pom.xml | 33 ++++++++++++- .../org/baeldung/mockito/repository/User.java | 49 +++++++++++++++++++ .../mockito/repository/UserRepository.java | 9 ++++ .../baeldung/mockito}/MockAnnotationTest.java | 6 +-- .../MockBeanAnnotationIntegrationTest.java | 5 +- 5 files changed, 95 insertions(+), 7 deletions(-) create mode 100644 testing-modules/mockito/src/main/java/org/baeldung/mockito/repository/User.java create mode 100644 testing-modules/mockito/src/main/java/org/baeldung/mockito/repository/UserRepository.java rename {spring-boot/src/test/java/org/baeldung => testing-modules/mockito/src/test/java/org/baeldung/mockito}/MockAnnotationTest.java (86%) rename {spring-boot/src/test/java/org/baeldung => testing-modules/mockito/src/test/java/org/baeldung/mockito}/MockBeanAnnotationIntegrationTest.java (91%) diff --git a/testing-modules/mockito/pom.xml b/testing-modules/mockito/pom.xml index c2e5b4bf31..45ce288fa9 100644 --- a/testing-modules/mockito/pom.xml +++ b/testing-modules/mockito/pom.xml @@ -46,6 +46,38 @@ ${hamcrest.version} + + org.springframework.boot + spring-boot-starter + LATEST + test + + + org.springframework.boot + spring-boot-starter-test + LATEST + test + + + org.springframework + spring-core + LATEST + + + org.springframework + spring-context + LATEST + + + org.eclipse.persistence + javax.persistence + 2.1.1 + + + org.springframework.data + spring-data-jpa + LATEST + @@ -67,7 +99,6 @@ 1.7.0 2.0.0.0 - \ No newline at end of file diff --git a/testing-modules/mockito/src/main/java/org/baeldung/mockito/repository/User.java b/testing-modules/mockito/src/main/java/org/baeldung/mockito/repository/User.java new file mode 100644 index 0000000000..28cd4f9fb0 --- /dev/null +++ b/testing-modules/mockito/src/main/java/org/baeldung/mockito/repository/User.java @@ -0,0 +1,49 @@ +package org.baeldung.mockito.repository; + +import javax.persistence.Entity; +import javax.persistence.GeneratedValue; +import javax.persistence.Id; +import javax.persistence.Table; + +@Entity +@Table(name = "users") +public class User { + + @Id + @GeneratedValue + private Integer id; + private String name; + private Integer status; + + public User() { + } + + public User(String name, Integer status) { + this.name = name; + this.status = status; + } + + public Integer getId() { + return id; + } + + public void setId(Integer id) { + this.id = id; + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public Integer getStatus() { + return status; + } + + public void setStatus(Integer status) { + this.status = status; + } +} \ No newline at end of file diff --git a/testing-modules/mockito/src/main/java/org/baeldung/mockito/repository/UserRepository.java b/testing-modules/mockito/src/main/java/org/baeldung/mockito/repository/UserRepository.java new file mode 100644 index 0000000000..3f1952a5e7 --- /dev/null +++ b/testing-modules/mockito/src/main/java/org/baeldung/mockito/repository/UserRepository.java @@ -0,0 +1,9 @@ +package org.baeldung.mockito.repository; + +import org.springframework.data.jpa.repository.JpaRepository; +import org.springframework.stereotype.Repository; + +@Repository("userRepository") +public interface UserRepository extends JpaRepository { + +} diff --git a/spring-boot/src/test/java/org/baeldung/MockAnnotationTest.java b/testing-modules/mockito/src/test/java/org/baeldung/mockito/MockAnnotationTest.java similarity index 86% rename from spring-boot/src/test/java/org/baeldung/MockAnnotationTest.java rename to testing-modules/mockito/src/test/java/org/baeldung/mockito/MockAnnotationTest.java index a70b31177f..0421204ca5 100644 --- a/spring-boot/src/test/java/org/baeldung/MockAnnotationTest.java +++ b/testing-modules/mockito/src/test/java/org/baeldung/mockito/MockAnnotationTest.java @@ -1,6 +1,6 @@ -package org.baeldung; +package org.baeldung.mockito; -import org.baeldung.repository.UserRepository; +import org.baeldung.mockito.repository.UserRepository; import org.junit.Assert; import org.junit.Test; import org.junit.runner.RunWith; @@ -28,6 +28,6 @@ public class MockAnnotationTest { Mockito.when(localMockRepository.count()).thenReturn(111L); long userCount = localMockRepository.count(); Assert.assertEquals(111L, userCount); - Mockito.verify(localMockRepository).count(); + Mockito.verify(localMockRepository).count(); } } diff --git a/spring-boot/src/test/java/org/baeldung/MockBeanAnnotationIntegrationTest.java b/testing-modules/mockito/src/test/java/org/baeldung/mockito/MockBeanAnnotationIntegrationTest.java similarity index 91% rename from spring-boot/src/test/java/org/baeldung/MockBeanAnnotationIntegrationTest.java rename to testing-modules/mockito/src/test/java/org/baeldung/mockito/MockBeanAnnotationIntegrationTest.java index 0c93004a49..008e674696 100644 --- a/spring-boot/src/test/java/org/baeldung/MockBeanAnnotationIntegrationTest.java +++ b/testing-modules/mockito/src/test/java/org/baeldung/mockito/MockBeanAnnotationIntegrationTest.java @@ -1,6 +1,6 @@ -package org.baeldung; +package org.baeldung.mockito; -import org.baeldung.repository.UserRepository; +import org.baeldung.mockito.repository.UserRepository; import org.junit.Assert; import org.junit.Test; import org.junit.runner.RunWith; @@ -10,7 +10,6 @@ import org.springframework.boot.test.mock.mockito.MockBean; import org.springframework.context.ApplicationContext; import org.springframework.test.context.junit4.SpringRunner; - @RunWith(SpringRunner.class) public class MockBeanAnnotationIntegrationTest { From a3f6ad6d8889eac5652ecffcce56d43884147b9c Mon Sep 17 00:00:00 2001 From: Priyesh Mashelkar Date: Wed, 11 Jul 2018 00:01:38 +0100 Subject: [PATCH 2/2] Renamed unit test --- .../{MockAnnotationTest.java => MockAnnotationUnitTest.java} | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) rename testing-modules/mockito/src/test/java/org/baeldung/mockito/{MockAnnotationTest.java => MockAnnotationUnitTest.java} (96%) diff --git a/testing-modules/mockito/src/test/java/org/baeldung/mockito/MockAnnotationTest.java b/testing-modules/mockito/src/test/java/org/baeldung/mockito/MockAnnotationUnitTest.java similarity index 96% rename from testing-modules/mockito/src/test/java/org/baeldung/mockito/MockAnnotationTest.java rename to testing-modules/mockito/src/test/java/org/baeldung/mockito/MockAnnotationUnitTest.java index 0421204ca5..5d565fea88 100644 --- a/testing-modules/mockito/src/test/java/org/baeldung/mockito/MockAnnotationTest.java +++ b/testing-modules/mockito/src/test/java/org/baeldung/mockito/MockAnnotationUnitTest.java @@ -9,7 +9,7 @@ import org.mockito.Mockito; import org.mockito.junit.MockitoJUnitRunner; @RunWith(MockitoJUnitRunner.class) -public class MockAnnotationTest { +public class MockAnnotationUnitTest { @Mock UserRepository mockRepository;