[jscover] 40/69: Remove checked exception from public API
Sylvestre Ledru
sylvestre at moszumanska.debian.org
Fri Aug 22 05:54:05 UTC 2014
This is an automated email from the git hooks/post-receive script.
sylvestre pushed a commit to branch master
in repository jscover.
commit c63924f4d14c50dde54a8f614a73ab66546d11fb
Author: tntim96 <tntim96 at gmail.com>
Date: Thu Jul 3 22:58:56 2014 +1000
Remove checked exception from public API
---
History.md | 4 +++
src/main/java/jscover/report/Main.java | 12 ++++-----
src/main/java/jscover/util/IoUtils.java | 17 ++++++++++++
src/test/java/jscover/report/MainTest.java | 8 +++---
src/test/java/jscover/util/IoUtilsTest.java | 40 +++++++++++++++++++++++++++++
5 files changed, 71 insertions(+), 10 deletions(-)
diff --git a/History.md b/History.md
index 4aa6ba5..016056b 100644
--- a/History.md
+++ b/History.md
@@ -1,3 +1,7 @@
+1.0.13 / 2014-??-??
+==================
+ * Internal: Remove checked exception from public API
+
1.0.12 / 2014-07-02
==================
* Add `--save-json-only` to only save coverage data (https://github.com/tntim96/JSCover/issues/142)
diff --git a/src/main/java/jscover/report/Main.java b/src/main/java/jscover/report/Main.java
index 34d08ab..af5e45c 100644
--- a/src/main/java/jscover/report/Main.java
+++ b/src/main/java/jscover/report/Main.java
@@ -364,8 +364,8 @@ public class Main {
public static final Properties properties = new Properties();
- public void initialize() throws IOException {
- properties.load(jscover.Main.class.getResourceAsStream("/jscover/configuration.properties"));
+ public void initialize() {
+ ioUtils.loadProperties(properties, jscover.Main.class.getResourceAsStream("/jscover/configuration.properties"));
}
private ExitHelper exitHelper = new ExitHelper();
@@ -437,10 +437,10 @@ public class Main {
ioUtils.copy(jsonDataMerger.toJSON(mergedMap), mergedJson);
}
- public void generateLCovDataFile() throws IOException {
+ public void generateLCovDataFile() {
String json = ioUtils.loadFromFileSystem(new File(config.getJsonDirectory(), "jscoverage.json"));
File lcovFile = new File(config.getJsonDirectory(), "jscover.lcov");
- lCovGenerator.saveData(jsonDataMerger.jsonToMap(json).values(), config.getSourceDirectory().getCanonicalPath(), lcovFile);
+ lCovGenerator.saveData(jsonDataMerger.jsonToMap(json).values(), ioUtils.getCanonicalPath(config.getSourceDirectory()), lcovFile);
}
public void saveXmlSummary() {
@@ -449,9 +449,9 @@ public class Main {
xmlSummary.saveSummary(summaryData, config.getJsonDirectory(), config.getVersion());
}
- public void saveCoberturaXml() throws IOException {
+ public void saveCoberturaXml() {
String json = ioUtils.loadFromFileSystem(new File(config.getJsonDirectory(), "jscoverage.json"));
- String xml = coberturaXmlGenerator.generateXml(new CoberturaData(jsonDataMerger.jsonToMap(json).values()), config.getSourceDirectory().getCanonicalPath(), config.getVersion());
+ String xml = coberturaXmlGenerator.generateXml(new CoberturaData(jsonDataMerger.jsonToMap(json).values()), ioUtils.getCanonicalPath(config.getSourceDirectory()), config.getVersion());
File dest = new File(config.getJsonDirectory(), "cobertura-coverage.xml");
ioUtils.copy(xml, dest);
}
diff --git a/src/main/java/jscover/util/IoUtils.java b/src/main/java/jscover/util/IoUtils.java
index d2f4797..9bf856a 100644
--- a/src/main/java/jscover/util/IoUtils.java
+++ b/src/main/java/jscover/util/IoUtils.java
@@ -345,6 +345,7 @@ package jscover.util;
import java.io.*;
import java.net.Socket;
import java.nio.charset.Charset;
+import java.util.Properties;
import java.util.logging.Level;
import java.util.logging.Logger;
@@ -624,6 +625,22 @@ public class IoUtils {
ioUtils.copy(src, dest);
}
+ public String getCanonicalPath(File file) {
+ try {
+ return file.getCanonicalPath();
+ } catch (IOException e) {
+ throw new RuntimeException(e);
+ }
+ }
+
+ public void loadProperties(Properties properties, InputStream is) {
+ try {
+ properties.load(is);
+ } catch (IOException e) {
+ throw new RuntimeException(e);
+ }
+ }
+
public int getDataIndex(byte[] bytes, Charset charset) {
String firstBytes = new String(bytes, charset);
String separator = CRLFx2;
diff --git a/src/test/java/jscover/report/MainTest.java b/src/test/java/jscover/report/MainTest.java
index 1fcf6ae..8fe997a 100644
--- a/src/test/java/jscover/report/MainTest.java
+++ b/src/test/java/jscover/report/MainTest.java
@@ -362,10 +362,8 @@ import org.mockito.runners.MockitoJUnitRunner;
import java.io.File;
import java.io.IOException;
-import java.util.ArrayList;
-import java.util.List;
-import java.util.SortedMap;
-import java.util.TreeMap;
+import java.io.InputStream;
+import java.util.*;
import static jscover.Main.reportSrcSubDir;
import static org.hamcrest.CoreMatchers.is;
@@ -436,6 +434,7 @@ public class MainTest {
given(config.getSourceDirectory()).willReturn(srcDir);
String json = "json";
given(ioUtils.loadFromFileSystem(new File(jsonDirectory, "jscoverage.json"))).willReturn(json);
+ doReturn(srcDir.getCanonicalPath()).when(ioUtils).getCanonicalPath(srcDir);
SortedMap<String, FileData> list = new TreeMap<String, FileData>();
given(jsonDataMerger.jsonToMap(json)).willReturn(list);
@@ -456,6 +455,7 @@ public class MainTest {
given(config.getSourceDirectory()).willReturn(srcDir);
String json = "json";
given(ioUtils.loadFromFileSystem(new File(jsonDirectory, "jscoverage.json"))).willReturn(json);
+ doReturn(srcDir.getCanonicalPath()).when(ioUtils).getCanonicalPath(srcDir);
SortedMap<String, FileData> list = new TreeMap<String, FileData>();
given(jsonDataMerger.jsonToMap(json)).willReturn(list);
given(coberturaXmlGenerator.generateXml(Matchers.<CoberturaData>any(), anyString(), anyString())).willReturn("<xml/>");
diff --git a/src/test/java/jscover/util/IoUtilsTest.java b/src/test/java/jscover/util/IoUtilsTest.java
index 0ad7f63..6992c2b 100644
--- a/src/test/java/jscover/util/IoUtilsTest.java
+++ b/src/test/java/jscover/util/IoUtilsTest.java
@@ -352,6 +352,7 @@ import org.mockito.runners.MockitoJUnitRunner;
import java.io.*;
import java.net.Socket;
import java.nio.charset.Charset;
+import java.util.Properties;
import static org.hamcrest.CoreMatchers.equalTo;
import static org.junit.Assert.*;
@@ -624,6 +625,45 @@ public class IoUtilsTest {
}
@Test
+ public void shouldGetCanonicalPath() throws IOException {
+ File file = new File("target/test.txt");
+ assertThat(ioUtils.getCanonicalPath(file), equalTo(file.getCanonicalPath()));
+ }
+
+ @Test
+ public void shouldWrapCanonicalPathException() throws IOException {
+ File file = mock(File.class);
+ given(file.getCanonicalPath()).willThrow(new IOException("Ouch!"));
+ try {
+ ioUtils.getCanonicalPath(file);
+ fail("Expected exception");
+ } catch (RuntimeException e) {
+ assertThat(e.getMessage(), equalTo("java.io.IOException: Ouch!"));
+ }
+ }
+
+ @Test
+ public void shouldLoadProperties() throws IOException {
+ Properties properties = mock(Properties.class);
+ InputStream is = mock(InputStream.class);
+ ioUtils.loadProperties(properties, is);
+ verify(properties).load(is);
+ }
+
+ @Test
+ public void shouldWrapLoadPropertiesException() throws IOException {
+ Properties properties = mock(Properties.class);
+ InputStream is = mock(InputStream.class);
+ doThrow(new IOException("Ouch!")).when(properties).load(is);
+ try {
+ ioUtils.loadProperties(properties, is);
+ fail("Expected exception");
+ } catch (RuntimeException e) {
+ assertThat(e.getMessage(), equalTo("java.io.IOException: Ouch!"));
+ }
+ }
+
+ @Test
public void should() {
new Dummy();
}
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-java/jscover.git
More information about the pkg-java-commits
mailing list