1
+ package world .bentobox .bentobox .api .commands .admin .blueprints ;
2
+
3
+ import static org .junit .Assert .assertEquals ;
4
+ import static org .junit .Assert .assertFalse ;
5
+ import static org .junit .Assert .assertNotNull ;
6
+ import static org .junit .Assert .assertTrue ;
7
+ import static org .mockito .ArgumentMatchers .any ;
8
+ import static org .mockito .ArgumentMatchers .anyString ;
9
+ import static org .mockito .Mockito .mock ;
10
+ import static org .mockito .Mockito .verify ;
11
+ import static org .mockito .Mockito .when ;
12
+
13
+ import java .util .HashMap ;
14
+ import java .util .List ;
15
+ import java .util .Map ;
16
+ import java .util .Optional ;
17
+ import java .util .UUID ;
18
+
19
+ import org .bukkit .Bukkit ;
20
+ import org .junit .After ;
21
+ import org .junit .Before ;
22
+ import org .junit .Test ;
23
+ import org .junit .runner .RunWith ;
24
+ import org .mockito .Mock ;
25
+ import org .mockito .Mockito ;
26
+ import org .powermock .api .mockito .PowerMockito ;
27
+ import org .powermock .core .classloader .annotations .PrepareForTest ;
28
+ import org .powermock .modules .junit4 .PowerMockRunner ;
29
+ import org .powermock .reflect .Whitebox ;
30
+
31
+ import world .bentobox .bentobox .BentoBox ;
32
+ import world .bentobox .bentobox .Settings ;
33
+ import world .bentobox .bentobox .api .addons .GameModeAddon ;
34
+ import world .bentobox .bentobox .api .localization .TextVariables ;
35
+ import world .bentobox .bentobox .api .user .User ;
36
+ import world .bentobox .bentobox .blueprints .Blueprint ;
37
+ import world .bentobox .bentobox .managers .BlueprintsManager ;
38
+ import world .bentobox .bentobox .managers .CommandsManager ;
39
+ import world .bentobox .bentobox .managers .LocalesManager ;
40
+
41
+ /**
42
+ * @author tastybento
43
+ *
44
+ */
45
+ @ RunWith (PowerMockRunner .class )
46
+ @ PrepareForTest ({Bukkit .class , BentoBox .class , User .class })
47
+ public class AdminBlueprintDeleteCommandTest {
48
+
49
+ @ Mock
50
+ private AdminBlueprintCommand ac ;
51
+ @ Mock
52
+ private GameModeAddon addon ;
53
+ @ Mock
54
+ private User user ;
55
+ private UUID uuid = UUID .randomUUID ();
56
+ @ Mock
57
+ private BlueprintsManager bm ;
58
+ private Blueprint bp = new Blueprint ();
59
+ private AdminBlueprintDeleteCommand abcc ;
60
+ private Map <String , Blueprint > map ;
61
+
62
+ /**
63
+ * @throws java.lang.Exception
64
+ */
65
+ @ Before
66
+ public void setUp () throws Exception {
67
+ // Set up plugin
68
+ BentoBox plugin = mock (BentoBox .class );
69
+ Whitebox .setInternalState (BentoBox .class , "instance" , plugin );
70
+
71
+ // Blueprints Manager
72
+ when (plugin .getBlueprintsManager ()).thenReturn (bm );
73
+
74
+ // Command manager
75
+ CommandsManager cm = mock (CommandsManager .class );
76
+ when (plugin .getCommandsManager ()).thenReturn (cm );
77
+
78
+ // Settings
79
+ Settings s = mock (Settings .class );
80
+ when (s .getResetCooldown ()).thenReturn (0 );
81
+ when (plugin .getSettings ()).thenReturn (s );
82
+
83
+ // Sometimes use Mockito.withSettings().verboseLogging()
84
+ User .setPlugin (plugin );
85
+ when (user .getUniqueId ()).thenReturn (uuid );
86
+ when (user .getTranslation (anyString ())).thenReturn ("translation" );
87
+
88
+ // Parent command
89
+ when (ac .getAddon ()).thenReturn (addon );
90
+ when (ac .getLabel ()).thenReturn ("blueprint" );
91
+ when (ac .getSubCommandAliases ()).thenReturn (new HashMap <>());
92
+ when (ac .getTopLabel ()).thenReturn ("admin" );
93
+
94
+ map = new HashMap <>();
95
+ map .put ("key" , bp );
96
+ when (bm .getBlueprints (any ())).thenReturn (map );
97
+
98
+ // Locales
99
+ LocalesManager lm = mock (LocalesManager .class );
100
+ when (lm .get (Mockito .any (), Mockito .any ())).thenReturn ("mock translation" );
101
+ when (plugin .getLocalesManager ()).thenReturn (lm );
102
+
103
+ PowerMockito .mockStatic (Bukkit .class , Mockito .RETURNS_MOCKS );
104
+
105
+
106
+ abcc = new AdminBlueprintDeleteCommand (ac );
107
+ }
108
+
109
+ /**
110
+ * @throws java.lang.Exception
111
+ */
112
+ @ After
113
+ public void tearDown () throws Exception {
114
+ User .clearUsers ();
115
+ Mockito .framework ().clearInlineMocks ();
116
+ }
117
+
118
+ /**
119
+ * Test method for {@link world.bentobox.bentobox.api.commands.admin.blueprints.AdminBlueprintDeleteCommand#AdminBlueprintDeleteCommand(world.bentobox.bentobox.api.commands.admin.blueprints.AdminBlueprintCommand)}.
120
+ */
121
+ @ Test
122
+ public void testAdminBlueprintDeleteCommand () {
123
+ assertNotNull (abcc );
124
+ }
125
+
126
+ /**
127
+ * Test method for {@link world.bentobox.bentobox.api.commands.admin.blueprints.AdminBlueprintDeleteCommand#setup()}.
128
+ */
129
+ @ Test
130
+ public void testSetup () {
131
+ abcc .setup ();
132
+ assertEquals ("commands.admin.blueprint.delete.description" , abcc .getDescription ());
133
+ assertEquals ("commands.admin.blueprint.delete.parameters" , abcc .getParameters ());
134
+
135
+ }
136
+
137
+ /**
138
+ * Test method for {@link world.bentobox.bentobox.api.commands.admin.blueprints.AdminBlueprintDeleteCommand#execute(world.bentobox.bentobox.api.user.User, java.lang.String, java.util.List)}.
139
+ */
140
+ @ Test
141
+ public void testExecuteUserStringListOfStringHelp () {
142
+ assertFalse (abcc .execute (user , "" , List .of ("1" , "2" , "3" )));
143
+ verify (user ).sendMessage ("commands.help.header" , "[label]" , "translation" );
144
+ }
145
+
146
+ /**
147
+ * Test method for {@link world.bentobox.bentobox.api.commands.admin.blueprints.AdminBlueprintDeleteCommand#execute(world.bentobox.bentobox.api.user.User, java.lang.String, java.util.List)}.
148
+ */
149
+ @ Test
150
+ public void testExecuteUserStringListOfStringNoBp () {
151
+ assertFalse (abcc .execute (user , "" , List .of (" iSlAnd " )));
152
+ verify (user ).sendMessage ("commands.admin.blueprint.delete.no-blueprint" , TextVariables .NAME , "_island__" );
153
+ }
154
+
155
+ /**
156
+ * Test method for {@link world.bentobox.bentobox.api.commands.admin.blueprints.AdminBlueprintDeleteCommand#execute(world.bentobox.bentobox.api.user.User, java.lang.String, java.util.List)}.
157
+ */
158
+ @ Test
159
+ public void testExecuteUserStringListOfStringSuccessCaps () {
160
+ assertTrue (abcc .execute (user , "" , List .of ("KEY" )));
161
+ verify (user ).getTranslation ("commands.admin.blueprint.delete.confirmation" );
162
+ }
163
+
164
+ /**
165
+ * Test method for {@link world.bentobox.bentobox.api.commands.admin.blueprints.AdminBlueprintDeleteCommand#tabComplete(world.bentobox.bentobox.api.user.User, java.lang.String, java.util.List)}.
166
+ */
167
+ @ Test
168
+ public void testTabCompleteUserStringListOfString () {
169
+ Optional <List <String >> o = abcc .tabComplete (user , "" , List .of ("" ));
170
+ assertTrue (o .isPresent ());
171
+ assertEquals ("key" , o .get ().get (0 ));
172
+ }
173
+
174
+ }
0 commit comments