File tree 6 files changed +47
-10
lines changed
main/java/net/clementraynaud/skoice/util
test/java/net/clementraynaud/skoice
6 files changed +47
-10
lines changed Original file line number Diff line number Diff line change 277
277
<version >4.11.0</version >
278
278
<scope >test</scope >
279
279
</dependency >
280
+ <dependency >
281
+ <groupId >org.mockito</groupId >
282
+ <artifactId >mockito-inline</artifactId >
283
+ <version >4.11.0</version >
284
+ <scope >test</scope >
285
+ </dependency >
280
286
</dependencies >
281
287
</project >
Original file line number Diff line number Diff line change @@ -29,13 +29,10 @@ private ThreadUtil() {
29
29
}
30
30
31
31
public static void ensureNotMainThread (boolean disablingBypass ) {
32
- try {
33
- if (Bukkit .isPrimaryThread () && (!disablingBypass || Bukkit .getPluginManager ().isPluginEnabled ("Skoice" ))) {
34
- Exception exception = new IllegalStateException ("This method should not be called from the main thread." );
35
- exception .printStackTrace ();
36
- Skoice .analyticManager ().getBugsnag ().notify (exception , Severity .WARNING );
37
- }
38
- } catch (NullPointerException ignored ) {
32
+ if (Bukkit .isPrimaryThread () && (!disablingBypass || Bukkit .getPluginManager ().isPluginEnabled ("Skoice" ))) {
33
+ Exception exception = new IllegalStateException ("This method should not be called from the main thread." );
34
+ exception .printStackTrace ();
35
+ Skoice .analyticManager ().getBugsnag ().notify (exception , Severity .WARNING );
39
36
}
40
37
}
41
38
Original file line number Diff line number Diff line change
1
+ package net .clementraynaud .skoice ;
2
+
3
+ import org .bukkit .Bukkit ;
4
+ import org .bukkit .plugin .PluginManager ;
5
+ import org .junit .jupiter .api .AfterAll ;
6
+ import org .junit .jupiter .api .BeforeAll ;
7
+ import org .mockito .MockedStatic ;
8
+
9
+ import static org .mockito .Mockito .mock ;
10
+ import static org .mockito .Mockito .mockStatic ;
11
+ import static org .mockito .Mockito .when ;
12
+
13
+ public class BukkitTestSetup {
14
+
15
+ private static MockedStatic <Bukkit > mockedBukkit ;
16
+
17
+ @ BeforeAll
18
+ static void setUpAll () {
19
+ BukkitTestSetup .mockedBukkit = mockStatic (Bukkit .class );
20
+ when (Bukkit .isPrimaryThread ()).thenReturn (false );
21
+ PluginManager mockPluginManager = mock (PluginManager .class );
22
+ when (Bukkit .getPluginManager ()).thenReturn (mockPluginManager );
23
+ when (mockPluginManager .isPluginEnabled ("Skoice" )).thenReturn (true );
24
+ }
25
+
26
+ @ AfterAll
27
+ static void tearDownAll () {
28
+ BukkitTestSetup .mockedBukkit .close ();
29
+ }
30
+
31
+ }
Original file line number Diff line number Diff line change 19
19
20
20
package net .clementraynaud .skoice .system ;
21
21
22
+ import net .clementraynaud .skoice .BukkitTestSetup ;
22
23
import net .clementraynaud .skoice .Skoice ;
23
24
import net .clementraynaud .skoice .storage .config .ConfigYamlFile ;
24
25
import org .bukkit .entity .Player ;
38
39
import static org .mockito .Mockito .when ;
39
40
40
41
@ ExtendWith (MockitoExtension .class )
41
- class LinkedPlayerTest {
42
+ class LinkedPlayerTest extends BukkitTestSetup {
42
43
43
44
@ Mock
44
45
private Skoice plugin ;
Original file line number Diff line number Diff line change 19
19
20
20
package net .clementraynaud .skoice .system ;
21
21
22
+ import net .clementraynaud .skoice .BukkitTestSetup ;
22
23
import net .clementraynaud .skoice .Skoice ;
23
24
import org .junit .jupiter .api .BeforeEach ;
24
25
import org .junit .jupiter .api .Test ;
34
35
import static org .mockito .Mockito .when ;
35
36
36
37
@ ExtendWith (MockitoExtension .class )
37
- class NetworkTest {
38
+ class NetworkTest extends BukkitTestSetup {
38
39
39
40
@ Mock
40
41
private Skoice plugin ;
Original file line number Diff line number Diff line change 19
19
20
20
package net .clementraynaud .skoice .system ;
21
21
22
+ import net .clementraynaud .skoice .BukkitTestSetup ;
22
23
import org .junit .jupiter .api .BeforeEach ;
23
24
import org .junit .jupiter .api .Test ;
24
25
import org .junit .jupiter .api .extension .ExtendWith ;
30
31
import static org .mockito .Mockito .when ;
31
32
32
33
@ ExtendWith (MockitoExtension .class )
33
- class NetworksTest {
34
+ class NetworksTest extends BukkitTestSetup {
34
35
35
36
@ Mock
36
37
private Network network1 ;
You can’t perform that action at this time.
0 commit comments