2
2
3
3
import org .hydev .mcpm .client .database .fetcher .BriefFetcherListener ;
4
4
import org .hydev .mcpm .client .database .fetcher .ConstantFetcher ;
5
+ import org .hydev .mcpm .client .models .PluginCommand ;
5
6
import org .hydev .mcpm .client .models .PluginModel ;
6
7
import org .hydev .mcpm .client .models .PluginVersion ;
7
8
import org .hydev .mcpm .client .models .PluginYml ;
9
+ import org .jetbrains .annotations .NotNull ;
10
+ import org .jetbrains .annotations .Unmodifiable ;
8
11
9
- import java .util .ArrayList ;
12
+ import java .util .HashMap ;
10
13
import java .util .List ;
14
+ import java .util .Map ;
11
15
import java .util .stream .IntStream ;
12
16
13
17
/**
14
- * Mock factory for testing search functionality
18
+ * This class creates Plugins mainly for testing purposes.
19
+ *
20
+ * @author Taylor Whatley
21
+ * @author Jerry Zhu (<a href="https://github.com/jerryzhu509">...</a>)
15
22
*/
16
23
public class PluginMockFactory {
17
24
private PluginMockFactory () { }
18
25
26
+ /**
27
+ * Creates a mock PluginCommand object.
28
+ *
29
+ * @param description Description
30
+ * @param aliases Other names
31
+ * @return A Map<String, PluginCommand> object.
32
+ */
33
+ public static @ NotNull Map <String , PluginCommand > createCommand (String description , List <String > aliases ) {
34
+ var map = new HashMap <String , PluginCommand >();
35
+ var pc = new PluginCommand (description , aliases , null , null );
36
+ for (String alias : aliases ) {
37
+ map .put (alias , pc );
38
+ }
39
+ return map ;
40
+ }
41
+
19
42
/**
20
43
* Creates a mock PluginYml object.
21
44
*
22
45
* @param name The name of the plugin.
23
46
* @param version The version string for the plugin.
24
47
* @param description The description for the plugin.
48
+ * @param commands Commands for the plugin.
25
49
* @return A PluginYml object.
26
50
*/
27
- public static PluginYml meta (String name , String version , String description ) {
51
+ public static PluginYml meta (String name , String version , String description ,
52
+ Map <String , PluginCommand > commands ) {
28
53
return new PluginYml (
29
- "org." + name ,
30
- name ,
31
- version ,
32
- description ,
33
- null ,
34
- null ,
35
- null ,
36
- null ,
37
- null ,
38
- null ,
39
- null ,
40
- null ,
41
- null ,
42
- null ,
43
- null
54
+ "org." + name ,
55
+ name ,
56
+ version ,
57
+ description ,
58
+ null ,
59
+ null ,
60
+ null ,
61
+ null ,
62
+ null ,
63
+ null ,
64
+ null ,
65
+ null ,
66
+ null ,
67
+ null ,
68
+ commands
44
69
);
45
70
}
46
71
@@ -53,7 +78,22 @@ public static PluginYml meta(String name, String version, String description) {
53
78
* @return A PluginVersion object.
54
79
*/
55
80
public static PluginVersion version (long id , String name , String string ) {
56
- return new PluginVersion (id , 0 , "" , meta (name , string , null ));
81
+ return new PluginVersion (id , 0 , "" , meta (name , string , null , null ));
82
+ }
83
+
84
+ /**
85
+ * Creates a mock PluginVersion object.
86
+ *
87
+ * @param id The version id.
88
+ * @param name The plugin name (for meta).
89
+ * @param string The version string (for meta).
90
+ * @param description The plugin description.
91
+ * @param commands The commands in the plugin.
92
+ * @return A PluginVersion object.
93
+ */
94
+ public static PluginVersion version (long id , String name , String string , String description ,
95
+ Map <String , PluginCommand > commands ) {
96
+ return new PluginVersion (id , 0 , "" , meta (name , string , description , commands ));
57
97
}
58
98
59
99
@@ -77,8 +117,8 @@ public static PluginModel model(long id) {
77
117
*/
78
118
public static PluginModel model (long id , String name ) {
79
119
return new PluginModel (
80
- id ,
81
- List .of (version (id , name , "ver." + name )) // NOT SEMVER
120
+ id ,
121
+ List .of (version (id , name , "ver." + name )) // NOT SEMVER
82
122
);
83
123
}
84
124
@@ -88,24 +128,63 @@ public static PluginModel model(long id, String name) {
88
128
*
89
129
* @param id The plugin id.
90
130
* @param name The plugin name.
131
+ * @param description The plugin description.
91
132
* @param versionNames The individual version strings for each version.
133
+ * @param commands Commands for the plugin.
92
134
* @return A PluginModel object.
93
135
*/
94
- public static PluginModel model (long id , String name , List <String > versionNames ) {
136
+ public static PluginModel model (long id , String name , String description , List <String > versionNames ,
137
+ Map <String , PluginCommand > commands ) {
95
138
return new PluginModel (
96
- id ,
97
- IntStream .range (0 , versionNames .size ())
98
- .mapToObj (i -> version (i , name , versionNames .get (i )))
99
- .toList ()
139
+ id ,
140
+ IntStream .range (0 , versionNames .size ())
141
+ .mapToObj (i -> version (i , name , versionNames .get (i ), description , commands ))
142
+ .toList ()
100
143
);
101
144
}
102
145
103
- public static List <PluginModel > generatePlugins () {
104
- List <PluginModel > plugins = new ArrayList <>();
105
- String [] names = {"WorldGuard" };
106
- String [] descriptions = {"Protect your server!\n " +
107
- "WorldGuard lets you and players guard areas of land against griefers and undesirables\n " +
108
- "as well as tweak and disable various gameplay features of Minecraft." };
109
- return plugins ;
146
+ /**
147
+ * Creates a mock DatabaseInteractor object with the provided plugin list.
148
+ *
149
+ * @param plugins A list of plugins that the DatabaseInteractor will have access to.
150
+ * @return A DatabaseInteractor object.
151
+ */
152
+ public static DatabaseInteractor interactor (List <PluginModel > plugins ) {
153
+ var fetcher = new ConstantFetcher (plugins );
154
+ var listener = new BriefFetcherListener (true );
155
+
156
+ return new DatabaseInteractor (fetcher , listener );
157
+ }
158
+
159
+
160
+ /**
161
+ * Generates a sample list of plugins used for testing, containing the name, description, and commands.
162
+ *
163
+ * @return List of plugins for testing.
164
+ */
165
+ public static @ Unmodifiable List <PluginModel > generateTestPlugins () {
166
+ String [] descriptions = {"WorldGuard lets you and players guard areas " +
167
+ "of land against griefers and undesirables as well " +
168
+ "as tweak and disable various gameplay features of Minecraft." ,
169
+ "Multiverse was created at the dawn of Bukkit multiworld support. " +
170
+ "It has since then grown into a complete world management " +
171
+ "solution including special treatment of your nether worlds with " +
172
+ "Multiverse NetherPortals." ,
173
+ "Create futuristic holograms to display text and items to players!"
174
+ };
175
+
176
+ return List .of (
177
+ PluginMockFactory .model (1 ),
178
+ PluginMockFactory .model (2 , "WorldGuard" ,
179
+ descriptions [0 ],
180
+ List .of ("1.18.2" , "1.18.1" ),
181
+ createCommand (descriptions [0 ], List .of ("/god" , "/ungod" ))),
182
+ PluginMockFactory .model (3 , "Multiverse-Core" , descriptions [1 ],
183
+ List .of ("1.19.2" , "1.19.1" ),
184
+ createCommand (descriptions [1 ],List .of ("/mvlist" , "/mvl" ))),
185
+ PluginMockFactory .model (4 , "Holographic Displays" , descriptions [2 ],
186
+ List .of ("1.19.2" , "1.19.1" , "1.19" ),
187
+ createCommand (descriptions [2 ], List .of ("/hd" , "/ungod" )))
188
+ );
110
189
}
111
190
}
0 commit comments