### Question:
ResourceManager { public <T extends EObject> Optional<T> loadModel(final URI resourceURI, final ResourceSet rs, final Class<T> clazz) { Optional<Resource> res = loadResource(resourceURI, rs); if (res.isPresent() && !res.get().getContents().isEmpty()) { EObject root = res.get().getContents().get(0); if (clazz.isInstance(root)) { return Optional.of(clazz.cast(root)); } LOG.info(String.format("Root element of resource \"%s\" is not an instance of %s", resourceURI, clazz)); } LOG.info("Resource appears to be empty: " + resourceURI); return Optional.empty(); } @Inject  ResourceManager(final Set<EPackageConfiguration> configurations); void initialize(); @SuppressWarnings("checkstyle:IllegalCatch") Optional<Resource> loadResource(final URI resourceURI, final ResourceSet rs); Optional<Resource> loadResource(final String resourceURI, final ResourceSet rs); Optional<T> loadModel(final URI resourceURI, final ResourceSet rs, final Class<T> clazz); Optional<T> loadModel(final String resourceURI, final ResourceSet rs,
      final Class<T> clazz); boolean save(final ResourceSet rs);  }### Answer:
@Test public void testLoadModelCastToExactType() { String resourceURI = toFullPath("Test1.ecore"); Optional<EPackage> result = resourceManager.loadModel(resourceURI, resourceSet, EPackage.class); assertNotNull(result); assertTrue(result.isPresent()); assertEquals("test1", result.get().getName()); }
@Test public void testLoadModelCastToSupertype() { String resourceURI = toFullPath("Test1.ecore"); Optional<EObject> result = resourceManager.loadModel(resourceURI, resourceSet, EObject.class); assertNotNull(result); assertTrue(result.isPresent()); }
@Test public void testLoadModelInvalidCast() { String resourceURI = toFullPath("Test1.ecore"); Optional<EClass> result = resourceManager.loadModel(resourceURI, resourceSet, EClass.class); assertNotNull(result); assertFalse(result.isPresent()); }