178
179 // Module name with consecutive dots, not allowed in java source
180 try {
181 m = ModuleHelper.ModuleObject("trailingdot.", cl, new String[] { "mypackage9b" });
182 ModuleHelper.DefineModule(m, false, "9.0", "module.name/here", new String[] { "mypackage9b" });
183 throw new RuntimeException("Failed to get expected IAE for trailingdot.");
184 } catch(IllegalArgumentException e) {
185 // Expected
186 }
187
188 // module name with multiple dots, should be okay
189 m = ModuleHelper.ModuleObject("more.than.one.dat", cl, new String[] { "mypackage9d" });
190 assertNotNull(m, "Module should not be null");
191 ModuleHelper.DefineModule(m, false, "9.0", "module.name/here", new String[] { "mypackage9d" });
192
193 // Zero length package list, should be okay
194 m = ModuleHelper.ModuleObject("zero.packages", cl, new String[] { });
195 assertNotNull(m, "Module should not be null");
196 ModuleHelper.DefineModule(m, false, "9.0", "module.name/here", new String[] { });
197
198 // Invalid package name, expect an IAE
199 m = ModuleHelper.ModuleObject("moduleFive", cl, new String[] { "your.apackage" });
200 try {
201 ModuleHelper.DefineModule(m, false, "9.0", "module.name/here", new String[] { "your.apackage" });
202 throw new RuntimeException("Failed to get expected IAE for your.apackage");
203 } catch(IllegalArgumentException e) {
204 if (!e.getMessage().contains("Invalid package name")) {
205 throw new RuntimeException("Failed to get expected IAE message for bad package name: " + e.getMessage());
206 }
207 }
208
209 // Invalid package name, expect an IAE
210 m = ModuleHelper.ModuleObject("moduleSix", cl, new String[] { "foo" }); // Name irrelevant
211 try {
212 ModuleHelper.DefineModule(m, false, "9.0", "module.name/here", new String[] { ";your/apackage" });
213 throw new RuntimeException("Failed to get expected IAE for ;your.apackage");
214 } catch(IllegalArgumentException e) {
215 if (!e.getMessage().contains("Invalid package name")) {
216 throw new RuntimeException("Failed to get expected IAE message for bad package name: " + e.getMessage());
217 }
218 }
219
220 // Invalid package name, expect an IAE
221 m = ModuleHelper.ModuleObject("moduleSeven", cl, new String[] { "foo" }); // Name irrelevant
222 try {
223 ModuleHelper.DefineModule(m, false, "9.0", "module.name/here", new String[] { "7[743" });
224 throw new RuntimeException("Failed to get expected IAE for package 7[743");
225 } catch(IllegalArgumentException e) {
226 if (!e.getMessage().contains("Invalid package name")) {
227 throw new RuntimeException("Failed to get expected IAE message for bad package name: " + e.getMessage());
263
264 // module version that is null, should be okay
265 m = ModuleHelper.ModuleObject("moduleEight", cl, new String[] { "a_package_8" });
266 assertNotNull(m, "Module should not be null");
267 ModuleHelper.DefineModule(m, false, null, "moduleEight/here", new String[] { "a_package_8" });
268
269 // module version that is "", should be okay
270 m = ModuleHelper.ModuleObject("moduleNine", cl, new String[] { "a_package_9" });
271 assertNotNull(m, "Module should not be null");
272 ModuleHelper.DefineModule(m, false, "", "moduleNine/here", new String[] { "a_package_9" });
273
274 // module location that is null, should be okay
275 m = ModuleHelper.ModuleObject("moduleTen", cl, new String[] { "a_package_10" });
276 assertNotNull(m, "Module should not be null");
277 ModuleHelper.DefineModule(m, false, "9.0", null, new String[] { "a_package_10" });
278
279 // module location that is "", should be okay
280 m = ModuleHelper.ModuleObject("moduleEleven", cl, new String[] { "a_package_11" });
281 assertNotNull(m, "Module should not be null");
282 ModuleHelper.DefineModule(m, false, "9.0", "", new String[] { "a_package_11" });
283 }
284
285 static class MyClassLoader extends ClassLoader { }
286 }
|
178
179 // Module name with consecutive dots, not allowed in java source
180 try {
181 m = ModuleHelper.ModuleObject("trailingdot.", cl, new String[] { "mypackage9b" });
182 ModuleHelper.DefineModule(m, false, "9.0", "module.name/here", new String[] { "mypackage9b" });
183 throw new RuntimeException("Failed to get expected IAE for trailingdot.");
184 } catch(IllegalArgumentException e) {
185 // Expected
186 }
187
188 // module name with multiple dots, should be okay
189 m = ModuleHelper.ModuleObject("more.than.one.dat", cl, new String[] { "mypackage9d" });
190 assertNotNull(m, "Module should not be null");
191 ModuleHelper.DefineModule(m, false, "9.0", "module.name/here", new String[] { "mypackage9d" });
192
193 // Zero length package list, should be okay
194 m = ModuleHelper.ModuleObject("zero.packages", cl, new String[] { });
195 assertNotNull(m, "Module should not be null");
196 ModuleHelper.DefineModule(m, false, "9.0", "module.name/here", new String[] { });
197
198 // Package name with dots, should be okay
199 m = ModuleHelper.ModuleObject("moduleFive", cl, new String[] { "your.apackage" });
200 assertNotNull(m, "Module should not be null");
201 ModuleHelper.DefineModule(m, false, "9.0", "moduleFive", new String[] { "your.apackage" });
202
203 // Invalid package name, expect an IAE
204 m = ModuleHelper.ModuleObject("moduleSix", cl, new String[] { "foo" }); // Name irrelevant
205 try {
206 ModuleHelper.DefineModule(m, false, "9.0", "module.name/here", new String[] { ";your/apackage" });
207 throw new RuntimeException("Failed to get expected IAE for ;your.apackage");
208 } catch(IllegalArgumentException e) {
209 if (!e.getMessage().contains("Invalid package name")) {
210 throw new RuntimeException("Failed to get expected IAE message for bad package name: " + e.getMessage());
211 }
212 }
213
214 // Invalid package name, expect an IAE
215 m = ModuleHelper.ModuleObject("moduleSeven", cl, new String[] { "foo" }); // Name irrelevant
216 try {
217 ModuleHelper.DefineModule(m, false, "9.0", "module.name/here", new String[] { "7[743" });
218 throw new RuntimeException("Failed to get expected IAE for package 7[743");
219 } catch(IllegalArgumentException e) {
220 if (!e.getMessage().contains("Invalid package name")) {
221 throw new RuntimeException("Failed to get expected IAE message for bad package name: " + e.getMessage());
257
258 // module version that is null, should be okay
259 m = ModuleHelper.ModuleObject("moduleEight", cl, new String[] { "a_package_8" });
260 assertNotNull(m, "Module should not be null");
261 ModuleHelper.DefineModule(m, false, null, "moduleEight/here", new String[] { "a_package_8" });
262
263 // module version that is "", should be okay
264 m = ModuleHelper.ModuleObject("moduleNine", cl, new String[] { "a_package_9" });
265 assertNotNull(m, "Module should not be null");
266 ModuleHelper.DefineModule(m, false, "", "moduleNine/here", new String[] { "a_package_9" });
267
268 // module location that is null, should be okay
269 m = ModuleHelper.ModuleObject("moduleTen", cl, new String[] { "a_package_10" });
270 assertNotNull(m, "Module should not be null");
271 ModuleHelper.DefineModule(m, false, "9.0", null, new String[] { "a_package_10" });
272
273 // module location that is "", should be okay
274 m = ModuleHelper.ModuleObject("moduleEleven", cl, new String[] { "a_package_11" });
275 assertNotNull(m, "Module should not be null");
276 ModuleHelper.DefineModule(m, false, "9.0", "", new String[] { "a_package_11" });
277
278 // module with very long package names, should be okay
279 String[] longPackageNames = new String[] {
280 "mypackage/mypackage/mypackage/mypackage1",
281 "mypackage/mypackage/mypackage/mypackage/" +
282 "mypackage/mypackage/mypackage/mypackage/" +
283 "mypackage/mypackage/mypackage/mypackage/" +
284 "mypackage/mypackage/mypackage/mypackage/" +
285 "mypackage/mypackage/mypackage/mypackage/" +
286 "mypackage/mypackage/mypackage/mypackage/" +
287 "mypackage/mypackage/mypackage/mypackage/" +
288 "mypackage/mypackage/mypackage/mypackage2",
289 "mypackage/mypackage/mypackage/mypackage/" +
290 "mypackage/mypackage/mypackage/mypackage/" +
291 "mypackage/mypackage/mypackage/mypackage/" +
292 "mypackage/mypackage/mypackage/mypackage/" +
293 "mypackage/mypackage/mypackage/mypackage/" +
294 "mypackage/mypackage/mypackage/mypackage/" +
295 "mypackage/mypackage/mypackage/mypackage/" +
296 "mypackage/mypackage/mypackage/mypackage/" +
297 "mypackage/mypackage/mypackage/mypackage/" +
298 "mypackage/mypackage/mypackage/mypackage/" +
299 "mypackage/mypackage/mypackage/mypackage/" +
300 "mypackage/mypackage/mypackage/mypackage3"
301 };
302 m = ModuleHelper.ModuleObject("moduleTwelve", cl, longPackageNames);
303 assertNotNull(m, "Module should not be null");
304 ModuleHelper.DefineModule(m, false, "9.0", "moduleTwelve", longPackageNames);
305 // Indirectly test that the package names doesn't get truncated when defined
306 for (int i = 0; i < longPackageNames.length; i++) {
307 ModuleHelper.AddModuleExportsToAllUnnamed(m, longPackageNames[i]);
308 }
309 }
310
311 static class MyClassLoader extends ClassLoader { }
312 }
|