diff --git a/testing-modules/mockito-simple/src/main/java/com/baeldung/app/api/MessageApi.java b/testing-modules/mockito-simple/src/main/java/com/baeldung/app/api/MessageDTO.java similarity index 94% rename from testing-modules/mockito-simple/src/main/java/com/baeldung/app/api/MessageApi.java rename to testing-modules/mockito-simple/src/main/java/com/baeldung/app/api/MessageDTO.java index edbe5a1d5a..1d9da244b0 100644 --- a/testing-modules/mockito-simple/src/main/java/com/baeldung/app/api/MessageApi.java +++ b/testing-modules/mockito-simple/src/main/java/com/baeldung/app/api/MessageDTO.java @@ -1,6 +1,6 @@ package com.baeldung.app.api; -public class MessageApi { +public class MessageDTO { private String from; private String to; private String text; diff --git a/testing-modules/mockito-simple/src/main/java/com/baeldung/app/rest/MessageController.java b/testing-modules/mockito-simple/src/main/java/com/baeldung/app/rest/MessageController.java index e23c2e7607..6911197197 100644 --- a/testing-modules/mockito-simple/src/main/java/com/baeldung/app/rest/MessageController.java +++ b/testing-modules/mockito-simple/src/main/java/com/baeldung/app/rest/MessageController.java @@ -1,6 +1,6 @@ package com.baeldung.app.rest; -import com.baeldung.app.api.MessageApi; +import com.baeldung.app.api.MessageDTO; import com.baeldung.domain.model.Message; import com.baeldung.domain.service.MessageService; import org.springframework.beans.factory.annotation.Autowired; @@ -21,7 +21,7 @@ public class MessageController { private MessageService messageService; @PostMapping - public Message createMessage (@RequestBody MessageApi messageDTO) { + public Message createMessage (@RequestBody MessageDTO messageDTO) { Message message = new Message(); message.setText(messageDTO.getText()); message.setFrom(messageDTO.getFrom()); diff --git a/testing-modules/mockito-simple/src/test/java/com/baeldung/app/rest/MessageControllerUnitTest.java b/testing-modules/mockito-simple/src/test/java/com/baeldung/app/rest/MessageControllerUnitTest.java index ae368c4c34..1bfbeecfec 100644 --- a/testing-modules/mockito-simple/src/test/java/com/baeldung/app/rest/MessageControllerUnitTest.java +++ b/testing-modules/mockito-simple/src/test/java/com/baeldung/app/rest/MessageControllerUnitTest.java @@ -11,7 +11,7 @@ import org.mockito.InjectMocks; import org.mockito.Mock; import org.mockito.junit.MockitoJUnitRunner; -import com.baeldung.app.api.MessageApi; +import com.baeldung.app.api.MessageDTO; import com.baeldung.domain.model.Message; import com.baeldung.domain.service.MessageService; import com.baeldung.domain.util.MessageMatcher; @@ -19,32 +19,32 @@ import com.baeldung.domain.util.MessageMatcher; @RunWith(MockitoJUnitRunner.class) public class MessageControllerUnitTest { + @InjectMocks + private MessageController messageController; + @Mock private MessageService messageService; - @InjectMocks - private MessageController messageController; - @Test public void givenMsg_whenVerifyUsingAnyMatcher_thenOk() { - MessageApi messageApi = new MessageApi(); - messageApi.setFrom("me"); - messageApi.setTo("you"); - messageApi.setText("Hello, you!"); + MessageDTO messageDTO = new MessageDTO(); + messageDTO.setFrom("me"); + messageDTO.setTo("you"); + messageDTO.setText("Hello, you!"); - messageController.createMessage(messageApi); + messageController.createMessage(messageDTO); verify(messageService, times(1)).deliverMessage(any(Message.class)); } @Test public void givenMsg_whenVerifyUsingMessageMatcher_thenOk() { - MessageApi messageApi = new MessageApi(); - messageApi.setFrom("me"); - messageApi.setTo("you"); - messageApi.setText("Hello, you!"); + MessageDTO messageDTO = new MessageDTO(); + messageDTO.setFrom("me"); + messageDTO.setTo("you"); + messageDTO.setText("Hello, you!"); - messageController.createMessage(messageApi); + messageController.createMessage(messageDTO); Message message = new Message(); message.setFrom("me");