JAVA-13629 More fixes and updates (#12566)

This commit is contained in:
Dhawal Kapil 2022-08-05 01:19:05 +05:30 committed by GitHub
parent 0dc36fdb43
commit 717e3fafdb
3 changed files with 17 additions and 17 deletions

View File

@ -1,6 +1,6 @@
package com.baeldung.app.api;
public class MessageApi {
public class MessageDTO {
private String from;
private String to;
private String text;

View File

@ -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());

View File

@ -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 {
@Mock
private MessageService messageService;
@InjectMocks
private MessageController messageController;
@Mock
private MessageService messageService;
@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");