### Question:
OASFactoryResolverImpl extends OASFactoryResolver { @SuppressWarnings("unchecked") @Override public <T extends Constructible> T createObject(Class<T> clazz) { if (clazz == null) { throw new NullPointerException(); } Class<? extends Constructible> implClass = registry.get(clazz); if (implClass == null) { throw SpiMessages.msg.classNotConstructible(clazz.getName()); } try { return (T) implClass.getConstructor().newInstance(); } catch (InstantiationException | IllegalAccessException | IllegalArgumentException | InvocationTargetException | NoSuchMethodException | SecurityException e) { throw new IllegalArgumentException(e); } }  @SuppressWarnings("unchecked") @Override T createObject(Class<T> clazz);  }### Answer:
@SuppressWarnings({ "rawtypes", "unchecked" }) @Test public void testCreateObject_All() { Class modelClasses[] = { APIResponse.class, APIResponses.class, Callback.class, Components.class, Contact.class, Content.class, Discriminator.class, Encoding.class, Example.class, ExternalDocumentation.class, Header.class, Info.class, License.class, Link.class, MediaType.class, OAuthFlow.class, OAuthFlows.class, OpenAPI.class, Operation.class, Parameter.class, PathItem.class, Paths.class, RequestBody.class, Schema.class, SecurityRequirement.class, SecurityScheme.class, Server.class, ServerVariable.class, Tag.class, XML.class }; for (Class modelClass : modelClasses) { Constructible object = OASFactory.createObject(modelClass); Assert.assertNotNull(object); } }
@Test public void testCreateObject_License() { License license = OASFactory.createObject(License.class).name("Test License").url("urn:test-url"); Assert.assertNotNull(license); Assert.assertEquals(LicenseImpl.class, license.getClass()); Assert.assertEquals("Test License", license.getName()); Assert.assertEquals("urn:test-url", license.getUrl()); }
@SuppressWarnings({ "rawtypes", "unchecked" }) @Test public void testCreateObject_RTE() { Class c = String.class; try { OASFactory.createObject(c); Assert.fail("Expected a runtime error."); } catch (RuntimeException e) { Assert.assertEquals("SROAP09000: Class 'java.lang.String' is not Constructible.", e.getMessage()); } }