@Test public void file_processor_is_always_available() { UriReader uriReader = new UriReader(new UriReader.SchemeProcessor[0]); assertThat(uriReader.searchForSupportedProcessor(testFile)).isNotNull(); }
@Test public void register_processors() throws Exception { UriReader.SchemeProcessor processor = mock(UriReader.SchemeProcessor.class); when(processor.getSupportedSchemes()).thenReturn(new String[] {"ftp"}); UriReader uriReader = new UriReader(new UriReader.SchemeProcessor[] {processor}); assertThat(uriReader.searchForSupportedProcessor(new URI("ftp://sonarsource.org"))).isNotNull(); } }
@Test public void file_readBytes() { UriReader uriReader = new UriReader(new UriReader.SchemeProcessor[0]); assertThat(new String(uriReader.readBytes(testFile))).isEqualTo("in foo"); }
@Test public void file_readString() { UriReader uriReader = new UriReader(new UriReader.SchemeProcessor[0]); assertThat(uriReader.readString(testFile, StandardCharsets.UTF_8)).isEqualTo("in foo"); }
@Test public void file_readString_fails_if_file_not_found() throws Exception { thrown.expect(RuntimeException.class); UriReader uriReader = new UriReader(new UriReader.SchemeProcessor[0]); uriReader.readString(new URI("file:/notfound"), StandardCharsets.UTF_8); }
@Test public void file_readBytes_fails_if_file_not_found() throws Exception { thrown.expect(RuntimeException.class); UriReader uriReader = new UriReader(new UriReader.SchemeProcessor[0]); uriReader.readBytes(new URI("file:/notfound")); }
@Test public void fail_if_unknown_scheme() throws Exception { thrown.expect(IllegalArgumentException.class); UriReader uriReader = new UriReader(new UriReader.SchemeProcessor[0]); uriReader.readBytes(new URI("ftp://sonarsource.org")); }
@Test public void file_description() { UriReader uriReader = new UriReader(new UriReader.SchemeProcessor[0]); // the prefix file:/ is removed assertThat(uriReader.description(testFile)).doesNotMatch("file:/.*"); assertThat(uriReader.description(testFile)).matches(".*foo\\.txt"); }