propane = cdk.loadMolecule(path); Assert.assertNotNull(propane.getResource()); Assert.assertTrue(propane.getResource() instanceof IFile); IFile resource = (IFile)propane.getResource(); Assert.assertNotNull(resource.getContentDescription()); IContentType type = resource.getContentDescription().getContentType(); Assert.assertNotNull(type); IChemFormat format = cdk.determineFormat(type); Assert.assertNotNull(format); Assert.assertEquals(MDLV2000Format.getInstance(), format);This test uses the getContentDescription() to get a content description and converts it to a CDK library specific format type.
The JavaDoc lists this methods as more efficient alternative:
- Calling this method produces a similar effect as calling getDescriptionFor(getContents(), getName(), IContentDescription.ALL) on IContentTypeManager, but provides better opportunities for improved performance.
As it used to work, I am considering the option it is a bug. But at the same time, maybe best practices have change? Should I keep using this method, explore the cause, perhaps file a bug report, or start using getDescriptionFor(getContents(), getName(), IContentDescription.ALL)?
Technically it could always return null. You'll probably want to fall back on IContentTypeMatcher#findContentTypesFor(String) if that happens in production code, but you should probably test that the resource is #isAccessible() in your test as well.
ReplyDeleteThanx for the tip! I will look into that API.
ReplyDelete