public static Version load(System2 system) { try { URL url = system.getResource(FILE_PATH); String versionInFile = Resources.toString(url, StandardCharsets.UTF_8); return Version.parse(versionInFile); } catch (IOException e) { throw new IllegalStateException("Can not load " + FILE_PATH + " from classpath", e); } } }
@Test public void testGetResource() { String name = "META-INF/MANIFEST.MF"; assertThat(System2.INSTANCE.getResource(name)).isEqualTo(getClass().getResource(name)); }
@Test public void throw_ISE_if_fail_to_load_version() throws Exception { expectedException.expect(IllegalStateException.class); expectedException.expectMessage("Can not load /sonar-api-version.txt from classpath"); System2 system = spy(System2.class); when(system.getResource(anyString())).thenReturn(new File("target/unknown").toURI().toURL()); ApiVersion.load(system); }
public static Version load(System2 system) { try { URL url = system.getResource(FILE_PATH); String versionInFile = Resources.toString(url, StandardCharsets.UTF_8); return Version.parse(versionInFile); } catch (IOException e) { throw new IllegalStateException("Can not load " + FILE_PATH + " from classpath", e); } } }