2222import java .util .Iterator ;
2323import org .apache .logging .log4j .ThreadContext ;
2424import org .apache .logging .log4j .core .Logger ;
25+ import org .apache .logging .log4j .core .LoggerContext ;
2526import org .apache .logging .log4j .core .test .AvailablePortFinder ;
26- import org .apache .logging .log4j .core .test .junit .LoggerContextRule ;
27+ import org .apache .logging .log4j .core .test .junit .LoggerContextSource ;
2728import org .apache .logging .log4j .core .test .smtp .SimpleSmtpServer ;
2829import org .apache .logging .log4j .core .test .smtp .SmtpMessage ;
29- import org .junit .After ;
30- import org .junit .AfterClass ;
31- import org .junit .Before ;
32- import org .junit .BeforeClass ;
33- import org .junit .Rule ;
34- import org .junit .Test ;
30+ import org .junit .jupiter .api .AfterAll ;
31+ import org .junit .jupiter .api .AfterEach ;
32+ import org .junit .jupiter .api .BeforeAll ;
33+ import org .junit .jupiter .api .BeforeEach ;
34+ import org .junit .jupiter .api .Test ;
3535
3636public class SmtpAppenderAsyncTest {
3737
3838 private static int PORT ;
3939
4040 private SimpleSmtpServer smtpServer ;
4141
42- @ BeforeClass
43- public static void setupClass () {
42+ @ BeforeAll
43+ public static void setupAll () {
4444 PORT = AvailablePortFinder .getNextAvailable ();
4545 System .setProperty ("smtp.port" , String .valueOf (PORT ));
4646 }
4747
48- @ Before
48+ @ BeforeEach
4949 public void setup () {
5050 smtpServer = SimpleSmtpServer .start (PORT );
5151 }
5252
53- @ Rule
54- public LoggerContextRule ctx = new LoggerContextRule ("SmtpAppenderAsyncTest.xml" );
55-
5653 @ Test
57- public void testSync () {
58- testSmtpAppender (ctx .getLogger ("sync" ));
54+ @ LoggerContextSource ("SmtpAppenderAsyncTest.xml" )
55+ public void testSync (final LoggerContext ctx ) {
56+ testSmtpAppender (ctx .getLogger ("sync" ), ctx );
5957 }
6058
6159 @ Test
62- public void testAsync () {
63- testSmtpAppender (ctx .getLogger ("async" ));
60+ @ LoggerContextSource ("SmtpAppenderAsyncTest.xml" )
61+ public void testAsync (final LoggerContext ctx ) {
62+ testSmtpAppender (ctx .getLogger ("async" ), ctx );
6463 }
6564
66- private void testSmtpAppender (final Logger logger ) {
65+ private void testSmtpAppender (final Logger logger , final LoggerContext ctx ) {
6766 ThreadContext .put ("MDC1" , "mdc1" );
6867 logger .error ("the message" );
69- ctx .getLoggerContext (). stop ();
68+ ctx .stop ();
7069 smtpServer .stop ();
7170
7271 assertEquals (1 , smtpServer .getReceivedEmailSize ());
@@ -83,15 +82,15 @@ private void testSmtpAppender(final Logger logger) {
8382 }
8483 }
8584
86- @ After
85+ @ AfterEach
8786 public void teardown () {
8887 if (smtpServer != null ) {
8988 smtpServer .stop ();
9089 }
9190 }
9291
93- @ AfterClass
94- public static void teardownClass () {
92+ @ AfterAll
93+ public static void teardownAll () {
9594 System .clearProperty ("smtp.port" );
9695 }
9796}
0 commit comments