-
-
Notifications
You must be signed in to change notification settings - Fork 45
/
ReplaceManagerTest.java
68 lines (54 loc) · 2.69 KB
/
ReplaceManagerTest.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
package com.github.games647.scoreboardstats.variables;
import com.github.games647.scoreboardstats.ScoreboardStats;
import java.util.logging.Logger;
import org.bukkit.Bukkit;
import org.bukkit.entity.Player;
import org.bukkit.plugin.Plugin;
import org.bukkit.plugin.SimplePluginManager;
import org.bukkit.plugin.messaging.StandardMessenger;
import org.bukkit.scheduler.BukkitScheduler;
import org.junit.Assert;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mockito;
import org.powermock.api.mockito.PowerMockito;
import org.powermock.core.classloader.annotations.PrepareForTest;
import org.powermock.modules.junit4.PowerMockRunner;
@PrepareForTest({Bukkit.class, SimplePluginManager.class, Plugin.class, ScoreboardStats.class})
@RunWith(PowerMockRunner.class)
public class ReplaceManagerTest {
private static final String SAMPLE_VARIABLE = "sample";
@Test
public void testUnregister() throws Exception {
PowerMockito.mockStatic(Bukkit.class);
Mockito.when(Bukkit.getPluginManager()).thenReturn(PowerMockito.mock(SimplePluginManager.class));
Mockito.when(Bukkit.getMessenger()).thenReturn(PowerMockito.mock(StandardMessenger.class));
Mockito.when(Bukkit.getScheduler()).thenReturn(PowerMockito.mock(BukkitScheduler.class));
ScoreboardStats plugin = PowerMockito.mock(ScoreboardStats.class);
PowerMockito.when(plugin.getLogger()).thenReturn(Logger.getGlobal());
ReplaceManager replaceManager = new ReplaceManager(null, plugin);
testLegacy(replaceManager);
testAbstract(plugin, replaceManager);
}
private void testAbstract(Plugin plugin, ReplaceManager replaceManager) {
VariableReplaceAdapter<?> replaceAdapter = new VariableReplaceAdapter<Plugin>(plugin, SAMPLE_VARIABLE) {
@Override
public void onReplace(Player player, String variable, ReplaceEvent replaceEvent) {
throw new UnsupportedOperationException("Not supported yet");
}
};
replaceManager.register(replaceAdapter);
Assert.assertTrue(replaceManager.unregister(replaceAdapter));
}
@SuppressWarnings("deprecation")
private void testLegacy(ReplaceManager replaceManager) {
Replaceable legacyReplaceable = (player, variable) -> {
throw new UnsupportedOperationException("Not supported yet.");
};
LegacyReplaceWrapper legacyWrapper = new LegacyReplaceWrapper(Bukkit
.getPluginManager().getPlugin("pluginName"), legacyReplaceable);
legacyWrapper.getVariables().add(SAMPLE_VARIABLE);
replaceManager.register(legacyWrapper);
Assert.assertTrue(replaceManager.unregister(legacyReplaceable));
}
}