MetadataResourceResolver { String removeFileExtension(String path) { if (simpleFileSystem.isFile(path)) { int i = path.lastIndexOf('.'); if (i > 0) { return path.substring(0, i); } } return path; } MetadataResourceResolver(SimpleFileSystem simpleFileSystem); SortedMap<String, String> getSourceMetadataPaths(String sourcePath); TargetResourceInfo getTargetName(String templatePath, String targetPath); static final String VELOCITY_TEMPLATE_EXTENSION; }
@Test public void testRemovefileExtension() throws Exception { SimpleFileSystem fileSystem = mock(SimpleFileSystem.class); MetadataResourceResolver metadataResourceResolver = new MetadataResourceResolver(fileSystem); when(fileSystem.isFile(Matchers.anyString())).thenReturn(true); assertEquals("foo", metadataResourceResolver.removeFileExtension("foo.txt")); assertEquals("foo", metadataResourceResolver.removeFileExtension("foo")); assertEquals("foo/bar", metadataResourceResolver.removeFileExtension("foo/bar.baz")); assertEquals("foo\\bar", metadataResourceResolver.removeFileExtension("foo\\bar.baz")); when(fileSystem.isFile(Matchers.anyString())).thenReturn(false ); assertEquals("bar.foo", metadataResourceResolver.removeFileExtension("bar.foo")); assertEquals("\\root\\foo", metadataResourceResolver.removeFileExtension("\\root\\foo")); String directory = "C:\\Users\\bettina\\Software-Tests\\own-software\\ceres-metadata-0.13.2-SNAPSHOT\\data\\out"; assertEquals(directory, metadataResourceResolver.removeFileExtension(directory)); assertEquals("/root/foo/", metadataResourceResolver.removeFileExtension("/root/foo/")); }