From be83bda550f9dc4e76dbd9309a9ccef43f9238f6 Mon Sep 17 00:00:00 2001 From: David Morley Date: Tue, 19 Jan 2016 06:12:11 -0600 Subject: [PATCH 1/2] Fix package name --- mockito-mocks-spring-beans/pom.xml | 67 +++++++++---------- .../baeldung/MocksApplication.java | 2 +- .../{org => com}/baeldung/NameService.java | 2 +- .../{org => com}/baeldung/UserService.java | 2 +- .../NameServiceTestConfiguration.java | 2 +- .../baeldung/UserServiceTest.java | 2 +- 6 files changed, 38 insertions(+), 39 deletions(-) rename mockito-mocks-spring-beans/src/main/java/{org => com}/baeldung/MocksApplication.java (92%) rename mockito-mocks-spring-beans/src/main/java/{org => com}/baeldung/NameService.java (88%) rename mockito-mocks-spring-beans/src/main/java/{org => com}/baeldung/UserService.java (94%) rename mockito-mocks-spring-beans/src/test/java/{org => com}/baeldung/NameServiceTestConfiguration.java (95%) rename mockito-mocks-spring-beans/src/test/java/{org => com}/baeldung/UserServiceTest.java (97%) diff --git a/mockito-mocks-spring-beans/pom.xml b/mockito-mocks-spring-beans/pom.xml index 5d4fdf069f..64dc7d83c9 100644 --- a/mockito-mocks-spring-beans/pom.xml +++ b/mockito-mocks-spring-beans/pom.xml @@ -1,34 +1,34 @@ - 4.0.0 + xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> + 4.0.0 - org.baeldung - mockito-mocks-spring-beans - 0.0.1-SNAPSHOT - jar + com.baeldung + mockito-mocks-spring-beans + 0.0.1-SNAPSHOT + jar - mocks - Injecting Mockito Mocks into Spring Beans + mocks + Injecting Mockito Mocks into Spring Beans - - org.springframework.boot - spring-boot-starter-parent - 1.3.1.RELEASE - - + + org.springframework.boot + spring-boot-starter-parent + 1.3.1.RELEASE + + - - UTF-8 - 1.8 - + + UTF-8 + 1.8 + - - - org.springframework.boot - spring-boot-starter + + + org.springframework.boot + spring-boot-starter 1.3.1.RELEASE - + org.springframework.boot spring-boot-starter-test @@ -40,16 +40,15 @@ mockito-all 1.10.19 - - - - - - org.springframework.boot - spring-boot-maven-plugin - - - - + + + + + + org.springframework.boot + spring-boot-maven-plugin + + + diff --git a/mockito-mocks-spring-beans/src/main/java/org/baeldung/MocksApplication.java b/mockito-mocks-spring-beans/src/main/java/com/baeldung/MocksApplication.java similarity index 92% rename from mockito-mocks-spring-beans/src/main/java/org/baeldung/MocksApplication.java rename to mockito-mocks-spring-beans/src/main/java/com/baeldung/MocksApplication.java index 08c3580382..32be4c6a0a 100644 --- a/mockito-mocks-spring-beans/src/main/java/org/baeldung/MocksApplication.java +++ b/mockito-mocks-spring-beans/src/main/java/com/baeldung/MocksApplication.java @@ -1,4 +1,4 @@ -package org.baeldung; +package com.baeldung; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; diff --git a/mockito-mocks-spring-beans/src/main/java/org/baeldung/NameService.java b/mockito-mocks-spring-beans/src/main/java/com/baeldung/NameService.java similarity index 88% rename from mockito-mocks-spring-beans/src/main/java/org/baeldung/NameService.java rename to mockito-mocks-spring-beans/src/main/java/com/baeldung/NameService.java index 2b755692fc..e28a96ff06 100644 --- a/mockito-mocks-spring-beans/src/main/java/org/baeldung/NameService.java +++ b/mockito-mocks-spring-beans/src/main/java/com/baeldung/NameService.java @@ -1,4 +1,4 @@ -package org.baeldung; +package com.baeldung; import org.springframework.stereotype.Service; diff --git a/mockito-mocks-spring-beans/src/main/java/org/baeldung/UserService.java b/mockito-mocks-spring-beans/src/main/java/com/baeldung/UserService.java similarity index 94% rename from mockito-mocks-spring-beans/src/main/java/org/baeldung/UserService.java rename to mockito-mocks-spring-beans/src/main/java/com/baeldung/UserService.java index e9ca7b3206..fe7e35b9f8 100644 --- a/mockito-mocks-spring-beans/src/main/java/org/baeldung/UserService.java +++ b/mockito-mocks-spring-beans/src/main/java/com/baeldung/UserService.java @@ -1,4 +1,4 @@ -package org.baeldung; +package com.baeldung; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; diff --git a/mockito-mocks-spring-beans/src/test/java/org/baeldung/NameServiceTestConfiguration.java b/mockito-mocks-spring-beans/src/test/java/com/baeldung/NameServiceTestConfiguration.java similarity index 95% rename from mockito-mocks-spring-beans/src/test/java/org/baeldung/NameServiceTestConfiguration.java rename to mockito-mocks-spring-beans/src/test/java/com/baeldung/NameServiceTestConfiguration.java index 0f26d9055d..2c63ff6203 100644 --- a/mockito-mocks-spring-beans/src/test/java/org/baeldung/NameServiceTestConfiguration.java +++ b/mockito-mocks-spring-beans/src/test/java/com/baeldung/NameServiceTestConfiguration.java @@ -1,4 +1,4 @@ -package org.baeldung; +package com.baeldung; import org.mockito.Mockito; import org.springframework.context.annotation.Bean; diff --git a/mockito-mocks-spring-beans/src/test/java/org/baeldung/UserServiceTest.java b/mockito-mocks-spring-beans/src/test/java/com/baeldung/UserServiceTest.java similarity index 97% rename from mockito-mocks-spring-beans/src/test/java/org/baeldung/UserServiceTest.java rename to mockito-mocks-spring-beans/src/test/java/com/baeldung/UserServiceTest.java index 09ef244147..8ce7033f18 100644 --- a/mockito-mocks-spring-beans/src/test/java/org/baeldung/UserServiceTest.java +++ b/mockito-mocks-spring-beans/src/test/java/com/baeldung/UserServiceTest.java @@ -1,4 +1,4 @@ -package org.baeldung; +package com.baeldung; import org.junit.Assert; import org.junit.Test; From 423ba80835e6d5ce7f739f6c0deaa759f411b736 Mon Sep 17 00:00:00 2001 From: David Morley Date: Tue, 19 Jan 2016 06:13:36 -0600 Subject: [PATCH 2/2] Update mock injection example to make the behavior clear --- .../src/main/java/com/baeldung/NameService.java | 2 +- .../src/test/java/com/baeldung/UserServiceTest.java | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/mockito-mocks-spring-beans/src/main/java/com/baeldung/NameService.java b/mockito-mocks-spring-beans/src/main/java/com/baeldung/NameService.java index e28a96ff06..bc328cfd8a 100644 --- a/mockito-mocks-spring-beans/src/main/java/com/baeldung/NameService.java +++ b/mockito-mocks-spring-beans/src/main/java/com/baeldung/NameService.java @@ -5,6 +5,6 @@ import org.springframework.stereotype.Service; @Service public class NameService { public String getUserName(String id) { - return "Baeldung"; + return "Real user name"; } } diff --git a/mockito-mocks-spring-beans/src/test/java/com/baeldung/UserServiceTest.java b/mockito-mocks-spring-beans/src/test/java/com/baeldung/UserServiceTest.java index 8ce7033f18..631a8634be 100644 --- a/mockito-mocks-spring-beans/src/test/java/com/baeldung/UserServiceTest.java +++ b/mockito-mocks-spring-beans/src/test/java/com/baeldung/UserServiceTest.java @@ -22,10 +22,10 @@ public class UserServiceTest { @Test public void whenUserIdIsProvided_thenRetrievedNameIsCorrect() { - Mockito.when(nameService.getUserName("SomeId")).thenReturn("Baeldung"); + Mockito.when(nameService.getUserName("SomeId")).thenReturn("Mock user name"); String testName = userService.getUserName("SomeId"); - Assert.assertEquals("Baeldung", testName); + Assert.assertEquals("Mock user name", testName); } } \ No newline at end of file