package com.customer.work.model;

import org.jspecify.annotations.NonNull;
import org.junit.jupiter.api.extension.AfterEachCallback;
import org.junit.jupiter.api.extension.BeforeEachCallback;
import org.junit.jupiter.api.extension.ExtensionContext;
import org.springframework.test.context.junit.jupiter.SpringExtension;

public class TestMailServerExtension implements BeforeEachCallback, AfterEachCallback {
    @Override
    public void beforeEach(@NonNull ExtensionContext context) {
        getTestMailServer(context).setup();
    }

    @Override
    public void afterEach(@NonNull ExtensionContext context) {
        getTestMailServer(context).stop();
    }

    protected TestMailServer getTestMailServer(ExtensionContext context) {
        return SpringExtension.getApplicationContext(context).getBean(TestMailServer.class);
    }
}
