Skip to content

Commit 570d16d

Browse files
Copilottastybento
andcommitted
Fix MockedStatic<User> resource leak in ShowBarrierTest
Co-authored-by: tastybento <[email protected]>
1 parent d36840d commit 570d16d

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

src/test/java/world/bentobox/border/listeners/ShowBarrierTest.java

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,8 @@ public class ShowBarrierTest extends CommonTestSetup {
4747
@Mock
4848
private @NonNull Location center;
4949

50+
private MockedStatic<User> mockedUser;
51+
5052
/**
5153
* @throws java.lang.Exception
5254
*/
@@ -77,7 +79,7 @@ public void setUp() throws Exception {
7779
when(im.getIslandAt(any(Location.class))).thenReturn(Optional.of(island));
7880

7981
// User
80-
MockedStatic<User> mockedUser = Mockito.mockStatic(User.class, Mockito.RETURNS_MOCKS);
82+
mockedUser = Mockito.mockStatic(User.class, Mockito.RETURNS_MOCKS);
8183
mockedUser.when(() -> User.getInstance(any(Player.class))).thenReturn(user);
8284
when(user.getMetaData(anyString())).thenReturn(Optional.empty());
8385
when(user.getPlayer()).thenReturn(player);
@@ -98,6 +100,9 @@ public void setUp() throws Exception {
98100
@Override
99101
@AfterEach
100102
public void tearDown() throws Exception {
103+
if (mockedUser != null) {
104+
mockedUser.close();
105+
}
101106
super.tearDown();
102107
}
103108

0 commit comments

Comments
 (0)