Skip to content

Commit

Permalink
refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
rafal-nowak committed Aug 14, 2023
1 parent 702197b commit 751f0fc
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 3 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
package com.amigoscode.config;

import com.amigoscode.domain.email.EmailRepository;
import com.amigoscode.domain.email.EmailSender;
import com.amigoscode.domain.email.EmailService;
import com.amigoscode.domain.note.NoteRepository;
import com.amigoscode.domain.note.NoteService;
import com.amigoscode.domain.order.OrderRepository;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
import com.amigoscode.TestProviderFactory;
import com.amigoscode.TestUserFactory;
import com.amigoscode.appservices.EmailApplicationService;
import com.amigoscode.appservices.IAuthenticationFacade;
import com.amigoscode.appservices.ProviderApplicationService;
import com.amigoscode.domain.email.Email;
import com.amigoscode.domain.order.Order;
import com.amigoscode.domain.order.OrderService;
Expand Down Expand Up @@ -33,14 +35,17 @@ class EmailControllerIT extends BaseIT {
@MockBean
JavaMailSender mailSender;

@MockBean
IAuthenticationFacade authenticationFacade;

@Autowired
EmailApplicationService emailApplicationService;

@Autowired
UserService userService;

@Autowired
ProviderService providerService;
ProviderApplicationService providerService;

@Autowired
OrderService orderService;
Expand All @@ -54,6 +59,7 @@ void user_should_be_able_to_send_email() {
Provider provider = TestProviderFactory.create();
provider.setCreatedBy(savedUser.getId());
provider.setEmail("[email protected]");
Mockito.when(authenticationFacade.getLoggedInUserId()).thenReturn(savedUser.getId());
Provider savedProvider = providerService.save(provider);
Order order1 = orderService.save(TestOrderFactory.create());
Order order2 = orderService.save(TestOrderFactory.create());
Expand Down Expand Up @@ -95,6 +101,7 @@ void user_should_get_information_about_any_email() {
Provider provider = TestProviderFactory.create();
provider.setCreatedBy(savedUser.getId());
provider.setEmail("[email protected]");
Mockito.when(authenticationFacade.getLoggedInUserId()).thenReturn(savedUser.getId());
Provider savedProvider = providerService.save(provider);
Order order1 = orderService.save(TestOrderFactory.create());
Order order2 = orderService.save(TestOrderFactory.create());
Expand Down Expand Up @@ -133,6 +140,7 @@ void admin_should_get_pageable_list_of_orders() {
Provider provider = TestProviderFactory.create();
provider.setCreatedBy(savedUser.getId());
provider.setEmail("[email protected]");
Mockito.when(authenticationFacade.getLoggedInUserId()).thenReturn(savedUser.getId());
Provider savedProvider = providerService.save(provider);
Order order1 = orderService.save(TestOrderFactory.create());
Order order2 = orderService.save(TestOrderFactory.create());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,14 +27,17 @@ class EmailApplicationServiceIT extends BaseIT {
@MockBean
JavaMailSender mailSender;

@MockBean
IAuthenticationFacade authenticationFacade;

@Autowired
EmailApplicationService emailApplicationService;

@Autowired
UserService userService;

@Autowired
ProviderService providerService;
ProviderApplicationService providerService;

@Autowired
OrderService orderService;
Expand All @@ -46,6 +49,7 @@ void should_send_email() {
Provider provider = TestProviderFactory.create();
provider.setCreatedBy(savedUser.getId());
provider.setEmail("[email protected]");
Mockito.when(authenticationFacade.getLoggedInUserId()).thenReturn(savedUser.getId());
Provider savedProvider = providerService.save(provider);
Order order1 = orderService.save(TestOrderFactory.create());
Order order2 = orderService.save(TestOrderFactory.create());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,25 +4,32 @@
import com.amigoscode.TestEmailFactory;
import com.amigoscode.TestProviderFactory;
import com.amigoscode.TestUserFactory;
import com.amigoscode.appservices.IAuthenticationFacade;
import com.amigoscode.appservices.ProviderApplicationService;
import com.amigoscode.domain.order.OrderService;
import com.amigoscode.domain.provider.Provider;
import com.amigoscode.domain.provider.ProviderService;
import com.amigoscode.domain.user.User;
import com.amigoscode.domain.user.UserService;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
import org.mockito.Mockito;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.mock.mockito.MockBean;

public class EmailServiceIT extends BaseIT {

@MockBean
IAuthenticationFacade authenticationFacade;

@Autowired
EmailService emailService;

@Autowired
UserService userService;

@Autowired
ProviderService providerService;
ProviderApplicationService providerService;

@Autowired
OrderService orderService;
Expand All @@ -35,6 +42,8 @@ void get_by_id_should_return_correct_email() {

Provider provider = TestProviderFactory.create();
provider.setCreatedBy(savedUser.getId());

Mockito.when(authenticationFacade.getLoggedInUserId()).thenReturn(savedUser.getId());
Provider savedProvider = providerService.save(provider);

Email email1 = TestEmailFactory.create();
Expand Down

0 comments on commit 751f0fc

Please sign in to comment.