test_class.declarator: messageRepositoryMock
test_class.modifier: @Mock
      private
test_class.original_string: @Mock
      private MessageRepository messageRepositoryMock;
test_class.type: MessageRepository
test_class.var_name: messageRepositoryMock
test_class.declarator: javaMailSenderMock
test_class.modifier: @Mock
      private
test_class.original_string: @Mock
      private JavaMailSenderImpl javaMailSenderMock;
test_class.type: JavaMailSenderImpl
test_class.var_name: javaMailSenderMock
test_class.declarator: userServiceMock
test_class.modifier: @Mock
      private
test_class.original_string: @Mock
      private UserService userServiceMock;
test_class.type: UserService
test_class.var_name: userServiceMock
test_class.declarator: mailPropertiesMock
test_class.modifier: @Mock
      private
test_class.original_string: @Mock
      private MailConfigurationProperties mailPropertiesMock;
test_class.type: MailConfigurationProperties
test_class.var_name: mailPropertiesMock
test_class.declarator: templateMessageMock
test_class.modifier: @Mock
      private
test_class.original_string: @Mock
      private TemplateMessage templateMessageMock;
test_class.type: TemplateMessage
test_class.var_name: templateMessageMock
test_class.declarator: userMock
test_class.modifier: @Mock
      private
test_class.original_string: @Mock
      private User userMock;
test_class.type: User
test_class.var_name: userMock
test_class.declarator: userDataMock
test_class.modifier: @Mock
      private
test_class.original_string: @Mock
      private UserData userDataMock;
test_class.type: UserData
test_class.var_name: userDataMock
test_class.declarator: clock
test_class.modifier: private
test_class.original_string: private Clock clock;
test_class.type: Clock
test_class.var_name: clock
test_class.declarator: mailSenderAdapter
test_class.modifier: private
test_class.original_string: private MailSenderAdapter mailSenderAdapter;
test_class.type: MailSenderAdapter
test_class.var_name: mailSenderAdapter
test_class.file: backend/project-board/src/test/java/de/adesso/projectboard/adapter/mail/MailSenderAdapterTest.java
test_class.identifier: MailSenderAdapterTest
test_case.body: @Test
      public void sendPendingMessagesOnlySendsRelevantMessages() {
          // given
          var expectedFrom = "sender@test.com";
          var expectedTo = "email@test.com";
          var expectedSubject = "This is a subject!";
          var expectedText = "This is a long text!";
  
          var expectedSimpleMessage = new SimpleMailMessage();
          expectedSimpleMessage.setFrom(expectedFrom);
          expectedSimpleMessage.setTo(expectedTo);
          expectedSimpleMessage.setSubject(expectedSubject);
          expectedSimpleMessage.setText(expectedText);
  
          given(messageRepositoryMock.findAll()).willReturn(List.of(templateMessageMock, templateMessageMock));
  
          given(templateMessageMock.isStillRelevant(LocalDateTime.now(clock)))
                  .willReturn(false, true);
          given(templateMessageMock.getSubject()).willReturn(expectedSubject);
          given(templateMessageMock.getText()).willReturn(expectedText);
          given(templateMessageMock.getAddressee()).willReturn(userMock);
  
          given(userServiceMock.getUserData(userMock)).willReturn(userDataMock);
          given(userDataMock.getEmail()).willReturn(expectedTo);
  
          given(mailPropertiesMock.getFromMail()).willReturn(expectedFrom);
  
          // when
          mailSenderAdapter.sendPendingMessages();
  
          // then
          verify(messageRepositoryMock, times(2)).delete(templateMessageMock);
          verify(javaMailSenderMock).send(expectedSimpleMessage);
      }
