199 Path classFile = Paths.get("p", "Provider.class");
200 Files.copy(output.resolve(classFile),
201 mods.resolve(TEST2_MODULE).resolve(classFile),
202 StandardCopyOption.REPLACE_EXISTING);
203
204 // load providers and instantiate each one
205 loadProviders(mods, TEST2_MODULE).forEach(Provider::get);
206 }
207
208
209 /**
210 * Test a service provider that defines more than one no-args
211 * public static "provider" method.
212 */
213 @Test(expectedExceptions = ServiceConfigurationError.class)
214 public void testWithTwoFactoryMethods() throws Exception {
215 Path mods = compileTest(TEST1_MODULE);
216
217 var bytes = ClassFile.of().build(ClassDesc.of("p", "ProviderFactory"), clb -> {
218 clb.withSuperclass(CD_Object);
219 clb.withFlags(AccessFlag.PUBLIC, AccessFlag.SUPER);
220
221 var providerFactory$1 = ClassDesc.of("p", "ProviderFactory$1");
222
223 // public static p.Service provider()
224 clb.withMethodBody("provider", MethodTypeDesc.of(ClassDesc.of("p", "Service")),
225 ACC_PUBLIC | ACC_STATIC, cob -> {
226 cob.new_(providerFactory$1);
227 cob.dup();
228 cob.invokespecial(providerFactory$1, INIT_NAME, MTD_void);
229 cob.areturn();
230 });
231
232 // public static p.ProviderFactory$1 provider()
233 clb.withMethodBody("provider", MethodTypeDesc.of(providerFactory$1),
234 ACC_PUBLIC | ACC_STATIC, cob -> {
235 cob.new_(providerFactory$1);
236 cob.dup();
237 cob.invokespecial(providerFactory$1, INIT_NAME, MTD_void);
238 cob.areturn();
239 });
|
199 Path classFile = Paths.get("p", "Provider.class");
200 Files.copy(output.resolve(classFile),
201 mods.resolve(TEST2_MODULE).resolve(classFile),
202 StandardCopyOption.REPLACE_EXISTING);
203
204 // load providers and instantiate each one
205 loadProviders(mods, TEST2_MODULE).forEach(Provider::get);
206 }
207
208
209 /**
210 * Test a service provider that defines more than one no-args
211 * public static "provider" method.
212 */
213 @Test(expectedExceptions = ServiceConfigurationError.class)
214 public void testWithTwoFactoryMethods() throws Exception {
215 Path mods = compileTest(TEST1_MODULE);
216
217 var bytes = ClassFile.of().build(ClassDesc.of("p", "ProviderFactory"), clb -> {
218 clb.withSuperclass(CD_Object);
219 clb.withFlags(AccessFlag.PUBLIC, AccessFlag.IDENTITY);
220
221 var providerFactory$1 = ClassDesc.of("p", "ProviderFactory$1");
222
223 // public static p.Service provider()
224 clb.withMethodBody("provider", MethodTypeDesc.of(ClassDesc.of("p", "Service")),
225 ACC_PUBLIC | ACC_STATIC, cob -> {
226 cob.new_(providerFactory$1);
227 cob.dup();
228 cob.invokespecial(providerFactory$1, INIT_NAME, MTD_void);
229 cob.areturn();
230 });
231
232 // public static p.ProviderFactory$1 provider()
233 clb.withMethodBody("provider", MethodTypeDesc.of(providerFactory$1),
234 ACC_PUBLIC | ACC_STATIC, cob -> {
235 cob.new_(providerFactory$1);
236 cob.dup();
237 cob.invokespecial(providerFactory$1, INIT_NAME, MTD_void);
238 cob.areturn();
239 });
|