// Path: src/main/java/de/gessnerfl/fakesmtp/config/FakeSmtpConfigurationProperties.java
// @Component
// @ConfigurationProperties(prefix = "fakesmtp")
// public class FakeSmtpConfigurationProperties {
// 
//     private static final int DEFAULT_PORT = 25;
// 
//     @NotNull
//     private Integer port = DEFAULT_PORT;
//     private InetAddress bindAddress;
//     private Authentication authentication;
//     private String filteredEmailRegexList;
//     private boolean forwardEmails = false;
// 
//     @NotNull
//     private Persistence persistence = new Persistence();
// 
//     public Integer getPort() {
//         return port;
//     }
// 
//     public void setPort(Integer port) {
//         this.port = port;
//     }
// 
//     public InetAddress getBindAddress() {
//         return bindAddress;
//     }
// 
//     public void setBindAddress(InetAddress bindAddress) {
//         this.bindAddress = bindAddress;
//     }
// 
//     public Authentication getAuthentication() {
//         return authentication;
//     }
// 
//     public void setAuthentication(Authentication authentication) {
//         this.authentication = authentication;
//     }
// 
//     public Persistence getPersistence() {
//         return persistence;
//     }
// 
//     public void setPersistence(Persistence persistence) {
//         this.persistence = persistence;
//     }
// 
//     public String getFilteredEmailRegexList() {
//         return filteredEmailRegexList;
//     }
// 
//     public void setFilteredEmailRegexList(String filteredEmailRegexList) {
//         this.filteredEmailRegexList = filteredEmailRegexList;
//     }
// 
//     public boolean isForwardEmails() {
//         return forwardEmails;
//     }
// 
//     public void setForwardEmails(boolean forwardEmails) {
//         this.forwardEmails = forwardEmails;
//     }
// 
//     public static class Authentication {
//         @NotNull
//         private String username;
//         @NotNull
//         private String password;
// 
//         public String getUsername() {
//             return username;
//         }
// 
//         public void setUsername(String username) {
//             this.username = username;
//         }
// 
//         public String getPassword() {
//             return password;
//         }
// 
//         public void setPassword(String password) {
//             this.password = password;
//         }
//     }
// 
//     public static class Persistence {
//         static final int DEFAULT_MAX_NUMBER_EMAILS = 100;
// 
//         @NotNull
//         private Integer maxNumberEmails = DEFAULT_MAX_NUMBER_EMAILS;
// 
//         public Integer getMaxNumberEmails() {
//             return maxNumberEmails;
//         }
// 
//         public void setMaxNumberEmails(Integer maxNumberEmails) {
//             this.maxNumberEmails = maxNumberEmails;
//         }
//     }
// }
// 
// Path: src/main/java/de/gessnerfl/fakesmtp/repository/EmailRepository.java
// @Repository
// public interface EmailRepository extends JpaRepository<Email,Long>{
// 
//     @Transactional
//     @Modifying
//     @Query(value = "DELETE email o WHERE o.id IN ( SELECT i.id FROM email i ORDER BY i.received_on DESC OFFSET ?1)", nativeQuery = true)
//     int deleteEmailsExceedingDateRetentionLimit(int maxNumber);
// }


import de.gessnerfl.fakesmtp.config.FakeSmtpConfigurationProperties;
import de.gessnerfl.fakesmtp.repository.EmailRepository;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.mockito.InjectMocks;
import org.mockito.Mock;
import org.mockito.junit.jupiter.MockitoExtension;
import org.slf4j.Logger;
import static org.mockito.Mockito.*;
package de.gessnerfl.fakesmtp.service;



@ExtendWith(MockitoExtension.class)
class EmailRetentionTimerTest {

    @Mock
    private FakeSmtpConfigurationProperties fakeSmtpConfigurationProperties;
    @Mock
    private EmailRepository emailRepository;
    @Mock
    private Logger logger;

    @InjectMocks
    private EmailRetentionTimer sut;

    @Test
    void shouldTriggerDeletionWhenDataRetentionIsConfigured(){
        var maxNumber = 5;
        var persistence = mock(FakeSmtpConfigurationProperties.Persistence.class);
        when(persistence.getMaxNumberEmails()).thenReturn(maxNumber);
        when(fakeSmtpConfigurationProperties.getPersistence()).thenReturn(persistence);

        sut.deleteOutdatedMails();

        verify(emailRepository).deleteEmailsExceedingDateRetentionLimit(maxNumber);
    }

