Skip to content

Commit f270c19

Browse files
committed
Fix to close the ApplicationContext at assertion failing
(cherry picked from commit b8554ac)
1 parent f9e9c74 commit f270c19

File tree

3 files changed

+32
-26
lines changed

3 files changed

+32
-26
lines changed

src/test/java/org/mybatis/spring/annotation/MapperScanTest.java

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -70,15 +70,17 @@ private void startContext() {
7070

7171
@After
7272
public void assertNoMapperClass() {
73-
// concrete classes should always be ignored by MapperScannerPostProcessor
74-
assertBeanNotLoaded("mapperClass");
75-
76-
// no method interfaces should be ignored too
77-
assertBeanNotLoaded("package-info");
78-
// assertBeanNotLoaded("annotatedMapperZeroMethods"); // as of 1.1.0 mappers
79-
// with no methods are loaded
80-
81-
applicationContext.close();
73+
try {
74+
// concrete classes should always be ignored by MapperScannerPostProcessor
75+
assertBeanNotLoaded("mapperClass");
76+
77+
// no method interfaces should be ignored too
78+
assertBeanNotLoaded("package-info");
79+
// assertBeanNotLoaded("annotatedMapperZeroMethods"); // as of 1.1.0 mappers
80+
// with no methods are loaded
81+
} finally {
82+
applicationContext.close();
83+
}
8284
}
8385

8486
@Test

src/test/java/org/mybatis/spring/config/NamespaceTest.java

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -56,15 +56,17 @@ private void startContext() {
5656

5757
@After
5858
public void assertNoMapperClass() {
59-
// concrete classes should always be ignored by MapperScannerPostProcessor
60-
assertBeanNotLoaded("mapperClass");
61-
62-
// no method interfaces should be ignored too
63-
assertBeanNotLoaded("package-info");
64-
// assertBeanNotLoaded("annotatedMapperZeroMethods"); // as of 1.1.0 mappers
65-
// with no methods are loaded
66-
67-
applicationContext.close();
59+
try {
60+
// concrete classes should always be ignored by MapperScannerPostProcessor
61+
assertBeanNotLoaded("mapperClass");
62+
63+
// no method interfaces should be ignored too
64+
assertBeanNotLoaded("package-info");
65+
// assertBeanNotLoaded("annotatedMapperZeroMethods"); // as of 1.1.0 mappers
66+
// with no methods are loaded
67+
} finally {
68+
applicationContext.close();
69+
}
6870
}
6971

7072
@Test

src/test/java/org/mybatis/spring/mapper/MapperScannerConfigurerTest.java

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -71,14 +71,16 @@ private void startContext() {
7171

7272
@After
7373
public void assertNoMapperClass() {
74-
// concrete classes should always be ignored by MapperScannerPostProcessor
75-
assertBeanNotLoaded("mapperClass");
76-
77-
// no method interfaces should be ignored too
78-
assertBeanNotLoaded("package-info");
79-
// assertBeanNotLoaded("annotatedMapperZeroMethods"); // as of 1.1.0 mappers with no methods are loaded
80-
81-
applicationContext.close();
74+
try {
75+
// concrete classes should always be ignored by MapperScannerPostProcessor
76+
assertBeanNotLoaded("mapperClass");
77+
78+
// no method interfaces should be ignored too
79+
assertBeanNotLoaded("package-info");
80+
// assertBeanNotLoaded("annotatedMapperZeroMethods"); // as of 1.1.0 mappers with no methods are loaded
81+
} finally {
82+
applicationContext.close();
83+
}
8284
}
8385

8486
@Test

0 commit comments

Comments
 (0)