diff --git a/testing-modules/spring-testing/README.md b/testing-modules/spring-testing/README.md new file mode 100644 index 0000000000..a96ddccabb --- /dev/null +++ b/testing-modules/spring-testing/README.md @@ -0,0 +1,2 @@ +### Relevant Articles: + diff --git a/testing-modules/spring-testing/pom.xml b/testing-modules/spring-testing/pom.xml new file mode 100644 index 0000000000..a137bc8d33 --- /dev/null +++ b/testing-modules/spring-testing/pom.xml @@ -0,0 +1,75 @@ + + 4.0.0 + org.baeldung + spring-testing + 0.1-SNAPSHOT + spring-testing + + + com.baeldung + parent-java + 0.0.1-SNAPSHOT + ../../parent-java + + + + + + + org.hamcrest + java-hamcrest + ${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 + + + + + spring-testing + + + src/main/resources + true + + + + + + + + 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/spring-testing/src/main/java/org/baeldung/mockito/repository/User.java similarity index 100% rename from testing-modules/mockito/src/main/java/org/baeldung/mockito/repository/User.java rename to testing-modules/spring-testing/src/main/java/org/baeldung/mockito/repository/User.java diff --git a/testing-modules/mockito/src/main/java/org/baeldung/mockito/repository/UserRepository.java b/testing-modules/spring-testing/src/main/java/org/baeldung/mockito/repository/UserRepository.java similarity index 100% rename from testing-modules/mockito/src/main/java/org/baeldung/mockito/repository/UserRepository.java rename to testing-modules/spring-testing/src/main/java/org/baeldung/mockito/repository/UserRepository.java diff --git a/testing-modules/mockito/src/test/java/org/baeldung/mockito/MockAnnotationUnitTest.java b/testing-modules/spring-testing/src/test/java/org/baeldung/mockito/MockAnnotationUnitTest.java similarity index 83% rename from testing-modules/mockito/src/test/java/org/baeldung/mockito/MockAnnotationUnitTest.java rename to testing-modules/spring-testing/src/test/java/org/baeldung/mockito/MockAnnotationUnitTest.java index 5d565fea88..fcc646e8ea 100644 --- a/testing-modules/mockito/src/test/java/org/baeldung/mockito/MockAnnotationUnitTest.java +++ b/testing-modules/spring-testing/src/test/java/org/baeldung/mockito/MockAnnotationUnitTest.java @@ -15,18 +15,22 @@ public class MockAnnotationUnitTest { UserRepository mockRepository; @Test - public void testMockAnnotation() { + public void givenCountMethodMocked_WhenCountInvoked_ThenMockValueReturned() { Mockito.when(mockRepository.count()).thenReturn(123L); + long userCount = mockRepository.count(); + Assert.assertEquals(123L, userCount); Mockito.verify(mockRepository).count(); } @Test - public void testMockitoMockMethod() { + public void givenCountMethodOfLocalMockVariableMocked_WhenCountInvoked_ThenMockedValueReturned() { UserRepository localMockRepository = Mockito.mock(UserRepository.class); Mockito.when(localMockRepository.count()).thenReturn(111L); + long userCount = localMockRepository.count(); + Assert.assertEquals(111L, userCount); Mockito.verify(localMockRepository).count(); } diff --git a/testing-modules/mockito/src/test/java/org/baeldung/mockito/MockBeanAnnotationIntegrationTest.java b/testing-modules/spring-testing/src/test/java/org/baeldung/mockito/MockBeanAnnotationIntegrationTest.java similarity index 91% rename from testing-modules/mockito/src/test/java/org/baeldung/mockito/MockBeanAnnotationIntegrationTest.java rename to testing-modules/spring-testing/src/test/java/org/baeldung/mockito/MockBeanAnnotationIntegrationTest.java index 008e674696..3a7e58fb48 100644 --- a/testing-modules/mockito/src/test/java/org/baeldung/mockito/MockBeanAnnotationIntegrationTest.java +++ b/testing-modules/spring-testing/src/test/java/org/baeldung/mockito/MockBeanAnnotationIntegrationTest.java @@ -20,10 +20,12 @@ public class MockBeanAnnotationIntegrationTest { ApplicationContext context; @Test - public void testMockBean() { + public void givenCountMethodMocked_WhenCountInvoked_ThenMockValueReturned() { Mockito.when(mockRepository.count()).thenReturn(123L); + UserRepository userRepoFromContext = context.getBean(UserRepository.class); long userCount = userRepoFromContext.count(); + Assert.assertEquals(123L, userCount); Mockito.verify(mockRepository).count(); }