    @Test
    void shouldNotTriggerDeletionWhenConfiguredMaxNumberIsNull(){
// Path: src/main/java/de/gessnerfl/fakesmtp/config/FakeSmtpConfigurationProperties.java
// @Component
// @ConfigurationProperties(prefix = "fakesmtp")
// public class FakeSmtpConfigurationProperties {
// 
//     private static final int DEFAULT_PORT = 25;
// 
//     @NotNull
//     private Integer port = DEFAULT_PORT;
//     private InetAddress bindAddress;
//     private Authentication authentication;
//     private String filteredEmailRegexList;
//     private boolean forwardEmails = false;
// 
//     @NotNull
//     private Persistence persistence = new Persistence();
// 
//     public Integer getPort() {
//         return port;
//     }
// 
//     public void setPort(Integer port) {
//         this.port = port;
//     }
// 
//     public InetAddress getBindAddress() {
//         return bindAddress;
//     }
// 
//     public void setBindAddress(InetAddress bindAddress) {
//         this.bindAddress = bindAddress;
//     }
// 
//     public Authentication getAuthentication() {
//         return authentication;
//     }
// 
//     public void setAuthentication(Authentication authentication) {
//         this.authentication = authentication;
//     }
// 
//     public Persistence getPersistence() {
//         return persistence;
//     }
// 
//     public void setPersistence(Persistence persistence) {
//         this.persistence = persistence;
//     }
// 
//     public String getFilteredEmailRegexList() {
//         return filteredEmailRegexList;
//     }
// 
//     public void setFilteredEmailRegexList(String filteredEmailRegexList) {
//         this.filteredEmailRegexList = filteredEmailRegexList;
//     }
// 
//     public boolean isForwardEmails() {
//         return forwardEmails;
//     }
// 
//     public void setForwardEmails(boolean forwardEmails) {
//         this.forwardEmails = forwardEmails;
//     }
// 
//     public static class Authentication {
//         @NotNull
//         private String username;
//         @NotNull
//         private String password;
// 
//         public String getUsername() {
//             return username;
//         }
// 
//         public void setUsername(String username) {
//             this.username = username;
//         }
// 
//         public String getPassword() {
//             return password;
//         }
// 
//         public void setPassword(String password) {
//             this.password = password;
//         }
//     }
// 
//     public static class Persistence {
//         static final int DEFAULT_MAX_NUMBER_EMAILS = 100;
// 
//         @NotNull
//         private Integer maxNumberEmails = DEFAULT_MAX_NUMBER_EMAILS;
// 
//         public Integer getMaxNumberEmails() {
//             return maxNumberEmails;
//         }
// 
//         public void setMaxNumberEmails(Integer maxNumberEmails) {
//             this.maxNumberEmails = maxNumberEmails;
//         }
//     }
// }
// 
// Path: src/main/java/de/gessnerfl/fakesmtp/repository/EmailRepository.java
// @Repository
// public interface EmailRepository extends JpaRepository<Email,Long>{
// 
//     @Transactional
//     @Modifying
//     @Query(value = "DELETE email o WHERE o.id IN ( SELECT i.id FROM email i ORDER BY i.received_on DESC OFFSET ?1)", nativeQuery = true)
//     int deleteEmailsExceedingDateRetentionLimit(int maxNumber);
// }


// Path: src/test/java/de/gessnerfl/fakesmtp/service/EmailRetentionTimerTest.java
import de.gessnerfl.fakesmtp.config.FakeSmtpConfigurationProperties;
import de.gessnerfl.fakesmtp.repository.EmailRepository;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.mockito.InjectMocks;
import org.mockito.Mock;
import org.mockito.junit.jupiter.MockitoExtension;
import org.slf4j.Logger;
import static org.mockito.Mockito.*;

package de.gessnerfl.fakesmtp.service;



@ExtendWith(MockitoExtension.class)
class EmailRetentionTimerTest {

    @Mock
    private FakeSmtpConfigurationProperties fakeSmtpConfigurationProperties;
    @Mock
    private EmailRepository emailRepository;
    @Mock
    private Logger logger;

    @InjectMocks
    private EmailRetentionTimer sut;

    @Test
    void shouldTriggerDeletionWhenDataRetentionIsConfigured(){
        var maxNumber = 5;
        var persistence = mock(FakeSmtpConfigurationProperties.Persistence.class);
        when(persistence.getMaxNumberEmails()).thenReturn(maxNumber);
        when(fakeSmtpConfigurationProperties.getPersistence()).thenReturn(persistence);

        sut.deleteOutdatedMails();

        verify(emailRepository).deleteEmailsExceedingDateRetentionLimit(maxNumber);
    }

    @Test
    void shouldNotTriggerDeletionWhenConfiguredMaxNumberIsNull(){
        var persistence = mock(FakeSmtpConfigurationProperties.Persistence.class);