@Test public void should_find_module_components_with_non_global_strategy() { InputComponentStore inputComponentStore = mock(InputComponentStore.class); SensorStrategy strategy = new SensorStrategy(); InputModule module = mock(InputModule.class); when(module.key()).thenReturn("foo"); ModuleInputComponentStore store = new ModuleInputComponentStore(module, inputComponentStore, strategy); strategy.setGlobal(false); store.inputFiles(); verify(inputComponentStore).filesByModule("foo"); String relativePath = "somepath"; store.inputFile(relativePath); verify(inputComponentStore).getFile(any(String.class), eq(relativePath)); store.languages(); verify(inputComponentStore).languages(any(String.class)); }
@Test public void test() throws Exception { Metadata metadata = new Metadata(42, 42, "", new int[0], new int[0], 10); DefaultInputFile inputFile = new DefaultInputFile(indexedFile, (f) -> f.setMetadata(metadata)) .setStatus(InputFile.Status.ADDED) .setCharset(StandardCharsets.ISO_8859_1); assertThat(inputFile.absolutePath()).endsWith("Foo.php"); assertThat(inputFile.filename()).isEqualTo("Foo.php"); assertThat(inputFile.uri()).hasPath(baseDir.resolve(PROJECT_RELATIVE_PATH).toUri().getPath()); assertThat(new File(inputFile.absolutePath())).isAbsolute(); assertThat(inputFile.language()).isEqualTo("php"); assertThat(inputFile.status()).isEqualTo(InputFile.Status.ADDED); assertThat(inputFile.type()).isEqualTo(InputFile.Type.TEST); assertThat(inputFile.lines()).isEqualTo(42); assertThat(inputFile.charset()).isEqualTo(StandardCharsets.ISO_8859_1); assertThat(inputFile.getModuleRelativePath()).isEqualTo(MODULE_RELATIVE_PATH); assertThat(inputFile.getProjectRelativePath()).isEqualTo(PROJECT_RELATIVE_PATH); sensorStrategy.setGlobal(false); assertThat(inputFile.relativePath()).isEqualTo(MODULE_RELATIVE_PATH); assertThat(new File(inputFile.relativePath())).isRelative(); sensorStrategy.setGlobal(true); assertThat(inputFile.relativePath()).isEqualTo(PROJECT_RELATIVE_PATH); assertThat(new File(inputFile.relativePath())).isRelative(); }
@Test public void should_find_all_components_with_global_strategy() { InputComponentStore inputComponentStore = mock(InputComponentStore.class); SensorStrategy strategy = new SensorStrategy(); ModuleInputComponentStore store = new ModuleInputComponentStore(mock(InputModule.class), inputComponentStore, strategy); strategy.setGlobal(true); store.inputFiles(); verify(inputComponentStore).inputFiles(); String relativePath = "somepath"; store.inputFile(relativePath); verify(inputComponentStore).inputFile(relativePath); store.languages(); verify(inputComponentStore).languages(); } }