test_case.class_method_signature: MailSenderAdapterTest.sendPendingMessagesOnlySendsRelevantMessages()
test_case.full_signature: @Test public void sendPendingMessagesOnlySendsRelevantMessages()
test_case.identifier: sendPendingMessagesOnlySendsRelevantMessages
test_case.invocations: setFrom setTo setSubject setText willReturn given findAll of willReturn given isStillRelevant now willReturn given getSubject willReturn given getText willReturn given getAddressee willReturn given getUserData willReturn given getEmail willReturn given getFromMail sendPendingMessages delete verify times send verify
test_case.modifiers: @Test public
test_case.parameters: ()
test_case.return: void
test_case.signature: void sendPendingMessagesOnlySendsRelevantMessages()
focal_class.declarator: messageRepository
focal_class.modifier: private final
focal_class.original_string: private final MessageRepository messageRepository;
focal_class.type: MessageRepository
focal_class.var_name: messageRepository
focal_class.declarator: mailSender
focal_class.modifier: private final
focal_class.original_string: private final JavaMailSender mailSender;
focal_class.type: JavaMailSender
focal_class.var_name: mailSender
focal_class.declarator: userService
focal_class.modifier: private final
focal_class.original_string: private final UserService userService;
focal_class.type: UserService
focal_class.var_name: userService
focal_class.declarator: properties
focal_class.modifier: private final
focal_class.original_string: private final MailConfigurationProperties properties;
focal_class.type: MailConfigurationProperties
focal_class.var_name: properties
focal_class.declarator: clock
focal_class.modifier: private final
focal_class.original_string: private final Clock clock;
focal_class.type: Clock
focal_class.var_name: clock
focal_class.file: backend/project-board/src/main/java/de/adesso/projectboard/adapter/mail/MailSenderAdapter.java
focal_class.identifier: MailSenderAdapter
focal_class.class_method_signature: MailSenderAdapter.MailSenderAdapter(MessageRepository messageRepository,
                               JavaMailSender mailSender,
                               UserService userService,
                               MailConfigurationProperties properties,
                               Clock clock)
focal_class.full_signature: public  MailSenderAdapter(MessageRepository messageRepository,
                               JavaMailSender mailSender,
                               UserService userService,
                               MailConfigurationProperties properties,
                               Clock clock)
focal_class.identifier: MailSenderAdapter
focal_class.modifiers: public
focal_class.parameters: (MessageRepository messageRepository,
                               JavaMailSender mailSender,
                               UserService userService,
                               MailConfigurationProperties properties,
                               Clock clock)
focal_class.signature:  MailSenderAdapter(MessageRepository messageRepository,
                               JavaMailSender mailSender,
                               UserService userService,
                               MailConfigurationProperties properties,
                               Clock clock)
focal_class.class_method_signature: MailSenderAdapter.sendPendingMessages()
focal_class.full_signature: @Scheduled(fixedDelay = 10000L) @Transactional public void sendPendingMessages()
focal_class.identifier: sendPendingMessages
focal_class.modifiers: @Scheduled(fixedDelay = 10000L) @Transactional public
focal_class.parameters: ()
focal_class.return: void
focal_class.signature: void sendPendingMessages()
focal_class.class_method_signature: MailSenderAdapter.queueMessage(T message)
focal_class.full_signature: @Transactional public T queueMessage(T message)
focal_class.identifier: queueMessage
focal_class.modifiers: @Transactional public
focal_class.parameters: (T message)
focal_class.return: T
focal_class.signature: T queueMessage(T message)
focal_class.class_method_signature: MailSenderAdapter.sendMessage(TemplateMessage message)
focal_class.full_signature:  void sendMessage(TemplateMessage message)
focal_class.identifier: sendMessage
focal_class.parameters: (TemplateMessage message)
focal_class.return: void
focal_class.signature: void sendMessage(TemplateMessage message)
focal_method.body: @Scheduled(fixedDelay = 10000L)
      @Transactional
      public void sendPendingMessages() {
          messageRepository.findAll().forEach(templateMessage -> {
              try {
                  if(templateMessage.isStillRelevant(LocalDateTime.now(clock))) {
                      sendMessage(templateMessage);
                  }
  
                  // delete the message when it was sent
                  // successfully or is not relevant anymore
                  messageRepository.delete(templateMessage);
              } catch (Exception err) {
                  log.error("Error sending mail!", err);
              }
          });
      }
focal_method.class_method_signature: MailSenderAdapter.sendPendingMessages()
focal_method.full_signature: @Scheduled(fixedDelay = 10000L) @Transactional public void sendPendingMessages()
focal_method.identifier: sendPendingMessages
focal_method.invocations: forEach findAll isStillRelevant now sendMessage delete error
focal_method.modifiers: @Scheduled(fixedDelay = 10000L) @Transactional public
focal_method.parameters: ()
focal_method.return: void
focal_method.signature: void sendPendingMessages()