package de.tum.in.www1.artemis.service;

import static org.mockito.Mockito.*;

import javax.mail.internet.MimeMessage;

import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
import org.mockito.Mock;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.MessageSource;
import org.springframework.mail.javamail.JavaMailSender;
import org.thymeleaf.spring5.SpringTemplateEngine;

import de.tum.in.www1.artemis.domain.User;
import tech.jhipster.config.JHipsterProperties;

/**
 * This is a very basic testing class for the mail service
 * Because this service mostly uses other frameworks/services and loads values/variables into html templates
 * we only test that the correct send method is called
 */

public class MailServiceTest {

    @Autowired
    private static MailService mailService;

    @Mock
    private static JavaMailSender javaMailSender;

    @Mock
    private static MimeMessage mimeMessage;

    @Mock
    private static JHipsterProperties jHipsterProperties;

    @Mock
    private static JHipsterProperties.Mail mail;

    @Mock
    private static MessageSource messageSource;

    @Mock
    private static SpringTemplateEngine templateEngine;

    @Mock
    private static TimeService timeService;

    private static User student1;

    private static final String EMAIL_ADDRESS_A = "benige8246@omibrown.com";

    private static final String EMAIL_ADDRESS_B = "alex2713@gmail.com";

    private static String subject;

    private static String content;

    /**
     * Prepares the needed values and objects for testing
     */
    @BeforeAll
    public static void setUp() {
        student1 = new User();
        student1.setId(555L);
        student1.setEmail(EMAIL_ADDRESS_A);

        subject = "subject";
        content = "content";

        mimeMessage = mock(MimeMessage.class);

        javaMailSender = mock(JavaMailSender.class);
        when(javaMailSender.createMimeMessage()).thenReturn(mimeMessage);

        mail = mock(JHipsterProperties.Mail.class);
        when(mail.getFrom()).thenReturn(EMAIL_ADDRESS_B);

        jHipsterProperties = mock(JHipsterProperties.class);
        when(jHipsterProperties.getMail()).thenReturn(mail);

        mailService = new MailService(jHipsterProperties, javaMailSender, messageSource, templateEngine, timeService);
    }

    /**
     * Very basic test that checks if the send method for emails is correctly called once
     */
    @Test
    public void testSendEmail() {
        mailService.sendEmail(student1, subject, content, false, true);
        verify(javaMailSender, times(1)).send(mimeMessage);
    }
}

@@ -148,19 +148,20 @@
 i.Before
-All
+Each
 ;%0Aimport
@@ -218,71 +218,8 @@
 ck;%0A
-import org.springframework.beans.factory.annotation.Autowired;%0A
 impo
@@ -696,17 +696,16 @@
 led%0A */%0A
-%0A
 public c
@@ -732,23 +732,8 @@
  %7B%0A%0A
-    @Autowired%0A
     
@@ -740,23 +740,16 @@
 private 
-static 
 MailServ
@@ -788,23 +788,16 @@
 private 
-static 
 JavaMail
@@ -842,23 +842,16 @@
 private 
-static 
 MimeMess
@@ -882,39 +882,32 @@
 ock%0A    private 
-static 
 JHipsterProperti
@@ -952,23 +952,16 @@
 private 
-static 
 JHipster
@@ -1005,23 +1005,16 @@
 private 
-static 
 MessageS
@@ -1057,23 +1057,16 @@
 private 
-static 
 SpringTe
@@ -1117,23 +1117,16 @@
 private 
-static 
 TimeServ
@@ -1155,23 +1155,16 @@
 private 
-static 
 User stu
@@ -1187,166 +1187,8 @@
 ate 
-static final String EMAIL_ADDRESS_A = %22benige8246@omibrown.com%22;%0A%0A    private static final String EMAIL_ADDRESS_B = %22alex2713@gmail.com%22;%0A%0A    private static 
 Stri
@@ -1212,23 +1212,16 @@
 private 
-static 
 String c
@@ -1318,11 +1318,12 @@
 fore
-All
+Each
 %0A   
@@ -1330,23 +1330,16 @@
  public 
-static 
 void set
@@ -1406,16 +1406,76 @@
 (555L);%0A
+        String EMAIL_ADDRESS_A = %22benige8246@omibrown.com%22;%0A
         
@@ -1790,32 +1790,87 @@
 es.Mail.class);%0A
+        String EMAIL_ADDRESS_B = %22alex2713@gmail.com%22;%0A
         when(mai

Remove static in MailServiceTest