package com.flowable.local.work.model;

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(ExtensionContext context) {
        getTestMailServer(context).setup();
    }

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

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