diff --git a/History.md b/History.md
index f0d94a7b..b85ec4b8 100644
--- a/History.md
+++ b/History.md
@@ -1,7 +1,7 @@
2.0.24 / 2026-??-??
==================
* Upgrade closure-compiler v20260128 to v20260406, Rhino 1.9.0 to 1.9.1
- * Internal: Mockito 5.20.0 to 5.23.0, JUnit 4.13.2 to JUnit 5.14.3
+ * Internal: Mockito 5.20.0 to 5.23.0, JUnit 4.13.2 to JUnit 6.0.3, Hamcrest 3.0 to AssertJ 3.27.7
2.0.23 / 2026-02-10
==================
diff --git a/JSCover.iml b/JSCover.iml
index c0a36fa9..e6e726bb 100644
--- a/JSCover.iml
+++ b/JSCover.iml
@@ -68,10 +68,9 @@
-
-
+
+
-
diff --git a/JSCover.ipr b/JSCover.ipr
index 4ab116f9..c5d82d0a 100644
--- a/JSCover.ipr
+++ b/JSCover.ipr
@@ -810,16 +810,16 @@
-
-
+
+
-
+
-
+
-
+
@@ -882,28 +882,16 @@
-
-
+
+
-
+
-
+
-
-
-
-
-
-
-
-
-
-
-
-
-
+
diff --git a/pom.xml b/pom.xml
index ad0d8979..75e84c21 100644
--- a/pom.xml
+++ b/pom.xml
@@ -106,9 +106,9 @@
test
- org.hamcrest
- hamcrest-core
- 3.0
+ org.assertj
+ assertj-core
+ 3.27.7
test
diff --git a/src/main/java/jscover/instrument/CommentsHandler.java b/src/main/java/jscover/instrument/CommentsHandler.java
index 6dd1f9cc..e86a7d16 100644
--- a/src/main/java/jscover/instrument/CommentsHandler.java
+++ b/src/main/java/jscover/instrument/CommentsHandler.java
@@ -342,7 +342,6 @@ You should also get your employer (if you work as a programmer) or your
package jscover.instrument;
-
import com.google.javascript.jscomp.parsing.parser.trees.Comment;
import java.util.HashSet;
diff --git a/src/main/java/jscover/report/BranchData.java b/src/main/java/jscover/report/BranchData.java
index 5d477dde..2dbcafa8 100644
--- a/src/main/java/jscover/report/BranchData.java
+++ b/src/main/java/jscover/report/BranchData.java
@@ -342,7 +342,6 @@ You should also get your employer (if you work as a programmer) or your
package jscover.report;
-
import java.util.logging.Level;
import java.util.logging.Logger;
diff --git a/src/main/java/jscover/server/HttpRequest.java b/src/main/java/jscover/server/HttpRequest.java
index d4fc1a0e..ca974e6b 100644
--- a/src/main/java/jscover/server/HttpRequest.java
+++ b/src/main/java/jscover/server/HttpRequest.java
@@ -342,7 +342,6 @@ You should also get your employer (if you work as a programmer) or your
package jscover.server;
-
import java.io.InputStream;
import java.io.OutputStream;
import java.net.MalformedURLException;
diff --git a/src/test-acceptance/java/jscover/MainGenerateFileAcceptanceTest.java b/src/test-acceptance/java/jscover/MainGenerateFileAcceptanceTest.java
index f82216c0..5f6008ba 100644
--- a/src/test-acceptance/java/jscover/MainGenerateFileAcceptanceTest.java
+++ b/src/test-acceptance/java/jscover/MainGenerateFileAcceptanceTest.java
@@ -350,9 +350,7 @@ You should also get your employer (if you work as a programmer) or your
import java.io.File;
import java.io.IOException;
-import static org.hamcrest.CoreMatchers.endsWith;
-import static org.hamcrest.MatcherAssert.assertThat;
-import static org.hamcrest.Matchers.is;
+import static org.assertj.core.api.Assertions.assertThat;
public class MainGenerateFileAcceptanceTest {
private IoUtils ioUtils = IoUtils.getInstance();
@@ -372,10 +370,10 @@ public void shouldGenerateReportFiles() throws IOException {
File jsCoverHtml = new File(reportDir, "jscoverage.html");
File jsCoverJS = new File(reportDir, "jscoverage.js");
File origSrc = new File(reportDir, Main.reportSrcSubDir);
- assertThat(jsCoverHtml.exists(), is(true));
- assertThat(jsCoverJS.exists(), is(true));
- assertThat(origSrc.exists(), is(false));
- assertThat(ioUtils.loadFromFileSystem(jsCoverJS), endsWith("\njscoverage_isReport = true;"));
+ assertThat(jsCoverHtml.exists()).isTrue();
+ assertThat(jsCoverJS.exists()).isTrue();
+ assertThat(origSrc.exists()).isFalse();
+ assertThat(ioUtils.loadFromFileSystem(jsCoverJS)).endsWith("\njscoverage_isReport = true;");
}
@Test
@@ -388,10 +386,10 @@ public void shouldGenerateReportFilesWithOriginalSource() throws IOException {
File jsCoverHtml = new File(reportDir, "jscoverage.html");
File jsCoverJS = new File(reportDir, "jscoverage.js");
File origSrc = new File(reportDir, Main.reportSrcSubDir);
- assertThat(jsCoverHtml.exists(), is(true));
- assertThat(jsCoverJS.exists(), is(true));
- assertThat(new File(origSrc, "script.js").exists(), is(true));
- assertThat(ioUtils.loadFromFileSystem(jsCoverJS), endsWith("\njscoverage_isReport = true;"));
+ assertThat(jsCoverHtml.exists()).isTrue();
+ assertThat(jsCoverJS.exists()).isTrue();
+ assertThat(new File(origSrc, "script.js").exists()).isTrue();
+ assertThat(ioUtils.loadFromFileSystem(jsCoverJS)).endsWith("\njscoverage_isReport = true;");
}
}
diff --git a/src/test-acceptance/java/jscover/filesystem/HtmlUnitFileSystemTest.java b/src/test-acceptance/java/jscover/filesystem/HtmlUnitFileSystemTest.java
index b0e4ac5e..1220a466 100644
--- a/src/test-acceptance/java/jscover/filesystem/HtmlUnitFileSystemTest.java
+++ b/src/test-acceptance/java/jscover/filesystem/HtmlUnitFileSystemTest.java
@@ -352,8 +352,7 @@ You should also get your employer (if you work as a programmer) or your
import java.io.File;
import java.io.IOException;
-import static org.hamcrest.CoreMatchers.equalTo;
-import static org.hamcrest.MatcherAssert.assertThat;
+import static org.assertj.core.api.Assertions.assertThat;
import static org.junit.jupiter.api.Assertions.assertEquals;
public class HtmlUnitFileSystemTest {
@@ -373,10 +372,10 @@ public void shouldWorkWithFileSystem() throws Exception {
Main.main(args);
String noInstrumentJS = ioUtils.loadFromFileSystem(new File(reportDir+"/example/lib/noInstrument.js"));
- assertThat(noInstrumentJS, equalTo("alert('Hey');"));
+ assertThat(noInstrumentJS).isEqualTo("alert('Hey');");
- assertThat(new File(reportDir+"/example/script.js").exists(), equalTo(true));
- assertThat(new File(reportDir+"/example/noCopy/test.txt").exists(), equalTo(false));
+ assertThat(new File(reportDir+"/example/script.js").exists()).isEqualTo(true);
+ assertThat(new File(reportDir+"/example/noCopy/test.txt").exists()).isEqualTo(false);
HtmlPage page = webClient.getPage(getFileURL(reportDir + "/jscoverage.html?example/index.html"));
verifyTotal(webClient, page, 15);
diff --git a/src/test-acceptance/java/jscover/report/MainReportMergeAcceptanceTest.java b/src/test-acceptance/java/jscover/report/MainReportMergeAcceptanceTest.java
index c83e681f..504be18e 100644
--- a/src/test-acceptance/java/jscover/report/MainReportMergeAcceptanceTest.java
+++ b/src/test-acceptance/java/jscover/report/MainReportMergeAcceptanceTest.java
@@ -344,7 +344,6 @@ You should also get your employer (if you work as a programmer) or your
import jscover.util.IoUtils;
import org.apache.commons.io.FileUtils;
-import org.hamcrest.Matchers;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
@@ -352,10 +351,7 @@ You should also get your employer (if you work as a programmer) or your
import java.io.IOException;
import java.util.Properties;
-import static org.hamcrest.CoreMatchers.endsWith;
-import static org.hamcrest.CoreMatchers.equalTo;
-import static org.hamcrest.MatcherAssert.assertThat;
-import static org.hamcrest.Matchers.is;
+import static org.assertj.core.api.Assertions.assertThat;
public class MainReportMergeAcceptanceTest {
private IoUtils ioUtils = IoUtils.getInstance();
@@ -386,18 +382,18 @@ public void shouldGenerateReportFiles() throws IOException {
properties.load(jscover.Main.class.getResourceAsStream("/jscover/configuration.properties"));
Main.main(args);
File jsCoverHtml = new File(reportDir12, "jscoverage.html");
- assertThat(jsCoverHtml.exists(), is(true));
+ assertThat(jsCoverHtml.exists()).isTrue();
File jsCoverJS = new File(reportDir12, "jscoverage.js");
- assertThat(jsCoverJS.exists(), is(true));
- assertThat(ioUtils.loadFromFileSystem(jsCoverHtml), Matchers.containsString(properties.getProperty("version")));
- assertThat(ioUtils.loadFromFileSystem(jsCoverJS), endsWith("\njscoverage_isReport = true;"));
+ assertThat(jsCoverJS.exists()).isTrue();
+ assertThat(ioUtils.loadFromFileSystem(jsCoverHtml)).contains(properties.getProperty("version"));
+ assertThat(ioUtils.loadFromFileSystem(jsCoverJS)).endsWith("\njscoverage_isReport = true;");
}
@Test
public void shouldNotCopyExtraFiles() throws IOException {
ioUtils.copy(data1, new File(reportDir1, "dummy.html"));
Main.main(args);
- assertThat(new File(reportDir12, "dummy.html").exists(), is(false));
+ assertThat(new File(reportDir12, "dummy.html").exists()).isFalse();
}
@Test
@@ -405,6 +401,6 @@ public void shouldMergeDataWithoutSource() throws IOException {
String expected = ioUtils.loadFromClassPath("/jscover/report/jscoverage-select-1-3.json");
Main.main(args);
String merged = ioUtils.loadFromFileSystem(new File(reportDir12, "jscoverage.json"));
- assertThat(merged, equalTo(expected));
+ assertThat(merged).isEqualTo(expected);
}
}
diff --git a/src/test-acceptance/java/jscover/server/HtmlServerUnloadedJSProxyOnlyInstrumentRegTest.java b/src/test-acceptance/java/jscover/server/HtmlServerUnloadedJSProxyOnlyInstrumentRegTest.java
index c943d404..6083e550 100644
--- a/src/test-acceptance/java/jscover/server/HtmlServerUnloadedJSProxyOnlyInstrumentRegTest.java
+++ b/src/test-acceptance/java/jscover/server/HtmlServerUnloadedJSProxyOnlyInstrumentRegTest.java
@@ -358,8 +358,7 @@ You should also get your employer (if you work as a programmer) or your
import java.net.ServerSocket;
import java.net.Socket;
-import static org.hamcrest.MatcherAssert.assertThat;
-import static org.hamcrest.Matchers.*;
+import static org.assertj.core.api.Assertions.assertThat;
import static org.junit.jupiter.api.Assertions.assertEquals;
//Provided by https://github.com/devangnegandhi 6 Sept 2013
@@ -439,12 +438,12 @@ public void shouldIncludeUnloadJSInSavedReport() throws Exception {
webClient.waitForBackgroundJavaScript(2000);
String result = page.getElementById("storeDiv").getTextContent();
- assertThat(result, containsString("Coverage data stored at " + new File(reportDir).getPath()));
+ assertThat(result).contains("Coverage data stored at " + new File(reportDir).getPath());
String json = ioUtils.toString(jsonFile);
- assertThat(json, not(containsString("/root.js")));
- assertThat(json, containsString("/level1/level1.js"));
- assertThat(json, containsString("/level1/level2/level2.js"));
+ assertThat(json).doesNotContain("/root.js");
+ assertThat(json).contains("/level1/level1.js");
+ assertThat(json).contains("/level1/level2/level2.js");
String url = "file:///" + new File(reportDir + "/jscoverage.html").getAbsolutePath();
page = webClient.getPage(url);
@@ -458,9 +457,9 @@ public void shouldIncludeUnloadJSInSavedReport() throws Exception {
}
private void verifyCoverage(HtmlPage page, String uri, String linePercentage, String branchPercentage, String functionPercentage) {
- assertThat(getHtmlElement(page, "//tr[@id='row-" + uri + "']/td[11]/span").getTextContent(), equalTo(linePercentage));
- assertThat(getHtmlElement(page, "//tr[@id='row-" + uri + "']/td[12]/span").getTextContent(), equalTo(branchPercentage));
- assertThat(getHtmlElement(page, "//tr[@id='row-" + uri + "']/td[13]/span").getTextContent(), equalTo(functionPercentage));
+ assertThat(getHtmlElement(page, "//tr[@id='row-" + uri + "']/td[11]/span").getTextContent()).isEqualTo(linePercentage);
+ assertThat(getHtmlElement(page, "//tr[@id='row-" + uri + "']/td[12]/span").getTextContent()).isEqualTo(branchPercentage);
+ assertThat(getHtmlElement(page, "//tr[@id='row-" + uri + "']/td[13]/span").getTextContent()).isEqualTo(functionPercentage);
}
private HtmlElement getHtmlElement(HtmlPage page, String xpathExpr) {
diff --git a/src/test-acceptance/java/jscover/server/HtmlServerUnloadedJSTestBaseClass.java b/src/test-acceptance/java/jscover/server/HtmlServerUnloadedJSTestBaseClass.java
index 61700acf..ef600fae 100644
--- a/src/test-acceptance/java/jscover/server/HtmlServerUnloadedJSTestBaseClass.java
+++ b/src/test-acceptance/java/jscover/server/HtmlServerUnloadedJSTestBaseClass.java
@@ -8,9 +8,7 @@
import java.io.File;
-import static org.hamcrest.MatcherAssert.assertThat;
-import static org.hamcrest.Matchers.containsString;
-import static org.hamcrest.Matchers.equalTo;
+import static org.assertj.core.api.Assertions.assertThat;
import static org.junit.jupiter.api.Assertions.assertEquals;
public abstract class HtmlServerUnloadedJSTestBaseClass {
@@ -50,11 +48,11 @@ public void shouldIncludeUnloadJSInSavedReport() throws Exception {
webClient.waitForBackgroundJavaScript(2000);
String result = page.getElementById("storeDiv").getTextContent();
- assertThat(result, containsString("Coverage data stored at " + new File(getReportDir()).getPath()));
+ assertThat(result).contains("Coverage data stored at " + new File(getReportDir()).getPath());
String json = ioUtils.toString(jsonFile);
- assertThat(json, containsString("/root.js"));
- assertThat(json, containsString("/level1/level2/level2.js"));
+ assertThat(json).contains("/root.js");
+ assertThat(json).contains("/level1/level2/level2.js");
String url = "file:///" + new File(getReportDir() + "/jscoverage.html").getAbsolutePath();
page = webClient.getPage(url);
@@ -68,9 +66,9 @@ public void shouldIncludeUnloadJSInSavedReport() throws Exception {
}
private void verifyCoverage(HtmlPage page, String uri, String linePercentage, String branchPercentage, String functionPercentage) {
- assertThat(getHtmlElement(page, "//tr[@id='row-" + uri + "']/td[11]/span").getTextContent(), equalTo(linePercentage));
- assertThat(getHtmlElement(page, "//tr[@id='row-" + uri + "']/td[12]/span").getTextContent(), equalTo(branchPercentage));
- assertThat(getHtmlElement(page, "//tr[@id='row-" + uri + "']/td[13]/span").getTextContent(), equalTo(functionPercentage));
+ assertThat(getHtmlElement(page, "//tr[@id='row-" + uri + "']/td[11]/span").getTextContent()).isEqualTo(linePercentage);
+ assertThat(getHtmlElement(page, "//tr[@id='row-" + uri + "']/td[12]/span").getTextContent()).isEqualTo(branchPercentage);
+ assertThat(getHtmlElement(page, "//tr[@id='row-" + uri + "']/td[13]/span").getTextContent()).isEqualTo(functionPercentage);
}
private HtmlElement getHtmlElement(HtmlPage page, String xpathExpr) {
diff --git a/src/test-acceptance/java/jscover/server/HtmlUnitJSTest.java b/src/test-acceptance/java/jscover/server/HtmlUnitJSTest.java
index 5e1145a6..269490f8 100644
--- a/src/test-acceptance/java/jscover/server/HtmlUnitJSTest.java
+++ b/src/test-acceptance/java/jscover/server/HtmlUnitJSTest.java
@@ -352,9 +352,7 @@ You should also get your employer (if you work as a programmer) or your
import java.util.List;
-import static org.hamcrest.MatcherAssert.assertThat;
-import static org.hamcrest.Matchers.equalTo;
-import static org.hamcrest.Matchers.startsWith;
+import static org.assertj.core.api.Assertions.assertThat;
import static org.junit.jupiter.api.Assertions.assertEquals;
public class HtmlUnitJSTest {
@@ -392,10 +390,10 @@ public void shouldTestJavaScript() throws Exception {
//Verify Jasmine test result
HtmlPage frame = (HtmlPage)page.getFrameByName("browserIframe").getEnclosedPage();
List passed = frame.getByXPath("//span[contains(@class,'jasmine-passed')]");
- assertThat(passed.size(), equalTo(1));
- assertThat(frame.getByXPath("//span[contains(@class,'jasmine-failed')]").size(), equalTo(0));
- assertThat(frame.getByXPath("//span[contains(@class,'jasmine-skipped')]").size(), equalTo(0));
- assertThat(passed.get(0).asNormalizedText(), startsWith("15 specs, 0 failures"));
+ assertThat(passed.size()).isEqualTo(1);
+ assertThat(frame.getByXPath("//span[contains(@class,'jasmine-failed')]").size()).isEqualTo(0);
+ assertThat(frame.getByXPath("//span[contains(@class,'jasmine-skipped')]").size()).isEqualTo(0);
+ assertThat(passed.get(0).asNormalizedText()).startsWith("15 specs, 0 failures");
//Store Report
frame.executeJavaScript("jscoverage_report();");
diff --git a/src/test-acceptance/java/jscover/server/HtmlUnitMergeTest.java b/src/test-acceptance/java/jscover/server/HtmlUnitMergeTest.java
index d7304bae..bd32dcc9 100644
--- a/src/test-acceptance/java/jscover/server/HtmlUnitMergeTest.java
+++ b/src/test-acceptance/java/jscover/server/HtmlUnitMergeTest.java
@@ -356,9 +356,7 @@ You should also get your employer (if you work as a programmer) or your
import java.io.File;
import java.io.IOException;
-import static org.hamcrest.MatcherAssert.assertThat;
-import static org.hamcrest.Matchers.containsString;
-import static org.hamcrest.Matchers.equalTo;
+import static org.assertj.core.api.Assertions.assertThat;
import static org.junit.jupiter.api.Assertions.assertEquals;
public class HtmlUnitMergeTest {
@@ -398,8 +396,8 @@ public void shouldMergeUnloadedButtonSavedAndJSSavedReports() throws Exception {
saveReportByButton();
String json = ioUtils.toString(jsonFile);
- assertThat(json, containsString("/root.js"));
- assertThat(json, containsString("/level1/level2/level2.js"));
+ assertThat(json).contains("/root.js");
+ assertThat(json).contains("/level1/level2/level2.js");
String url = "file:///" + new File(reportDir + "/jscoverage.html").getAbsolutePath();
WebClient webClient = new WebClient();
@@ -459,13 +457,13 @@ private void storeReport(WebClient webClient, HtmlPage page) throws IOException
webClient.waitForBackgroundJavaScript(2000);
String result = page.getElementById("storeDiv").getTextContent();
- assertThat(result, containsString("Coverage data stored at " + new File(reportDir).getPath()));
+ assertThat(result).contains("Coverage data stored at " + new File(reportDir).getPath());
}
private void verifyCoverage(HtmlPage page, String uri, String linePercentage, String branchPercentage, String functionPercentage) {
- assertThat(getHtmlElement(page, "//tr[@id='row-" + uri + "']/td[11]/span").getTextContent(), equalTo(linePercentage));
- assertThat(getHtmlElement(page, "//tr[@id='row-" + uri + "']/td[12]/span").getTextContent(), equalTo(branchPercentage));
- assertThat(getHtmlElement(page, "//tr[@id='row-" + uri + "']/td[13]/span").getTextContent(), equalTo(functionPercentage));
+ assertThat(getHtmlElement(page, "//tr[@id='row-" + uri + "']/td[11]/span").getTextContent()).isEqualTo(linePercentage);
+ assertThat(getHtmlElement(page, "//tr[@id='row-" + uri + "']/td[12]/span").getTextContent()).isEqualTo(branchPercentage);
+ assertThat(getHtmlElement(page, "//tr[@id='row-" + uri + "']/td[13]/span").getTextContent()).isEqualTo(functionPercentage);
}
private HtmlElement getHtmlElement(HtmlPage page, String xpathExpr) {
diff --git a/src/test-acceptance/java/jscover/server/HtmlUnitServerBranchAndFunctionTest.java b/src/test-acceptance/java/jscover/server/HtmlUnitServerBranchAndFunctionTest.java
index bf42bdc5..2610d6d4 100644
--- a/src/test-acceptance/java/jscover/server/HtmlUnitServerBranchAndFunctionTest.java
+++ b/src/test-acceptance/java/jscover/server/HtmlUnitServerBranchAndFunctionTest.java
@@ -353,9 +353,7 @@ You should also get your employer (if you work as a programmer) or your
import java.io.IOException;
-import static org.hamcrest.MatcherAssert.assertThat;
-import static org.hamcrest.Matchers.containsString;
-import static org.hamcrest.Matchers.equalTo;
+import static org.assertj.core.api.Assertions.assertThat;
public class HtmlUnitServerBranchAndFunctionTest extends HtmlUnitServerTestBaseClass {
private static Main main = new Main();
@@ -447,22 +445,22 @@ public void shouldDisplayCoverageInformationOnSourcePage() throws IOException {
}
private void verifySource(HtmlTable sourceTable, int row, int coverageCount, String source, String alertLine, String cssClass) throws IOException {
- assertThat(sourceTable.getRow(row).getCell(1).asNormalizedText(), equalTo(""+coverageCount));
- assertThat(sourceTable.getRow(row).getCell(3).asNormalizedText(), equalTo(source));
+ assertThat(sourceTable.getRow(row).getCell(1).asNormalizedText()).isEqualTo(""+coverageCount);
+ assertThat(sourceTable.getRow(row).getCell(3).asNormalizedText()).isEqualTo(source);
HtmlTableCell branchCell = sourceTable.getRow(row).getCell(2);
if (alertLine == null) {
- assertThat(branchCell.asNormalizedText(), equalTo(" "));
- assertThat(branchCell.getAttribute("class"), equalTo("numeric "+cssClass));
+ assertThat(branchCell.asNormalizedText()).isEqualTo(" ");
+ assertThat(branchCell.getAttribute("class")).isEqualTo("numeric "+cssClass);
} else {
- assertThat(branchCell.asNormalizedText(), equalTo("info"));
+ assertThat(branchCell.asNormalizedText()).isEqualTo("info");
HtmlAnchor anchor = (HtmlAnchor) branchCell.getFirstChild().getFirstChild();
final String alert[] = new String[1];
webClient.setAlertHandler((page, message) -> alert[0] = message);
anchor.click();
- assertThat(alert[0], containsString(alertLine));
+ assertThat(alert[0]).contains(alertLine);
}
}
}
diff --git a/src/test-acceptance/java/jscover/server/HtmlUnitServerTestBaseClass.java b/src/test-acceptance/java/jscover/server/HtmlUnitServerTestBaseClass.java
index 71c9fabe..0cab49e4 100644
--- a/src/test-acceptance/java/jscover/server/HtmlUnitServerTestBaseClass.java
+++ b/src/test-acceptance/java/jscover/server/HtmlUnitServerTestBaseClass.java
@@ -13,9 +13,7 @@
import java.io.File;
import java.io.IOException;
-import static org.hamcrest.MatcherAssert.assertThat;
-import static org.hamcrest.Matchers.containsString;
-import static org.hamcrest.Matchers.equalTo;
+import static org.assertj.core.api.Assertions.assertThat;
import static org.junit.jupiter.api.Assertions.assertEquals;
public abstract class HtmlUnitServerTestBaseClass {
@@ -36,7 +34,7 @@ public void setUp() {
@Test
public void shouldNotInstrument() throws Exception {
Page page = webClient.getPage("http://localhost:9001/example/lib/noInstrument.js");
- assertThat(page.getWebResponse().getContentAsString(), equalTo("alert('Hey');"));
+ assertThat(page.getWebResponse().getContentAsString()).isEqualTo("alert('Hey');");
}
@Test
@@ -108,8 +106,8 @@ public void shouldDisplayCoverageInformationOnSourcePage() throws IOException {
}
private void verifySource(HtmlTable sourceTable, int row, int coverageCount, String source) {
- assertThat(sourceTable.getRow(row).getCell(1).asNormalizedText(), equalTo(""+coverageCount));
- assertThat(sourceTable.getRow(row).getCell(2).asNormalizedText(), equalTo(source));
+ assertThat(sourceTable.getRow(row).getCell(1).asNormalizedText()).isEqualTo(""+coverageCount);
+ assertThat(sourceTable.getRow(row).getCell(2).asNormalizedText()).isEqualTo(source);
}
@Test
@@ -133,10 +131,10 @@ protected void testStoreAndLoadResult(int branchPercentage, int functionPercenta
webClient.waitForBackgroundJavaScript(2000);
String result = page.getElementById("storeDiv").getTextContent();
- assertThat(result, containsString("Coverage data stored at target"));
+ assertThat(result).contains("Coverage data stored at target");
String json = ioUtils.toString(jsonFile);
- assertThat(json, containsString("/script.js"));
+ assertThat(json).contains("/script.js");
page = webClient.getPage("file:///"+ new File(getReportDir()+"/jscoverage.html").getAbsolutePath());
verifyTotal(webClient, page, 89, branchPercentage, functionPercentage);
@@ -160,7 +158,7 @@ public void shouldStoreResultViaJavaScriptCall() throws Exception {
webClient.waitForBackgroundJavaScript(2000);
String json = ioUtils.toString(jsonFile);
- assertThat(json, containsString("/script.js"));
+ assertThat(json).contains("/script.js");
page = webClient.getPage("file:///"+ new File(getReportDir()+"/directory/jscoverage.html").getAbsolutePath());
verifyTotal(webClient, page, 15);
@@ -178,7 +176,7 @@ public void shouldStoreResultViaJavaScriptCallWithoutUI() throws Exception {
webClient.waitForBackgroundJavaScript(2000);
String json = ioUtils.toString(jsonFile);
- assertThat(json, containsString("/script.js"));
+ assertThat(json).contains("/script.js");
page = webClient.getPage("file:///"+ new File(getReportDir()+"/directory-no-ui/jscoverage.html").getAbsolutePath());
verifyTotal(webClient, page, 15);
@@ -196,7 +194,7 @@ public void shouldStoreResultViaJavaScriptCallWithoutUIAsync() throws Exception
webClient.waitForBackgroundJavaScript(100);
String json = ioUtils.toString(jsonFile);
- assertThat(json, containsString("/script.js"));
+ assertThat(json).contains("/script.js");
page = webClient.getPage("file:///"+ new File(getReportDir()+"/directory-no-ui-cb/jscoverage.html").getAbsolutePath());
verifyTotal(webClient, page, 15);
@@ -280,7 +278,7 @@ public void shouldWorkWithPost() throws Exception {
page = page.getHtmlElementById("submitButton").click();
String data = page.getHtmlElementById("postData").getTextContent();
- assertThat(data, equalTo("inputName=POST+data%21%21%21"));
+ assertThat(data).isEqualTo("inputName=POST+data%21%21%21");
}
@Test
@@ -300,7 +298,7 @@ public void shouldWorkWithLargeUpload() throws Exception {
page = page.getHtmlElementById("submitButton").click();
String data = page.getHtmlElementById("postData").getTextContent();
- assertThat(data, containsString("js.jar"));
+ assertThat(data).contains("js.jar");
}
private void testFileUpload(String postFile) throws IOException {
@@ -309,7 +307,7 @@ private void testFileUpload(String postFile) throws IOException {
page = page.getHtmlElementById("submitButton").click();
String data = page.getHtmlElementById("postData").getTextContent();
- assertThat(data, containsString("Line 1\nLine 2"));
+ assertThat(data).contains("Line 1\nLine 2");
}
protected void verifyTotal(WebClient webClient, HtmlPage page, int percentage) throws IOException {
diff --git a/src/test-acceptance/java/jscover/server/WebDaemonTest.java b/src/test-acceptance/java/jscover/server/WebDaemonTest.java
index a8fca2d0..32482e43 100644
--- a/src/test-acceptance/java/jscover/server/WebDaemonTest.java
+++ b/src/test-acceptance/java/jscover/server/WebDaemonTest.java
@@ -6,8 +6,7 @@
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
-import static org.hamcrest.MatcherAssert.assertThat;
-import static org.hamcrest.Matchers.equalTo;
+import static org.assertj.core.api.Assertions.assertThat;
public class WebDaemonTest {
private Thread server;
@@ -30,9 +29,9 @@ public void setUp() throws InterruptedException {
@Test
public void shouldStopDaemon() throws Exception {
HtmlPage page = webClient.getPage("http://localhost:8081/jscoverage.html");
- assertThat(page.getTitleText(), equalTo("JSCover"));
+ assertThat(page.getTitleText()).isEqualTo("JSCover");
main.stop();
server.join(1000);
- assertThat(server.getState(), equalTo(Thread.State.TERMINATED));
+ assertThat(server.getState()).isEqualTo(Thread.State.TERMINATED);
}
}
\ No newline at end of file
diff --git a/src/test-acceptance/java/jscover/ui/HtmlUnitUITest.java b/src/test-acceptance/java/jscover/ui/HtmlUnitUITest.java
index e5b90f87..2b101fc4 100644
--- a/src/test-acceptance/java/jscover/ui/HtmlUnitUITest.java
+++ b/src/test-acceptance/java/jscover/ui/HtmlUnitUITest.java
@@ -345,8 +345,6 @@ You should also get your employer (if you work as a programmer) or your
import jscover.Main;
import jscover.util.ReflectionUtils;
import org.apache.commons.io.FileUtils;
-import org.hamcrest.Description;
-import org.hamcrest.TypeSafeMatcher;
import org.htmlunit.WebClient;
import org.htmlunit.html.HtmlPage;
import org.htmlunit.html.HtmlTableRow;
@@ -358,11 +356,11 @@ You should also get your employer (if you work as a programmer) or your
import java.io.File;
import java.io.IOException;
import java.util.*;
+import java.util.function.Predicate;
import static jscover.ui.HTMLCoverageData.byName;
import static jscover.ui.HTMLCoverageData.parse;
-import static org.hamcrest.MatcherAssert.assertThat;
-import static org.hamcrest.Matchers.*;
+import static org.assertj.core.api.Assertions.assertThat;
public class HtmlUnitUITest {
private static Thread server;
@@ -426,7 +424,7 @@ private static void storeResult() throws IOException {
webClient.waitForBackgroundJavaScript(2000);
String result = page.getElementById("storeDiv").getTextContent();
- assertThat(result, containsString("Coverage data stored at target"));
+ assertThat(result).contains("Coverage data stored at target");
}
@Test
@@ -443,10 +441,10 @@ public void shouldSortFilesByName() throws IOException {
}
private void verifyScriptMatchesRow(HTMLCoverageData data, HtmlTableRow row) {
- assertThat(data.getName(), equalTo(row.getCell(0).asNormalizedText()));
- assertThat(data.getLineCoverage(), equalTo(row.getCell(10).asNormalizedText()));
- assertThat(data.getBranchCoverage(), equalTo(row.getCell(11).asNormalizedText()));
- assertThat(data.getFunctionCoverage(), equalTo(row.getCell(12).asNormalizedText()));
+ assertThat(data.getName()).isEqualTo(row.getCell(0).asNormalizedText());
+ assertThat(data.getLineCoverage()).isEqualTo(row.getCell(10).asNormalizedText());
+ assertThat(data.getBranchCoverage()).isEqualTo(row.getCell(11).asNormalizedText());
+ assertThat(data.getFunctionCoverage()).isEqualTo(row.getCell(12).asNormalizedText());
}
@Test
@@ -474,17 +472,17 @@ private void sortByField(HtmlPage page, String field) throws IOException {
HtmlTableRow htmlTableRow = (HtmlTableRow) page.getByXPath("//tbody[@id='summaryTbody']/tr[" + (i + 1) + "]").get(0);
currentValue = verifyRow(field, currentValue, matched, htmlTableRow);
}
- assertThat(matched[0], equalTo(data.size()));
+ assertThat(matched[0]).isEqualTo(data.size());
}
private int verifyRow(String field, int currentValue, int[] matched, HtmlTableRow htmlTableRow) {
final String path = htmlTableRow.getCell(0).asNormalizedText();
int value = parse(htmlTableRow.getCell(ReportField.getField(field).index).asNormalizedText());
- assertThat(value, greaterThanOrEqualTo(currentValue));
+ assertThat(value).isGreaterThanOrEqualTo(currentValue);
currentValue = value;
List list = dataMap.get(value);
- assertThat(list, notNullValue());
- assertThat(list, hasItem(getTypeSafeMatcher(matched, path)));
+ assertThat(list).isNotNull();
+ assertThat(list).anyMatch(getCoveragePredicate(matched, path));
return currentValue;
}
@@ -500,19 +498,13 @@ private void populateDataMap(String field) {
}
}
- private TypeSafeMatcher getTypeSafeMatcher(final int[] matched, final String path) {
- return new TypeSafeMatcher() {
- @Override
- protected boolean matchesSafely(HTMLCoverageData htmlCoverageData) {
- boolean equals = htmlCoverageData.getName().equals(path);
- if (equals)
- matched[0]++;
- return equals;
- }
-
- public void describeTo(Description description) {
-
+ private Predicate getCoveragePredicate(final int[] matched, final String path) {
+ return data -> {
+ boolean equals = data.getName().equals(path);
+ if (equals) {
+ matched[0]++;
}
+ return equals;
};
}
}
diff --git a/src/test-acceptance/java/jscover/util/ClassVersionChecker.java b/src/test-acceptance/java/jscover/util/ClassVersionChecker.java
index 5bccf624..4867a945 100644
--- a/src/test-acceptance/java/jscover/util/ClassVersionChecker.java
+++ b/src/test-acceptance/java/jscover/util/ClassVersionChecker.java
@@ -8,8 +8,7 @@
import java.util.zip.ZipEntry;
import java.util.zip.ZipInputStream;
-import static org.hamcrest.MatcherAssert.assertThat;
-import static org.hamcrest.Matchers.equalTo;
+import static org.assertj.core.api.Assertions.assertThat;
public class ClassVersionChecker {
@Test
@@ -36,6 +35,6 @@ private static void checkClassVersion2(File file) throws IOException {
int majorVersion = buffer[6] << 8 | buffer[7];
//int minorVersion = buffer[4] << 8 | buffer[5];
- assertThat(file + " is not a 1.8 class! Major version " + majorVersion, majorVersion, equalTo(65));
+ assertThat(majorVersion).isEqualTo(65).overridingErrorMessage(file + " is not a 1.8 class! Major version " + majorVersion);
}
}
diff --git a/src/test-integration/java/jscover/filesystem/FileSystemInstrumenterIntegrationTest.java b/src/test-integration/java/jscover/filesystem/FileSystemInstrumenterIntegrationTest.java
index f10b8952..318af6fa 100644
--- a/src/test-integration/java/jscover/filesystem/FileSystemInstrumenterIntegrationTest.java
+++ b/src/test-integration/java/jscover/filesystem/FileSystemInstrumenterIntegrationTest.java
@@ -11,10 +11,7 @@
import java.util.Properties;
import java.util.SortedMap;
-import static org.hamcrest.CoreMatchers.equalTo;
-import static org.hamcrest.CoreMatchers.nullValue;
-import static org.hamcrest.MatcherAssert.assertThat;
-import static org.hamcrest.Matchers.is;
+import static org.assertj.core.api.Assertions.assertThat;
public class FileSystemInstrumenterIntegrationTest {
private FileSystemInstrumenter fileSystemInstrumenter = new FileSystemInstrumenter();
@@ -44,21 +41,21 @@ public void shouldGenerateEmptyCoverageDataFile() {
String json = ioUtils.loadFromFileSystem(new File(destDir, "jscoverage.json"));
SortedMap map = jsonMerger.jsonToMap(json);
- assertThat(map.keySet().size(), equalTo(6));
- assertThat(map.containsKey("/root.js"), is(true));
- assertThat(map.containsKey("/root-empty.js"), is(true));
- assertThat(map.containsKey("/level1/level1.js"), is(true));
- assertThat(map.containsKey("/level1/level2/level2-empty.js"), is(true));
- assertThat(map.containsKey("/level1/level2/level2.js"), is(true));
- assertThat(map.containsKey("/noInstrument/noInstrument.js"), is(true));
+ assertThat(map.keySet().size()).isEqualTo(6);
+ assertThat(map.containsKey("/root.js")).isTrue();
+ assertThat(map.containsKey("/root-empty.js")).isTrue();
+ assertThat(map.containsKey("/level1/level1.js")).isTrue();
+ assertThat(map.containsKey("/level1/level2/level2-empty.js")).isTrue();
+ assertThat(map.containsKey("/level1/level2/level2.js")).isTrue();
+ assertThat(map.containsKey("/noInstrument/noInstrument.js")).isTrue();
FileData fileData = map.get("/level1/level1.js");
- assertThat(fileData.getLines().size(), equalTo(5));
- assertThat(fileData.getLines().get(0), nullValue());
- assertThat(fileData.getLines().get(1), equalTo(0));
- assertThat(fileData.getLines().get(2), equalTo(0));
- assertThat(fileData.getLines().get(3), equalTo(0));
- assertThat(fileData.getLines().get(4), equalTo(0));
+ assertThat(fileData.getLines().size()).isEqualTo(5);
+ assertThat(fileData.getLines().get(0)).isNull();
+ assertThat(fileData.getLines().get(1)).isEqualTo(0);
+ assertThat(fileData.getLines().get(2)).isEqualTo(0);
+ assertThat(fileData.getLines().get(3)).isEqualTo(0);
+ assertThat(fileData.getLines().get(4)).isEqualTo(0);
}
@Test
@@ -73,20 +70,20 @@ public void shouldGenerateEmptyCoverageDataFileWithExclusions() {
String json = ioUtils.loadFromFileSystem(new File(destDir, "jscoverage.json"));
SortedMap map = jsonMerger.jsonToMap(json);
- assertThat(map.keySet().size(), equalTo(3));
- assertThat(map.containsKey("/root.js"), is(true));
- assertThat(map.containsKey("/root-empty.js"), is(true));
- assertThat(map.containsKey("/level1/level1.js"), is(true));
- assertThat(map.containsKey("/level1/level2/level2-empty.js"), is(false));
- assertThat(map.containsKey("/level1/level2/level2.js"), is(false));
- assertThat(map.containsKey("/noInstrument/noInstrument.js"), is(false));
+ assertThat(map.keySet().size()).isEqualTo(3);
+ assertThat(map.containsKey("/root.js")).isTrue();
+ assertThat(map.containsKey("/root-empty.js")).isTrue();
+ assertThat(map.containsKey("/level1/level1.js")).isTrue();
+ assertThat(map.containsKey("/level1/level2/level2-empty.js")).isFalse();
+ assertThat(map.containsKey("/level1/level2/level2.js")).isFalse();
+ assertThat(map.containsKey("/noInstrument/noInstrument.js")).isFalse();
FileData fileData = map.get("/level1/level1.js");
- assertThat(fileData.getLines().size(), equalTo(5));
- assertThat(fileData.getLines().get(0), nullValue());
- assertThat(fileData.getLines().get(1), equalTo(0));
- assertThat(fileData.getLines().get(2), equalTo(0));
- assertThat(fileData.getLines().get(3), equalTo(0));
- assertThat(fileData.getLines().get(4), equalTo(0));
+ assertThat(fileData.getLines().size()).isEqualTo(5);
+ assertThat(fileData.getLines().get(0)).isNull();
+ assertThat(fileData.getLines().get(1)).isEqualTo(0);
+ assertThat(fileData.getLines().get(2)).isEqualTo(0);
+ assertThat(fileData.getLines().get(3)).isEqualTo(0);
+ assertThat(fileData.getLines().get(4)).isEqualTo(0);
}
}
diff --git a/src/test-integration/java/jscover/instrument/BranchInstrumentorIntegrationTest.java b/src/test-integration/java/jscover/instrument/BranchInstrumentorIntegrationTest.java
index dd877600..0d94db45 100644
--- a/src/test-integration/java/jscover/instrument/BranchInstrumentorIntegrationTest.java
+++ b/src/test-integration/java/jscover/instrument/BranchInstrumentorIntegrationTest.java
@@ -348,8 +348,7 @@ You should also get your employer (if you work as a programmer) or your
import org.junit.jupiter.api.Test;
import org.mozilla.javascript.*;
-import static org.hamcrest.MatcherAssert.assertThat;
-import static org.hamcrest.Matchers.equalTo;
+import static org.assertj.core.api.Assertions.assertThat;
public class BranchInstrumentorIntegrationTest {
private static IoUtils ioUtils = IoUtils.getInstance();
@@ -372,21 +371,21 @@ public void shouldHandleSingleCondition() {
Function coveredFn = (Function) ScriptableObject.getProperty(coverageData, "covered");
Function testFn = (Function) scope.get("test", scope);
- assertThat(coverageData.get("evalTrue", coverageData), equalTo(0));
- assertThat(coverageData.get("evalFalse", coverageData), equalTo(0));
- assertThat(coverageData.get("position", coverageData), equalTo(6));
- assertThat(coverageData.get("nodeLength", coverageData), equalTo(5));
- assertThat(coveredFn.call(context, scope, coverageData, new Object[0]), equalTo(false));
+ assertThat(coverageData.get("evalTrue", coverageData)).isEqualTo(0);
+ assertThat(coverageData.get("evalFalse", coverageData)).isEqualTo(0);
+ assertThat(coverageData.get("position", coverageData)).isEqualTo(6);
+ assertThat(coverageData.get("nodeLength", coverageData)).isEqualTo(5);
+ assertThat(coveredFn.call(context, scope, coverageData, new Object[0])).isEqualTo(false);
testFn.call(context, scope, null, new Object[]{-1});
- assertThat(coverageData.get("evalTrue", coverageData), equalTo(1));
- assertThat(coverageData.get("evalFalse", coverageData), equalTo(0));
- assertThat(coveredFn.call(context, scope, coverageData, new Object[0]), equalTo(false));
+ assertThat(coverageData.get("evalTrue", coverageData)).isEqualTo(1);
+ assertThat(coverageData.get("evalFalse", coverageData)).isEqualTo(0);
+ assertThat(coveredFn.call(context, scope, coverageData, new Object[0])).isEqualTo(false);
testFn.call(context, scope, null, new Object[]{1});
- assertThat(coverageData.get("evalTrue", coverageData), equalTo(1));
- assertThat(coverageData.get("evalFalse", coverageData), equalTo(1));
- assertThat(coveredFn.call(context, scope, coverageData, new Object[0]), equalTo(true));
+ assertThat(coverageData.get("evalTrue", coverageData)).isEqualTo(1);
+ assertThat(coverageData.get("evalFalse", coverageData)).isEqualTo(1);
+ assertThat(coveredFn.call(context, scope, coverageData, new Object[0])).isEqualTo(true);
}
@Test
@@ -397,8 +396,8 @@ public void shouldWrapReturnCondition() {
script.append("test(1);");
runScript(script.toString(), false);
Scriptable coverageData = getCoverageData(scope, "test.js", 2, 1);
- assertThat(coverageData.get("evalTrue", coverageData), equalTo(1));
- assertThat(coverageData.get("evalFalse", coverageData), equalTo(0));
+ assertThat(coverageData.get("evalTrue", coverageData)).isEqualTo(1);
+ assertThat(coverageData.get("evalFalse", coverageData)).isEqualTo(0);
}
@Test
@@ -406,8 +405,8 @@ public void shouldWrapArrayLiteralCondition() {
StringBuilder script = new StringBuilder("var x = [ 1 || 0];\n");
runScript(script.toString(), false);
Scriptable coverageData = getCoverageData(scope, "test.js", 1, 1);
- assertThat(coverageData.get("evalTrue", coverageData), equalTo(1));
- assertThat(coverageData.get("evalFalse", coverageData), equalTo(0));
+ assertThat(coverageData.get("evalTrue", coverageData)).isEqualTo(1);
+ assertThat(coverageData.get("evalFalse", coverageData)).isEqualTo(0);
}
@Test
@@ -415,15 +414,15 @@ public void shouldWrapCoalesce() {
StringBuilder script = new StringBuilder("function test(a) {\n var x = a || {};\n }\ntest();");
runScript(script.toString(), false);
Scriptable coverageData = getCoverageData(scope, "test.js", 2, 1);
- assertThat(coverageData.get("evalTrue", coverageData), equalTo(1));
- assertThat(coverageData.get("evalFalse", coverageData), equalTo(0));
+ assertThat(coverageData.get("evalTrue", coverageData)).isEqualTo(1);
+ assertThat(coverageData.get("evalFalse", coverageData)).isEqualTo(0);
}
@Test
public void shouldNotWrapCoalesceIfConfiguredNotTo() {
String source = "function test(a) {\n var x = a || {};\n }\ntest();";
runScript(source, true);
- assertThat(getBranchData(scope, "test.js").size(), equalTo(0));
+ assertThat(getBranchData(scope, "test.js").size()).isEqualTo(0);
}
@Test
@@ -431,8 +430,8 @@ public void shouldWrapNonCoalesce() {
String source = "function test(a) {\n var x = a > 7;\n }\ntest(3);";
runScript(source, true);
Scriptable coverageData = getCoverageData(scope, "test.js", 2, 1);
- assertThat(coverageData.get("evalTrue", coverageData), equalTo(0));
- assertThat(coverageData.get("evalFalse", coverageData), equalTo(1));
+ assertThat(coverageData.get("evalTrue", coverageData)).isEqualTo(0);
+ assertThat(coverageData.get("evalFalse", coverageData)).isEqualTo(1);
}
@Test
@@ -442,8 +441,8 @@ public void shouldWrapGetterCondition() {
script.append("var x = y[prop || 'a'];");
runScript(script.toString(), false);
Scriptable coverageData = getCoverageData(scope, "test.js", 3, 1);
- assertThat(coverageData.get("evalTrue", coverageData), equalTo(1));
- assertThat(coverageData.get("evalFalse", coverageData), equalTo(0));
+ assertThat(coverageData.get("evalTrue", coverageData)).isEqualTo(1);
+ assertThat(coverageData.get("evalFalse", coverageData)).isEqualTo(0);
}
@Test
@@ -454,8 +453,8 @@ public void shouldWrapExpressionCondition() {
script.append("test();\n");
runScript(script.toString(), false);
Scriptable coverageData = getCoverageData(scope, "test.js", 2, 1);
- assertThat(coverageData.get("evalTrue", coverageData), equalTo(0));
- assertThat(coverageData.get("evalFalse", coverageData), equalTo(1));
+ assertThat(coverageData.get("evalTrue", coverageData)).isEqualTo(0);
+ assertThat(coverageData.get("evalFalse", coverageData)).isEqualTo(1);
}
@Test
@@ -464,8 +463,8 @@ public void shouldWrapAssignmentCondition() {
script.append("x = x === undefined;\n");
runScript(script.toString(), false);
Scriptable coverageData = getCoverageData(scope, "test.js", 2, 1);
- assertThat(coverageData.get("evalTrue", coverageData), equalTo(0));
- assertThat(coverageData.get("evalFalse", coverageData), equalTo(1));
+ assertThat(coverageData.get("evalTrue", coverageData)).isEqualTo(0);
+ assertThat(coverageData.get("evalFalse", coverageData)).isEqualTo(1);
}
@Test
@@ -475,8 +474,8 @@ public void shouldWrapIfCondition() {
script.append(" x--;\n");
runScript(script.toString(), false);
Scriptable coverageData = getCoverageData(scope, "test.js", 2, 1);
- assertThat(coverageData.get("evalTrue", coverageData), equalTo(1));
- assertThat(coverageData.get("evalFalse", coverageData), equalTo(0));
+ assertThat(coverageData.get("evalTrue", coverageData)).isEqualTo(1);
+ assertThat(coverageData.get("evalFalse", coverageData)).isEqualTo(0);
}
@Test
@@ -486,8 +485,8 @@ public void shouldWrapIfConditionVariable() {
script.append(" x = false;\n");
runScript(script.toString(), false);
Scriptable coverageData = getCoverageData(scope, "test.js", 2, 1);
- assertThat(coverageData.get("evalTrue", coverageData), equalTo(1));
- assertThat(coverageData.get("evalFalse", coverageData), equalTo(0));
+ assertThat(coverageData.get("evalTrue", coverageData)).isEqualTo(1);
+ assertThat(coverageData.get("evalFalse", coverageData)).isEqualTo(0);
}
@Test
@@ -497,8 +496,8 @@ public void shouldWrapWhileCondition() {
script.append(" x--;\n");
runScript(script.toString(), false);
Scriptable coverageData = getCoverageData(scope, "test.js", 2, 1);
- assertThat(coverageData.get("evalTrue", coverageData), equalTo(1));
- assertThat(coverageData.get("evalFalse", coverageData), equalTo(1));
+ assertThat(coverageData.get("evalTrue", coverageData)).isEqualTo(1);
+ assertThat(coverageData.get("evalFalse", coverageData)).isEqualTo(1);
}
@Test
@@ -508,8 +507,8 @@ public void shouldWrapWhileConditionVariable() {
script.append(" x = false;\n");
runScript(script.toString(), false);
Scriptable coverageData = getCoverageData(scope, "test.js", 2, 1);
- assertThat(coverageData.get("evalTrue", coverageData), equalTo(1));
- assertThat(coverageData.get("evalFalse", coverageData), equalTo(1));
+ assertThat(coverageData.get("evalTrue", coverageData)).isEqualTo(1);
+ assertThat(coverageData.get("evalFalse", coverageData)).isEqualTo(1);
}
@Test
@@ -518,8 +517,8 @@ public void shouldNotBreakCommaCondition() {
script.append(" ;\n");
runScript(script.toString(), false);
Scriptable coverageData = getCoverageData(scope, "test.js", 1, 1);
- assertThat(coverageData.get("evalTrue", coverageData), equalTo(0));
- assertThat(coverageData.get("evalFalse", coverageData), equalTo(1));
+ assertThat(coverageData.get("evalTrue", coverageData)).isEqualTo(0);
+ assertThat(coverageData.get("evalFalse", coverageData)).isEqualTo(1);
}
@Test
@@ -528,8 +527,8 @@ public void shouldNotBreakCommaCondition2() {
script.append(" ;\n");
runScript(script.toString(), false);
Scriptable coverageData = getCoverageData(scope, "test.js", 1, 1);
- assertThat(coverageData.get("evalTrue", coverageData), equalTo(1));
- assertThat(coverageData.get("evalFalse", coverageData), equalTo(0));
+ assertThat(coverageData.get("evalTrue", coverageData)).isEqualTo(1);
+ assertThat(coverageData.get("evalFalse", coverageData)).isEqualTo(0);
}
@Test
@@ -540,8 +539,8 @@ public void shouldWrapDoCondition() {
script.append("while (x > 0)\n");
runScript(script.toString(), false);
Scriptable coverageData = getCoverageData(scope, "test.js", 4, 1);
- assertThat(coverageData.get("evalTrue", coverageData), equalTo(0));
- assertThat(coverageData.get("evalFalse", coverageData), equalTo(1));
+ assertThat(coverageData.get("evalTrue", coverageData)).isEqualTo(0);
+ assertThat(coverageData.get("evalFalse", coverageData)).isEqualTo(1);
}
@Test
@@ -552,8 +551,8 @@ public void shouldWrapDoConditionVariable() {
script.append("while (x)\n");
runScript(script.toString(), false);
Scriptable coverageData = getCoverageData(scope, "test.js", 4, 1);
- assertThat(coverageData.get("evalTrue", coverageData), equalTo(0));
- assertThat(coverageData.get("evalFalse", coverageData), equalTo(1));
+ assertThat(coverageData.get("evalTrue", coverageData)).isEqualTo(0);
+ assertThat(coverageData.get("evalFalse", coverageData)).isEqualTo(1);
}
@Test
@@ -564,8 +563,8 @@ public void shouldWrapSwitchCondition() {
script.append("}\n");
runScript(script.toString(), false);
Scriptable coverageData = getCoverageData(scope, "test.js", 1, 1);
- assertThat(coverageData.get("evalTrue", coverageData), equalTo(1));
- assertThat(coverageData.get("evalFalse", coverageData), equalTo(0));
+ assertThat(coverageData.get("evalTrue", coverageData)).isEqualTo(1);
+ assertThat(coverageData.get("evalFalse", coverageData)).isEqualTo(0);
}
@Test
@@ -574,8 +573,8 @@ public void shouldWrapForCondition() {
script.append(" ;\n");
runScript(script.toString(), false);
Scriptable coverageData = getCoverageData(scope, "test.js", 1, 1);
- assertThat(coverageData.get("evalTrue", coverageData), equalTo(1));
- assertThat(coverageData.get("evalFalse", coverageData), equalTo(1));
+ assertThat(coverageData.get("evalTrue", coverageData)).isEqualTo(1);
+ assertThat(coverageData.get("evalFalse", coverageData)).isEqualTo(1);
}
@Test
@@ -583,7 +582,7 @@ public void shouldNotWrapInfiniteForCondition() {
StringBuilder script = new StringBuilder("for (;;)\n");
script.append(" break;\n");
runScript(script.toString(), false);
- assertThat(getBranchData(scope, "test.js").size(), equalTo(0));
+ assertThat(getBranchData(scope, "test.js").size()).isEqualTo(0);
}
@Test
@@ -593,8 +592,8 @@ public void shouldWrapForConditionVariable() {
script.append(" x = false;\n");
runScript(script.toString(), false);
Scriptable coverageData = getCoverageData(scope, "test.js", 2, 1);
- assertThat(coverageData.get("evalTrue", coverageData), equalTo(1));
- assertThat(coverageData.get("evalFalse", coverageData), equalTo(1));
+ assertThat(coverageData.get("evalTrue", coverageData)).isEqualTo(1);
+ assertThat(coverageData.get("evalFalse", coverageData)).isEqualTo(1);
}
@Test
@@ -603,8 +602,8 @@ public void shouldWrapTernaryCondition() {
script.append("var y = x > 0 ? 1 : 0;\n");
runScript(script.toString(), false);
Scriptable coverageData = getCoverageData(scope, "test.js", 2, 1);
- assertThat(coverageData.get("evalTrue", coverageData), equalTo(1));
- assertThat(coverageData.get("evalFalse", coverageData), equalTo(0));
+ assertThat(coverageData.get("evalTrue", coverageData)).isEqualTo(1);
+ assertThat(coverageData.get("evalFalse", coverageData)).isEqualTo(0);
}
@Test
@@ -613,8 +612,8 @@ public void shouldWrapTernaryConditionWithParentheses() {
script.append("var y = (x > 0) ? 1 : 0;\n");
runScript(script.toString(), false);
Scriptable coverageData = getCoverageData(scope, "test.js", 2, 1);
- assertThat(coverageData.get("evalTrue", coverageData), equalTo(1));
- assertThat(coverageData.get("evalFalse", coverageData), equalTo(0));
+ assertThat(coverageData.get("evalTrue", coverageData)).isEqualTo(1);
+ assertThat(coverageData.get("evalFalse", coverageData)).isEqualTo(0);
}
@Test
@@ -623,8 +622,8 @@ public void shouldWrapTernaryConditionVariable() {
script.append("var x = y ? 1 : 2;\n");
runScript(script.toString(), false);
Scriptable coverageData = getCoverageData(scope, "test.js", 2, 1);
- assertThat(coverageData.get("evalTrue", coverageData), equalTo(1));
- assertThat(coverageData.get("evalFalse", coverageData), equalTo(0));
+ assertThat(coverageData.get("evalTrue", coverageData)).isEqualTo(1);
+ assertThat(coverageData.get("evalFalse", coverageData)).isEqualTo(0);
}
@Test
@@ -633,8 +632,8 @@ public void shouldWrapTernaryConditionParentheses() {
script.append("var x = (y) ? 1 : 2;\n");
runScript(script.toString(), false);
Scriptable coverageData = getCoverageData(scope, "test.js", 2, 1);
- assertThat(coverageData.get("evalTrue", coverageData), equalTo(1));
- assertThat(coverageData.get("evalFalse", coverageData), equalTo(0));
+ assertThat(coverageData.get("evalTrue", coverageData)).isEqualTo(1);
+ assertThat(coverageData.get("evalFalse", coverageData)).isEqualTo(0);
}
@Test
@@ -643,14 +642,14 @@ public void shouldWrapTernaryConditionArgument() {
script.append("var y = x > 0 ? x > 100 : x < 100;\n");
runScript(script.toString(), false);
Scriptable coverageData1 = getCoverageData(scope, "test.js", 2, 1);
- assertThat(coverageData1.get("evalTrue", coverageData1), equalTo(1));
- assertThat(coverageData1.get("evalFalse", coverageData1), equalTo(0));
+ assertThat(coverageData1.get("evalTrue", coverageData1)).isEqualTo(1);
+ assertThat(coverageData1.get("evalFalse", coverageData1)).isEqualTo(0);
Scriptable coverageData2 = getCoverageData(scope, "test.js", 2, 2);
- assertThat(coverageData2.get("evalTrue", coverageData2), equalTo(0));
- assertThat(coverageData2.get("evalFalse", coverageData2), equalTo(1));
+ assertThat(coverageData2.get("evalTrue", coverageData2)).isEqualTo(0);
+ assertThat(coverageData2.get("evalFalse", coverageData2)).isEqualTo(1);
Scriptable coverageData3 = getCoverageData(scope, "test.js", 2, 3);
- assertThat(coverageData3.get("evalTrue", coverageData3), equalTo(0));
- assertThat(coverageData3.get("evalFalse", coverageData3), equalTo(0));
+ assertThat(coverageData3.get("evalTrue", coverageData3)).isEqualTo(0);
+ assertThat(coverageData3.get("evalFalse", coverageData3)).isEqualTo(0);
}
@Test
@@ -659,8 +658,8 @@ public void shouldWrapFunctionCallCondition() {
script.append("test(0, 1 > 0);\n");
runScript(script.toString(), false);
Scriptable coverageData = getCoverageData(scope, "test.js", 2, 1);
- assertThat(coverageData.get("evalTrue", coverageData), equalTo(1));
- assertThat(coverageData.get("evalFalse", coverageData), equalTo(0));
+ assertThat(coverageData.get("evalTrue", coverageData)).isEqualTo(1);
+ assertThat(coverageData.get("evalFalse", coverageData)).isEqualTo(0);
}
@Test
@@ -672,8 +671,8 @@ public void shouldWrapNotOperatorCondition() {
script.append("test(true);\n");
runScript(script.toString(), false);
Scriptable coverageData = getCoverageData(scope, "test.js", 2, 1);
- assertThat(coverageData.get("evalTrue", coverageData), equalTo(0));
- assertThat(coverageData.get("evalFalse", coverageData), equalTo(1));
+ assertThat(coverageData.get("evalTrue", coverageData)).isEqualTo(0);
+ assertThat(coverageData.get("evalFalse", coverageData)).isEqualTo(1);
}
@Test
@@ -682,8 +681,8 @@ public void shouldWrapFunctionCallConditionAsFirstArgument() {
script.append("test(1 > 0, 0);\n");
runScript(script.toString(), false);
Scriptable coverageData = getCoverageData(scope, "test.js", 2, 1);
- assertThat(coverageData.get("evalTrue", coverageData), equalTo(1));
- assertThat(coverageData.get("evalFalse", coverageData), equalTo(0));
+ assertThat(coverageData.get("evalTrue", coverageData)).isEqualTo(1);
+ assertThat(coverageData.get("evalFalse", coverageData)).isEqualTo(0);
}
@Test
@@ -701,20 +700,20 @@ public void shouldHandleTwoSeparateConditions() {
Function coveredFn2 = (Function) ScriptableObject.getProperty(coverageData2, "covered");
Function testFn = (Function) scope.get("test", scope);
- assertThat(coveredFn1.call(context, scope, coverageData1, new Object[0]), equalTo(false));
- assertThat(coveredFn2.call(context, scope, coverageData2, new Object[0]), equalTo(false));
+ assertThat(coveredFn1.call(context, scope, coverageData1, new Object[0])).isEqualTo(false);
+ assertThat(coveredFn2.call(context, scope, coverageData2, new Object[0])).isEqualTo(false);
testFn.call(context, scope, null, new Object[]{-1});
- assertThat(coveredFn1.call(context, scope, coverageData1, new Object[0]), equalTo(false));
- assertThat(coveredFn2.call(context, scope, coverageData2, new Object[0]), equalTo(false));
+ assertThat(coveredFn1.call(context, scope, coverageData1, new Object[0])).isEqualTo(false);
+ assertThat(coveredFn2.call(context, scope, coverageData2, new Object[0])).isEqualTo(false);
testFn.call(context, scope, null, new Object[]{1});
- assertThat(coveredFn1.call(context, scope, coverageData1, new Object[0]), equalTo(true));
- assertThat(coveredFn2.call(context, scope, coverageData2, new Object[0]), equalTo(false));
+ assertThat(coveredFn1.call(context, scope, coverageData1, new Object[0])).isEqualTo(true);
+ assertThat(coveredFn2.call(context, scope, coverageData2, new Object[0])).isEqualTo(false);
testFn.call(context, scope, null, new Object[]{1000});
- assertThat(coveredFn1.call(context, scope, coverageData1, new Object[0]), equalTo(true));
- assertThat(coveredFn2.call(context, scope, coverageData2, new Object[0]), equalTo(true));
+ assertThat(coveredFn1.call(context, scope, coverageData1, new Object[0])).isEqualTo(true);
+ assertThat(coveredFn2.call(context, scope, coverageData2, new Object[0])).isEqualTo(true);
}
@Test
@@ -733,24 +732,24 @@ public void shouldWrapOr() {
Function coveredFn2 = (Function) ScriptableObject.getProperty(coverageData2, "covered");
Function coveredFn3 = (Function) ScriptableObject.getProperty(coverageData3, "covered");
- assertThat(coveredFn1.call(context, scope, coverageData1, new Object[0]), equalTo(false));
- assertThat(coveredFn2.call(context, scope, coverageData2, new Object[0]), equalTo(false));
- assertThat(coveredFn3.call(context, scope, coverageData3, new Object[0]), equalTo(false));
+ assertThat(coveredFn1.call(context, scope, coverageData1, new Object[0])).isEqualTo(false);
+ assertThat(coveredFn2.call(context, scope, coverageData2, new Object[0])).isEqualTo(false);
+ assertThat(coveredFn3.call(context, scope, coverageData3, new Object[0])).isEqualTo(false);
testFn.call(context, scope, null, new Object[]{-1, -1});
- assertThat(coveredFn1.call(context, scope, coverageData1, new Object[0]), equalTo(false));
- assertThat(coveredFn2.call(context, scope, coverageData2, new Object[0]), equalTo(false));
- assertThat(coveredFn3.call(context, scope, coverageData3, new Object[0]), equalTo(false));
+ assertThat(coveredFn1.call(context, scope, coverageData1, new Object[0])).isEqualTo(false);
+ assertThat(coveredFn2.call(context, scope, coverageData2, new Object[0])).isEqualTo(false);
+ assertThat(coveredFn3.call(context, scope, coverageData3, new Object[0])).isEqualTo(false);
testFn.call(context, scope, null, new Object[]{1, -1});
- assertThat(coveredFn1.call(context, scope, coverageData1, new Object[0]), equalTo(false));
- assertThat(coveredFn2.call(context, scope, coverageData2, new Object[0]), equalTo(true));
- assertThat(coveredFn3.call(context, scope, coverageData3, new Object[0]), equalTo(false));
+ assertThat(coveredFn1.call(context, scope, coverageData1, new Object[0])).isEqualTo(false);
+ assertThat(coveredFn2.call(context, scope, coverageData2, new Object[0])).isEqualTo(true);
+ assertThat(coveredFn3.call(context, scope, coverageData3, new Object[0])).isEqualTo(false);
testFn.call(context, scope, null, new Object[]{1, 1});
- assertThat(coveredFn1.call(context, scope, coverageData1, new Object[0]), equalTo(true));
- assertThat(coveredFn2.call(context, scope, coverageData2, new Object[0]), equalTo(true));
- assertThat(coveredFn3.call(context, scope, coverageData3, new Object[0]), equalTo(true));
+ assertThat(coveredFn1.call(context, scope, coverageData1, new Object[0])).isEqualTo(true);
+ assertThat(coveredFn2.call(context, scope, coverageData2, new Object[0])).isEqualTo(true);
+ assertThat(coveredFn3.call(context, scope, coverageData3, new Object[0])).isEqualTo(true);
}
@Test
@@ -766,16 +765,16 @@ public void shouldWrapNot() throws Exception {
Function coveredFn2 = (Function) ScriptableObject.getProperty(coverageData2, "covered");
Function testFn = (Function) scope.get("test", scope);
- assertThat(coveredFn1.call(context, scope, coverageData1, new Object[0]), equalTo(false));
- assertThat(coveredFn2.call(context, scope, coverageData2, new Object[0]), equalTo(false));
+ assertThat(coveredFn1.call(context, scope, coverageData1, new Object[0])).isEqualTo(false);
+ assertThat(coveredFn2.call(context, scope, coverageData2, new Object[0])).isEqualTo(false);
testFn.call(context, scope, null, new Object[]{-1});
- assertThat(coveredFn1.call(context, scope, coverageData1, new Object[0]), equalTo(false));
- assertThat(coveredFn2.call(context, scope, coverageData2, new Object[0]), equalTo(false));
+ assertThat(coveredFn1.call(context, scope, coverageData1, new Object[0])).isEqualTo(false);
+ assertThat(coveredFn2.call(context, scope, coverageData2, new Object[0])).isEqualTo(false);
testFn.call(context, scope, null, new Object[]{1});
- assertThat(coveredFn1.call(context, scope, coverageData1, new Object[0]), equalTo(true));
- assertThat(coveredFn2.call(context, scope, coverageData2, new Object[0]), equalTo(true));
+ assertThat(coveredFn1.call(context, scope, coverageData1, new Object[0])).isEqualTo(true);
+ assertThat(coveredFn2.call(context, scope, coverageData2, new Object[0])).isEqualTo(true);
}
@Test
@@ -785,8 +784,8 @@ public void shouldWrapStringKeyCondition() {
script.append("};\n");
runScript(script.toString(), false);
Scriptable coverageData1 = getCoverageData(scope, "test.js", 2, 1);
- assertThat(coverageData1.get("evalTrue", coverageData1), equalTo(1));
- assertThat(coverageData1.get("evalFalse", coverageData1), equalTo(0));
+ assertThat(coverageData1.get("evalTrue", coverageData1)).isEqualTo(1);
+ assertThat(coverageData1.get("evalFalse", coverageData1)).isEqualTo(0);
}
@Test
@@ -817,24 +816,24 @@ private void testNestedScript(StringBuilder script) {
Function coveredFn3 = (Function) ScriptableObject.getProperty(coverageData3, "covered");
Function testFn = (Function) scope.get("test", scope);
- assertThat(coveredFn1.call(context, scope, coverageData1, new Object[0]), equalTo(false));
- assertThat(coveredFn2.call(context, scope, coverageData2, new Object[0]), equalTo(false));
- assertThat(coveredFn2.call(context, scope, coverageData3, new Object[0]), equalTo(false));
+ assertThat(coveredFn1.call(context, scope, coverageData1, new Object[0])).isEqualTo(false);
+ assertThat(coveredFn2.call(context, scope, coverageData2, new Object[0])).isEqualTo(false);
+ assertThat(coveredFn2.call(context, scope, coverageData3, new Object[0])).isEqualTo(false);
testFn.call(context, scope, null, new Object[]{-1, -1});
- assertThat(coveredFn1.call(context, scope, coverageData1, new Object[0]), equalTo(false));
- assertThat(coveredFn2.call(context, scope, coverageData2, new Object[0]), equalTo(false));
- assertThat(coveredFn3.call(context, scope, coverageData3, new Object[0]), equalTo(false));
+ assertThat(coveredFn1.call(context, scope, coverageData1, new Object[0])).isEqualTo(false);
+ assertThat(coveredFn2.call(context, scope, coverageData2, new Object[0])).isEqualTo(false);
+ assertThat(coveredFn3.call(context, scope, coverageData3, new Object[0])).isEqualTo(false);
testFn.call(context, scope, null, new Object[]{1, -1});
- assertThat(coveredFn1.call(context, scope, coverageData1, new Object[0]), equalTo(true));
- assertThat(coveredFn2.call(context, scope, coverageData2, new Object[0]), equalTo(true));
- assertThat(coveredFn3.call(context, scope, coverageData3, new Object[0]), equalTo(false));
+ assertThat(coveredFn1.call(context, scope, coverageData1, new Object[0])).isEqualTo(true);
+ assertThat(coveredFn2.call(context, scope, coverageData2, new Object[0])).isEqualTo(true);
+ assertThat(coveredFn3.call(context, scope, coverageData3, new Object[0])).isEqualTo(false);
testFn.call(context, scope, null, new Object[]{-1, 1});
- assertThat(coveredFn1.call(context, scope, coverageData1, new Object[0]), equalTo(true));
- assertThat(coveredFn2.call(context, scope, coverageData2, new Object[0]), equalTo(true));
- assertThat(coveredFn3.call(context, scope, coverageData3, new Object[0]), equalTo(true));
+ assertThat(coveredFn1.call(context, scope, coverageData1, new Object[0])).isEqualTo(true);
+ assertThat(coveredFn2.call(context, scope, coverageData2, new Object[0])).isEqualTo(true);
+ assertThat(coveredFn3.call(context, scope, coverageData3, new Object[0])).isEqualTo(true);
}
@Test
@@ -844,8 +843,8 @@ public void shouldHandleFunctionAsIfConditions() {
script.append(" ;\n");
runScript(script.toString(), false);
Scriptable coverageData = getCoverageData(scope, "test.js", 2, 1);
- assertThat(coverageData.get("evalTrue", coverageData), equalTo(1));
- assertThat(coverageData.get("evalFalse", coverageData), equalTo(0));
+ assertThat(coverageData.get("evalTrue", coverageData)).isEqualTo(1);
+ assertThat(coverageData.get("evalFalse", coverageData)).isEqualTo(0);
}
@Test
@@ -859,21 +858,21 @@ public void shouldHandleVariableAsIfConditions() {
Function coveredFn = (Function) ScriptableObject.getProperty(coverageData, "covered");
Function testFn = (Function) scope.get("test", scope);
- assertThat(coverageData.get("evalTrue", coverageData), equalTo(0));
- assertThat(coverageData.get("evalFalse", coverageData), equalTo(0));
- assertThat(coverageData.get("position", coverageData), equalTo(6));
- assertThat(coverageData.get("nodeLength", coverageData), equalTo(1));
- assertThat(coveredFn.call(context, scope, coverageData, new Object[0]), equalTo(false));
+ assertThat(coverageData.get("evalTrue", coverageData)).isEqualTo(0);
+ assertThat(coverageData.get("evalFalse", coverageData)).isEqualTo(0);
+ assertThat(coverageData.get("position", coverageData)).isEqualTo(6);
+ assertThat(coverageData.get("nodeLength", coverageData)).isEqualTo(1);
+ assertThat(coveredFn.call(context, scope, coverageData, new Object[0])).isEqualTo(false);
testFn.call(context, scope, null, new Object[]{true});
- assertThat(coverageData.get("evalTrue", coverageData), equalTo(1));
- assertThat(coverageData.get("evalFalse", coverageData), equalTo(0));
- assertThat(coveredFn.call(context, scope, coverageData, new Object[0]), equalTo(false));
+ assertThat(coverageData.get("evalTrue", coverageData)).isEqualTo(1);
+ assertThat(coverageData.get("evalFalse", coverageData)).isEqualTo(0);
+ assertThat(coveredFn.call(context, scope, coverageData, new Object[0])).isEqualTo(false);
testFn.call(context, scope, null, new Object[]{false});
- assertThat(coverageData.get("evalTrue", coverageData), equalTo(1));
- assertThat(coverageData.get("evalFalse", coverageData), equalTo(1));
- assertThat(coveredFn.call(context, scope, coverageData, new Object[0]), equalTo(true));
+ assertThat(coverageData.get("evalTrue", coverageData)).isEqualTo(1);
+ assertThat(coverageData.get("evalFalse", coverageData)).isEqualTo(1);
+ assertThat(coveredFn.call(context, scope, coverageData, new Object[0])).isEqualTo(true);
}
@Test
@@ -887,21 +886,21 @@ public void shouldHandleVariableInitializer() {
Function coveredFn = (Function) ScriptableObject.getProperty(coverageData, "covered");
Function testFn = (Function) scope.get("test", scope);
- assertThat(coverageData.get("evalTrue", coverageData), equalTo(0));
- assertThat(coverageData.get("evalFalse", coverageData), equalTo(0));
- assertThat(coverageData.get("position", coverageData), equalTo(10));
- assertThat(coverageData.get("nodeLength", coverageData), equalTo(5));
- assertThat(coveredFn.call(context, scope, coverageData, new Object[0]), equalTo(false));
+ assertThat(coverageData.get("evalTrue", coverageData)).isEqualTo(0);
+ assertThat(coverageData.get("evalFalse", coverageData)).isEqualTo(0);
+ assertThat(coverageData.get("position", coverageData)).isEqualTo(10);
+ assertThat(coverageData.get("nodeLength", coverageData)).isEqualTo(5);
+ assertThat(coveredFn.call(context, scope, coverageData, new Object[0])).isEqualTo(false);
testFn.call(context, scope, null, new Object[]{-1});
- assertThat(coverageData.get("evalTrue", coverageData), equalTo(1));
- assertThat(coverageData.get("evalFalse", coverageData), equalTo(0));
- assertThat(coveredFn.call(context, scope, coverageData, new Object[0]), equalTo(false));
+ assertThat(coverageData.get("evalTrue", coverageData)).isEqualTo(1);
+ assertThat(coverageData.get("evalFalse", coverageData)).isEqualTo(0);
+ assertThat(coveredFn.call(context, scope, coverageData, new Object[0])).isEqualTo(false);
testFn.call(context, scope, null, new Object[]{1});
- assertThat(coverageData.get("evalTrue", coverageData), equalTo(1));
- assertThat(coverageData.get("evalFalse", coverageData), equalTo(1));
- assertThat(coveredFn.call(context, scope, coverageData, new Object[0]), equalTo(true));
+ assertThat(coverageData.get("evalTrue", coverageData)).isEqualTo(1);
+ assertThat(coverageData.get("evalFalse", coverageData)).isEqualTo(1);
+ assertThat(coveredFn.call(context, scope, coverageData, new Object[0])).isEqualTo(true);
}
private Scriptable getCoverageData(Scriptable scope, String uri, int lineNo, int conditionNo) {
diff --git a/src/test-integration/java/jscover/instrument/InMemoryCoverageTest.java b/src/test-integration/java/jscover/instrument/InMemoryCoverageTest.java
index d2e3f60a..1257d7f8 100644
--- a/src/test-integration/java/jscover/instrument/InMemoryCoverageTest.java
+++ b/src/test-integration/java/jscover/instrument/InMemoryCoverageTest.java
@@ -342,7 +342,6 @@ You should also get your employer (if you work as a programmer) or your
package jscover.instrument;
-
import com.google.javascript.jscomp.CompilerOptions;
import jscover.ConfigurationCommon;
import org.junit.jupiter.api.Disabled;
@@ -352,10 +351,7 @@ You should also get your employer (if you work as a programmer) or your
import org.mockito.junit.jupiter.MockitoExtension;
import org.mozilla.javascript.*;
-import static org.hamcrest.MatcherAssert.assertThat;
-import static org.hamcrest.Matchers.equalTo;
-import static org.hamcrest.Matchers.nullValue;
-import static org.hamcrest.core.Is.is;
+import static org.assertj.core.api.Assertions.assertThat;
import static org.mockito.BDDMockito.given;
@ExtendWith(MockitoExtension.class)
@@ -369,7 +365,7 @@ public void shouldExecuteJS() {
Scriptable scope = cx.initStandardObjects();
String source = "function isNegative(x) {\n if (x>=0)\n return false;\n else\n return true;\n}; isNegative(12);";
Object result = cx.evaluateString(scope, source, "inMemory.js", 1, null);
- assertThat(result, is(false));
+ assertThat(result).isEqualTo(Boolean.FALSE);
}
@Test
@@ -384,7 +380,7 @@ public void shouldExecuteInstrumentedJS() {
Object expected = cx.evaluateString(scope, source, "inMemory.js", 1, null);
Object actual = cx.evaluateString(scope, instrumentedJS, "inMemory.js", 1, null);
- assertThat(actual, equalTo(expected));
+ assertThat(actual).isEqualTo(expected);
}
@Test
@@ -425,9 +421,9 @@ public void shouldPrintLineCoverage() {
private void verifyLineCount(NativeArray array, Integer line, Double count) {
if (count == null)
- assertThat(array.get(line), nullValue());
+ assertThat(array.get(line)).isNull();
else
- assertThat(array.get(line), equalTo(count));
+ assertThat(array.get(line)).isEqualTo(count);
}
@Override
diff --git a/src/test-integration/java/jscover/instrument/InstrumenterIntegrationTest.java b/src/test-integration/java/jscover/instrument/InstrumenterIntegrationTest.java
index bc581c06..7aef4ed0 100644
--- a/src/test-integration/java/jscover/instrument/InstrumenterIntegrationTest.java
+++ b/src/test-integration/java/jscover/instrument/InstrumenterIntegrationTest.java
@@ -376,7 +376,7 @@ public void shouldInstrumentForFileSystem() {
String instrumentedSource = instrumenter.processSourceForFileSystem();
String expectedSource = ioUtils.loadFromClassPath("/test-instrumented-file-system.js");
- // assertThat(instrumentedSource, equalTo(expectedSource));
+ // assertThat(instrumentedSource).isEqualTo(expectedSource);
//ioUtils.copy(instrumentedSource, new File("src/test-integration/resources/test-instrumented-file-system.js"));
assertEquals(expectedSource.replaceAll("\r\n","\n"), instrumentedSource.replaceAll("\r\n","\n"));
}
@@ -390,7 +390,7 @@ public void shouldInstrumentForServer() {
String instrumentedSource = instrumenter.processSourceForServer();
String expectedSource = ioUtils.loadFromClassPath("/test-instrumented-server.js");
- // assertThat(instrumentedSource, equalTo(expectedSource));
+ // assertThat(instrumentedSource).isEqualTo(expectedSource);
//ioUtils.copy(instrumentedSource, new File("src/test-integration/resources/test-instrumented-server.js"));
assertEquals(expectedSource.replaceAll("\r\n","\n"), instrumentedSource.replaceAll("\r\n","\n"));
}
diff --git a/src/test-integration/java/jscover/report/coberturaxml/CoberturaXmlGeneratorIntegrationTest.java b/src/test-integration/java/jscover/report/coberturaxml/CoberturaXmlGeneratorIntegrationTest.java
index fa3ed71d..4658d768 100644
--- a/src/test-integration/java/jscover/report/coberturaxml/CoberturaXmlGeneratorIntegrationTest.java
+++ b/src/test-integration/java/jscover/report/coberturaxml/CoberturaXmlGeneratorIntegrationTest.java
@@ -356,9 +356,7 @@ You should also get your employer (if you work as a programmer) or your
import java.io.File;
import java.io.IOException;
-import static org.hamcrest.MatcherAssert.assertThat;
-import static org.hamcrest.Matchers.equalTo;
-import static org.hamcrest.Matchers.notNullValue;
+import static org.assertj.core.api.Assertions.assertThat;
import static org.junit.jupiter.api.Assertions.assertThrows;
public class CoberturaXmlGeneratorIntegrationTest {
@@ -412,56 +410,56 @@ public void shouldGenerateXml() throws Exception {
//IoUtils.getInstance().copy(xml, new File("cobertura-coverage.xml"));
//Check summary
- assertThat(getXPath(xpath, document, "/coverage/@complexity"), equalTo("0"));
- assertThat(getXPath(xpath, document, "/coverage/@line-rate"), equalTo("0.5301349726045703"));
- assertThat(getXPath(xpath, document, "/coverage/@branch-rate"), equalTo("0.34330143540669855"));
- assertThat(getXPath(xpath, document, "/coverage/@lines-covered"), equalTo("3967"));
- assertThat(getXPath(xpath, document, "/coverage/@lines-valid"), equalTo("7483"));
- assertThat(getXPath(xpath, document, "/coverage/@branches-covered"), equalTo("2009"));
- assertThat(getXPath(xpath, document, "/coverage/@branches-valid"), equalTo("5852"));
- assertThat(getXPath(xpath, document, "/coverage/@version"), equalTo("theVersion"));
- assertThat(getXPath(xpath, document, "/coverage/@timestamp"), notNullValue());
+ assertThat(getXPath(xpath, document, "/coverage/@complexity")).isEqualTo("0");
+ assertThat(getXPath(xpath, document, "/coverage/@line-rate")).isEqualTo("0.5301349726045703");
+ assertThat(getXPath(xpath, document, "/coverage/@branch-rate")).isEqualTo("0.34330143540669855");
+ assertThat(getXPath(xpath, document, "/coverage/@lines-covered")).isEqualTo("3967");
+ assertThat(getXPath(xpath, document, "/coverage/@lines-valid")).isEqualTo("7483");
+ assertThat(getXPath(xpath, document, "/coverage/@branches-covered")).isEqualTo("2009");
+ assertThat(getXPath(xpath, document, "/coverage/@branches-valid")).isEqualTo("5852");
+ assertThat(getXPath(xpath, document, "/coverage/@version")).isEqualTo("theVersion");
+ assertThat(getXPath(xpath, document, "/coverage/@timestamp")).isNotNull();
//Check summary
- assertThat(getXPath(xpath, document, "/coverage/sources/source"), equalTo("c:/sourceDir"));
+ assertThat(getXPath(xpath, document, "/coverage/sources/source")).isEqualTo("c:/sourceDir");
//Check package
- assertThat(getXPath(xpath, document, "count(/coverage/packages/package)"), equalTo("42"));
+ assertThat(getXPath(xpath, document, "count(/coverage/packages/package)")).isEqualTo("42");
String packageXPath = "/coverage/packages/package[@name='/build/yui']";
- assertThat(getXPath(xpath, document, packageXPath + "/@name"), equalTo("/build/yui"));
- assertThat(getXPath(xpath, document, packageXPath + "/@complexity"), equalTo("0"));
- assertThat(getXPath(xpath, document, packageXPath + "/@line-rate"), equalTo("0.5865470852017938"));
- assertThat(getXPath(xpath, document, packageXPath + "/@branch-rate"), equalTo("0.3797235023041475"));
+ assertThat(getXPath(xpath, document, packageXPath + "/@name")).isEqualTo("/build/yui");
+ assertThat(getXPath(xpath, document, packageXPath + "/@complexity")).isEqualTo("0");
+ assertThat(getXPath(xpath, document, packageXPath + "/@line-rate")).isEqualTo("0.5865470852017938");
+ assertThat(getXPath(xpath, document, packageXPath + "/@branch-rate")).isEqualTo("0.3797235023041475");
//Check class
String classXPath = packageXPath + "/classes/class[@name='/build/yui/yui.js']";
- assertThat(getXPath(xpath, document, classXPath + "/@branch-rate"), equalTo("0.3797235023041475"));
- assertThat(getXPath(xpath, document, classXPath + "/@line-rate"), equalTo("0.5865470852017938"));
- assertThat(getXPath(xpath, document, classXPath + "/@complexity"), equalTo("0"));
- assertThat(getXPath(xpath, document, classXPath + "/@filename"), equalTo("build/yui/yui.js"));
+ assertThat(getXPath(xpath, document, classXPath + "/@branch-rate")).isEqualTo("0.3797235023041475");
+ assertThat(getXPath(xpath, document, classXPath + "/@line-rate")).isEqualTo("0.5865470852017938");
+ assertThat(getXPath(xpath, document, classXPath + "/@complexity")).isEqualTo("0");
+ assertThat(getXPath(xpath, document, classXPath + "/@filename")).isEqualTo("build/yui/yui.js");
//Check line
String lineXPath = classXPath + "/lines/line[@number='10']";
- assertThat(getXPath(xpath, document, lineXPath + "/@hits"), equalTo("1"));
- assertThat(getXPath(xpath, document, lineXPath + "/@condition-coverage"), equalTo("50% (1/2)"));
- assertThat(getXPath(xpath, document, lineXPath + "/@branch"), equalTo("true"));
+ assertThat(getXPath(xpath, document, lineXPath + "/@hits")).isEqualTo("1");
+ assertThat(getXPath(xpath, document, lineXPath + "/@condition-coverage")).isEqualTo("50% (1/2)");
+ assertThat(getXPath(xpath, document, lineXPath + "/@branch")).isEqualTo("true");
//Check line with zero hits
String lineZeroHitsXPath = classXPath + "/lines/line[@number='11']";
- assertThat(getXPath(xpath, document, lineZeroHitsXPath + "/@hits"), equalTo("0"));
+ assertThat(getXPath(xpath, document, lineZeroHitsXPath + "/@hits")).isEqualTo("0");
//Check line 62, branch data with branch hit but no line hit
String branchXPath = classXPath + "/lines/line[@number='62']";
- assertThat(getXPath(xpath, document, branchXPath + "/@hits"), equalTo("1"));
- assertThat(getXPath(xpath, document, branchXPath + "/@condition-coverage"), equalTo("50% (2/4)"));
+ assertThat(getXPath(xpath, document, branchXPath + "/@hits")).isEqualTo("1");
+ assertThat(getXPath(xpath, document, branchXPath + "/@condition-coverage")).isEqualTo("50% (2/4)");
//Check line 4393, branch data with no branch hit or line hit
String branchUnHitXPath = classXPath + "/lines/line[@number='4393']";
- assertThat(getXPath(xpath, document, branchUnHitXPath + "/@hits"), equalTo("0"));
- assertThat(getXPath(xpath, document, branchUnHitXPath + "/@condition-coverage"), equalTo("0% (0/2)"));
+ assertThat(getXPath(xpath, document, branchUnHitXPath + "/@hits")).isEqualTo("0");
+ assertThat(getXPath(xpath, document, branchUnHitXPath + "/@condition-coverage")).isEqualTo("0% (0/2)");
//Check condition
String conditionXPath = lineXPath + "/conditions/condition[@number='1']";
- assertThat(getXPath(xpath, document, conditionXPath + "/@coverage"), equalTo("50%"));
- assertThat(getXPath(xpath, document, conditionXPath + "/@type"), equalTo("jump"));
+ assertThat(getXPath(xpath, document, conditionXPath + "/@coverage")).isEqualTo("50%");
+ assertThat(getXPath(xpath, document, conditionXPath + "/@type")).isEqualTo("jump");
}
private Document parseXml(String xml) throws ParserConfigurationException, SAXException, IOException {
diff --git a/src/test-integration/java/jscover/report/lcov/LCovGeneratorIntegrationTest.java b/src/test-integration/java/jscover/report/lcov/LCovGeneratorIntegrationTest.java
index e2cd72b4..6a600b1e 100644
--- a/src/test-integration/java/jscover/report/lcov/LCovGeneratorIntegrationTest.java
+++ b/src/test-integration/java/jscover/report/lcov/LCovGeneratorIntegrationTest.java
@@ -352,8 +352,7 @@ You should also get your employer (if you work as a programmer) or your
import java.io.File;
import java.util.SortedMap;
-import static org.hamcrest.CoreMatchers.equalTo;
-import static org.hamcrest.MatcherAssert.assertThat;
+import static org.assertj.core.api.Assertions.assertThat;
public class LCovGeneratorIntegrationTest {
private LCovGenerator lCovGenerator = new LCovGenerator();
@@ -418,6 +417,6 @@ public void shouldGenerateLCovDataFromJSON() throws Exception {
"DA:24,2\n" +
"DA:25,2\n" +
"end_of_record\n";
- assertThat(result, equalTo(expected));
+ assertThat(result).isEqualTo(expected);
}
}
diff --git a/src/test-integration/java/jscover/report/xml/XMLSummaryIntegrationTest.java b/src/test-integration/java/jscover/report/xml/XMLSummaryIntegrationTest.java
index 3b845252..15dbc5ea 100644
--- a/src/test-integration/java/jscover/report/xml/XMLSummaryIntegrationTest.java
+++ b/src/test-integration/java/jscover/report/xml/XMLSummaryIntegrationTest.java
@@ -358,8 +358,7 @@ You should also get your employer (if you work as a programmer) or your
import java.io.File;
import java.util.Locale;
-import static org.hamcrest.CoreMatchers.equalTo;
-import static org.hamcrest.MatcherAssert.assertThat;
+import static org.assertj.core.api.Assertions.assertThat;
public class XMLSummaryIntegrationTest {
private XMLSummary xmlSummary = new XMLSummary();
@@ -386,13 +385,13 @@ public void shouldCalculateXmlSummaryForYUI3() throws Exception {
DocumentBuilder builder = DocumentBuilderFactory.newInstance().newDocumentBuilder();
Document document = builder.parse(dest);
- assertThat(getXPath(xpath, document, "/coverage/@line-rate"), equalTo("0.530135"));
- assertThat(getXPath(xpath, document, "/coverage/@branch-rate"), equalTo("0.343301"));
- assertThat(getXPath(xpath, document, "/coverage/@lines-covered"), equalTo("3967"));
- assertThat(getXPath(xpath, document, "/coverage/@lines"), equalTo("7483"));
- assertThat(getXPath(xpath, document, "/coverage/@branches-covered"), equalTo("2009"));
- assertThat(getXPath(xpath, document, "/coverage/@branches"), equalTo("5852"));
- assertThat(getXPath(xpath, document, "/coverage/@version"), equalTo("theVersion"));
+ assertThat(getXPath(xpath, document, "/coverage/@line-rate")).isEqualTo("0.530135");
+ assertThat(getXPath(xpath, document, "/coverage/@branch-rate")).isEqualTo("0.343301");
+ assertThat(getXPath(xpath, document, "/coverage/@lines-covered")).isEqualTo("3967");
+ assertThat(getXPath(xpath, document, "/coverage/@lines")).isEqualTo("7483");
+ assertThat(getXPath(xpath, document, "/coverage/@branches-covered")).isEqualTo("2009");
+ assertThat(getXPath(xpath, document, "/coverage/@branches")).isEqualTo("5852");
+ assertThat(getXPath(xpath, document, "/coverage/@version")).isEqualTo("theVersion");
}
private String getXPath(XPath xpath, Document document, String expression) throws Exception {
diff --git a/src/test-integration/java/jscover/util/IoUtilsIntegrationTest.java b/src/test-integration/java/jscover/util/IoUtilsIntegrationTest.java
index dc2eb91e..abb0ac82 100644
--- a/src/test-integration/java/jscover/util/IoUtilsIntegrationTest.java
+++ b/src/test-integration/java/jscover/util/IoUtilsIntegrationTest.java
@@ -346,8 +346,7 @@ You should also get your employer (if you work as a programmer) or your
import java.io.File;
-import static org.hamcrest.MatcherAssert.assertThat;
-import static org.hamcrest.Matchers.equalTo;
+import static org.assertj.core.api.Assertions.assertThat;
public class IoUtilsIntegrationTest {
IoUtils ioUtils = IoUtils.getInstance();
@@ -365,6 +364,6 @@ public void shouldCopyDir() {
private void verifyFilesTheSame(String path, File src, File dest) {
String data1 = ioUtils.loadFromFileSystem(new File(src, path));
String data2 = ioUtils.loadFromFileSystem(new File(dest, path));
- assertThat(data2, equalTo(data1));
+ assertThat(data2).isEqualTo(data1);
}
}
diff --git a/src/test/java/jscover/ConfigurationCommonTest.java b/src/test/java/jscover/ConfigurationCommonTest.java
index 818f66f6..300a96b6 100644
--- a/src/test/java/jscover/ConfigurationCommonTest.java
+++ b/src/test/java/jscover/ConfigurationCommonTest.java
@@ -345,8 +345,7 @@ You should also get your employer (if you work as a programmer) or your
import com.google.javascript.jscomp.CompilerOptions;
import org.junit.jupiter.api.Test;
-import static org.hamcrest.MatcherAssert.assertThat;
-import static org.hamcrest.Matchers.is;
+import static org.assertj.core.api.Assertions.assertThat;
import static org.junit.jupiter.api.Assertions.assertThrows;
public class ConfigurationCommonTest {
@@ -354,13 +353,13 @@ public class ConfigurationCommonTest {
@Test
public void shouldHaveDefaults() {
- assertThat(config.getECMAVersion(), is(CompilerOptions.LanguageMode.ECMASCRIPT_NEXT));
- assertThat(config.isIncludeUnloadedJS(), is(false));
- assertThat(config.isIncludeBranch(), is(true));
- assertThat(config.isIncludeFunction(), is(true));
- assertThat(config.isLocalStorage(), is(false));
- assertThat(config.isolateBrowser(), is(false));
- assertThat(config.isDetectCoalesce(), is(false));
+ assertThat(config.getECMAVersion()).isEqualTo(CompilerOptions.LanguageMode.ECMASCRIPT_NEXT);
+ assertThat(config.isIncludeUnloadedJS()).isFalse();
+ assertThat(config.isIncludeBranch()).isTrue();
+ assertThat(config.isIncludeFunction()).isTrue();
+ assertThat(config.isLocalStorage()).isFalse();
+ assertThat(config.isolateBrowser()).isFalse();
+ assertThat(config.isDetectCoalesce()).isFalse();
}
@Test
@@ -373,31 +372,31 @@ public void shouldSetValues() {
config.setIsolateBrowser(true);
config.setDetectCoalesce(true);
- assertThat(config.getECMAVersion(), is(CompilerOptions.LanguageMode.ECMASCRIPT3));
- assertThat(config.isIncludeUnloadedJS(), is(true));
- assertThat(config.isIncludeBranch(), is(false));
- assertThat(config.isIncludeFunction(), is(false));
- assertThat(config.isLocalStorage(), is(true));
- assertThat(config.isolateBrowser(), is(true));
- assertThat(config.isDetectCoalesce(), is(true));
+ assertThat(config.getECMAVersion()).isEqualTo(CompilerOptions.LanguageMode.ECMASCRIPT3);
+ assertThat(config.isIncludeUnloadedJS()).isTrue();
+ assertThat(config.isIncludeBranch()).isFalse();
+ assertThat(config.isIncludeFunction()).isFalse();
+ assertThat(config.isLocalStorage()).isTrue();
+ assertThat(config.isolateBrowser()).isTrue();
+ assertThat(config.isDetectCoalesce()).isTrue();
}
@Test
public void shouldParseIncludedUnloadedJS() {
- assertThat(config.parseArg("--include-unloaded-js"), is(true));
- assertThat(config.isIncludeUnloadedJS(), is(true));
+ assertThat(config.parseArg("--include-unloaded-js")).isTrue();
+ assertThat(config.isIncludeUnloadedJS()).isTrue();
}
@Test
public void shouldParseLocalStorage() {
- assertThat(config.parseArg("--local-storage"), is(true));
- assertThat(config.isLocalStorage(), is(true));
+ assertThat(config.parseArg("--local-storage")).isTrue();
+ assertThat(config.isLocalStorage()).isTrue();
}
@Test
public void shouldParseIsolateBrowser() {
- assertThat(config.parseArg("--isolate-browser"), is(true));
- assertThat(config.isolateBrowser(), is(true));
+ assertThat(config.parseArg("--isolate-browser")).isTrue();
+ assertThat(config.isolateBrowser()).isTrue();
}
@Test
@@ -414,7 +413,7 @@ public void shouldNotCombineLocalStorageAndIsolateBrowser() {
@Test
public void shouldParseDetectCoalesce() {
- assertThat(config.parseArg("--detect-coalesce"), is(true));
- assertThat(config.isDetectCoalesce(), is(true));
+ assertThat(config.parseArg("--detect-coalesce")).isTrue();
+ assertThat(config.isDetectCoalesce()).isTrue();
}
}
diff --git a/src/test/java/jscover/MainHelperTest.java b/src/test/java/jscover/MainHelperTest.java
index 54873ef7..23084e9e 100644
--- a/src/test/java/jscover/MainHelperTest.java
+++ b/src/test/java/jscover/MainHelperTest.java
@@ -348,9 +348,7 @@ You should also get your employer (if you work as a programmer) or your
import java.util.ArrayList;
import java.util.List;
-import static org.hamcrest.MatcherAssert.assertThat;
-import static org.hamcrest.Matchers.containsString;
-import static org.hamcrest.Matchers.equalTo;
+import static org.assertj.core.api.Assertions.assertThat;
import static org.junit.jupiter.api.Assertions.fail;
public class MainHelperTest {
@@ -366,8 +364,8 @@ public void shouldDetectMissingJARs() throws IOException {
fail("Should have thrown exception");
} catch(IllegalStateException e) {
String message = e.getMessage();
- assertThat(message, containsString("Ensure these JARs are in the same directory as JSCover.jar:"));
- assertThat(message, containsString("js.jar"));
+ assertThat(message).contains("Ensure these JARs are in the same directory as JSCover.jar:");
+ assertThat(message).contains("js.jar");
}
}
@@ -381,7 +379,7 @@ public void shouldDetectMissingClassPath() throws IOException {
fail("Should have thrown exception");
} catch(IllegalStateException e) {
String message = e.getMessage();
- assertThat(message, equalTo("Could not find the 'Class-Path' attribute in the manifest 'MANIFEST-NO-CLASS-PATH.MF'"));
+ assertThat(message).isEqualTo("Could not find the 'Class-Path' attribute in the manifest 'MANIFEST-NO-CLASS-PATH.MF'");
}
}
diff --git a/src/test/java/jscover/MainInstanceTest.java b/src/test/java/jscover/MainInstanceTest.java
index b8b420db..22b93f60 100644
--- a/src/test/java/jscover/MainInstanceTest.java
+++ b/src/test/java/jscover/MainInstanceTest.java
@@ -342,18 +342,13 @@ You should also get your employer (if you work as a programmer) or your
package jscover;
-import jscover.filesystem.ConfigurationForFS;
import jscover.filesystem.FileSystemInstrumenter;
import jscover.server.ConfigurationForServer;
import jscover.server.WebDaemon;
-import jscover.stdout.ConfigurationForStdOut;
import jscover.stdout.StdOutInstrumenter;
import jscover.util.IoService;
import jscover.util.IoUtils;
import jscover.util.ReflectionUtils;
-import org.hamcrest.Description;
-import org.hamcrest.Matcher;
-import org.hamcrest.TypeSafeMatcher;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
@@ -365,12 +360,9 @@ You should also get your employer (if you work as a programmer) or your
import java.util.Properties;
import static com.google.javascript.jscomp.CompilerOptions.LanguageMode.ECMASCRIPT5;
-import static org.hamcrest.CoreMatchers.equalTo;
-import static org.hamcrest.CoreMatchers.sameInstance;
-import static org.hamcrest.MatcherAssert.assertThat;
+import static org.assertj.core.api.Assertions.assertThat;
import static org.junit.jupiter.api.Assertions.fail;
import static org.mockito.Mockito.*;
-import static org.mockito.hamcrest.MockitoHamcrest.argThat;
@ExtendWith(MockitoExtension.class)
public class MainInstanceTest {
@@ -403,7 +395,7 @@ public void shouldWrapIoException() throws IOException {
try {
main.initialize();
} catch (RuntimeException e) {
- assertThat(e.getMessage(), equalTo("java.io.IOException: Ouch!"));
+ assertThat(e.getMessage()).isEqualTo("java.io.IOException: Ouch!");
}
}
@@ -447,17 +439,7 @@ public void shouldShowFileSystemHelp() {
public void shouldRunWebServer() throws IOException {
main.runMain(new String[]{"-ws", "--port=1234"});
- TypeSafeMatcher matcher = new TypeSafeMatcher<>() {
- @Override
- protected boolean matchesSafely(ConfigurationForServer item) {
- return item.getPort() == 1234;
- }
-
- public void describeTo(Description description) {
-
- }
- };
- verify(webDaemon, times(1)).start(argThat(matcher));
+ verify(webDaemon).start(argThat(item -> item.getPort() == 1234));
verifyNoInteractions(exitHelper);
}
@@ -472,17 +454,7 @@ public void shouldRunWebServerWithInvalidOptions() {
public void shouldRunFileSystem() {
main.runMain(new String[]{"-fs", "--js-version=ECMASCRIPT5", "src", "dest"});
- TypeSafeMatcher matcher = new TypeSafeMatcher<>() {
- @Override
- protected boolean matchesSafely(ConfigurationForFS item) {
- return item.getECMAVersion() == ECMASCRIPT5;
- }
-
- public void describeTo(Description description) {
-
- }
- };
- verify(fileSystemInstrumenter, times(1)).run(argThat(matcher));
+ verify(fileSystemInstrumenter).run(argThat(item -> item.getECMAVersion() == ECMASCRIPT5));
verifyNoInteractions(exitHelper);
}
@@ -497,17 +469,7 @@ public void shouldRunFileSystemWithInvalidOptions() {
public void shouldRunStdIO() {
main.runMain(new String[]{"-io", "--js-version=ECMASCRIPT5", "doc/example/script.js"});
- TypeSafeMatcher matcher = new TypeSafeMatcher<>() {
- @Override
- protected boolean matchesSafely(ConfigurationForStdOut item) {
- return item.getECMAVersion() == ECMASCRIPT5;
- }
-
- public void describeTo(Description description) {
-
- }
- };
- verify(stdOutInstrumenter, times(1)).run(argThat(matcher));
+ verify(stdOutInstrumenter).run(argThat(item -> item.getECMAVersion() == ECMASCRIPT5));
verifyNoInteractions(exitHelper);
}
@@ -521,16 +483,25 @@ public void shouldRunStdIOWithInvalidOptions() {
@Test
public void shouldRunGenerateFiles() {
main.runMain(new String[]{"-gf", "dest"});
- verify(ioService, times(1)).generateJSCoverFilesForWebServer(argThat(getFileNameMatcher("dest")), (String) eq(properties.get("version")));
- verify(ioUtils, times(0)).copyDir(any(File.class), any(File.class));
+ verify(ioService).generateJSCoverFilesForWebServer(
+ argThat(file -> matchesFileName(file, "dest", null)),
+ eq(properties.getProperty("version"))
+ );
+ verify(ioUtils, never()).copyDir(any(File.class), any(File.class));
verifyNoInteractions(exitHelper);
}
@Test
public void shouldRunGenerateFilesWithOriginalSource() {
main.runMain(new String[]{"-gf", "src", "dest"});
- verify(ioService, times(1)).generateJSCoverFilesForWebServer(argThat(getFileNameMatcher("dest")), (String) eq(properties.get("version")));
- verify(ioUtils, times(1)).copyDir(argThat(getFileNameMatcher("src")), argThat(getFileNameMatcher(Main.reportSrcSubDir, "dest")));
+ verify(ioService).generateJSCoverFilesForWebServer(
+ argThat(file -> matchesFileName(file, "dest", null)),
+ eq((String)properties.get("version"))
+ );
+ verify(ioUtils).copyDir(
+ argThat(file -> matchesFileName(file, "src", null)),
+ argThat(file -> matchesFileName(file, Main.reportSrcSubDir, "dest"))
+ );
verifyNoInteractions(exitHelper);
}
@@ -541,22 +512,9 @@ public void shouldRunGenerateFilesWithInvalidOptions() {
verifyNoInteractions(exitHelper);
}
- public Matcher extends File> getFileNameMatcher(final String name) {
- return getFileNameMatcher(name, null);
- }
-
- public Matcher extends File> getFileNameMatcher(final String name, final String parent) {
- return new TypeSafeMatcher<>() {
- @Override
- protected boolean matchesSafely(File file) {
- return file.getName().equals(name) && (parent == null || file.getParent().equals(parent));
- }
-
- @Override
- public void describeTo(Description description) {
-
- }
- };
+ private boolean matchesFileName(File file, String name, String parent) {
+ return file.getName().equals(name) &&
+ (parent == null || file.getParent().equals(parent));
}
@Test
@@ -589,18 +547,18 @@ public void shouldReThrowWebServerException() throws IOException {
main.runMain(new String[]{"-ws", "--port=1234"});
fail("Should have thrown exception");
} catch (RuntimeException rte) {
- assertThat(rte.getCause(), sameInstance(toBeThrown));
+ assertThat(rte.getCause()).isSameAs(toBeThrown);
}
verifyNoInteractions(exitHelper);
}
@Test
public void shouldLogArguments() {
- assertThat(main.logArgs(new String[]{"a", "b"}), equalTo("a,b"));
+ assertThat(main.logArgs(new String[]{"a", "b"})).isEqualTo("a,b");
}
@Test
public void shouldGetArgsLogger() {
- assertThat(main.getArgsLogger(new String[]{"a", "b"}).toString(), equalTo("a,b"));
+ assertThat(main.getArgsLogger(new String[]{"a", "b"}).toString()).isEqualTo("a,b");
}
}
diff --git a/src/test/java/jscover/MainParsingTest.java b/src/test/java/jscover/MainParsingTest.java
index 2e124e23..7eccc07a 100644
--- a/src/test/java/jscover/MainParsingTest.java
+++ b/src/test/java/jscover/MainParsingTest.java
@@ -344,9 +344,7 @@ You should also get your employer (if you work as a programmer) or your
import org.junit.jupiter.api.Test;
-import static org.hamcrest.MatcherAssert.assertThat;
-import static org.hamcrest.Matchers.containsString;
-import static org.hamcrest.Matchers.equalTo;
+import static org.assertj.core.api.Assertions.assertThat;
public class MainParsingTest {
private Main main = new Main();
@@ -354,73 +352,73 @@ public class MainParsingTest {
@Test
public void shouldHaveDefaults() {
- assertThat(main.getExitStatus(), equalTo(0));
+ assertThat(main.getExitStatus()).isEqualTo(0);
main.parse(new String[]{});
- assertThat(main.showHelp(), equalTo(true));
- assertThat(main.printVersion(), equalTo(false));
- assertThat(main.isServer(), equalTo(false));
- assertThat(main.isFileSystem(), equalTo(false));
- assertThat(main.showCharSets(), equalTo(false));
- assertThat(main.isRegExpTest(), equalTo(false));
- assertThat(main.isGenerateFiles(), equalTo(false));
+ assertThat(main.showHelp()).isEqualTo(true);
+ assertThat(main.printVersion()).isEqualTo(false);
+ assertThat(main.isServer()).isEqualTo(false);
+ assertThat(main.isFileSystem()).isEqualTo(false);
+ assertThat(main.showCharSets()).isEqualTo(false);
+ assertThat(main.isRegExpTest()).isEqualTo(false);
+ assertThat(main.isGenerateFiles()).isEqualTo(false);
}
@Test
public void shouldParseVersion() {
- assertThat(main.parse(new String[]{"-V"}).printVersion(), equalTo(true));
- assertThat(main.parse(new String[]{"--version"}).printVersion(), equalTo(true));
- assertThat(main.getExitStatus(), equalTo(0));
+ assertThat(main.parse(new String[]{"-V"}).printVersion()).isEqualTo(true);
+ assertThat(main.parse(new String[]{"--version"}).printVersion()).isEqualTo(true);
+ assertThat(main.getExitStatus()).isEqualTo(0);
}
@Test
public void shouldParseFileSystem() {
- assertThat(main.parse(new String[]{"-fs"}).isFileSystem(), equalTo(true));
- assertThat(main.parse(new String[]{"src", "doc", "-fs"}).isFileSystem(), equalTo(true));
- assertThat(main.getExitStatus(), equalTo(0));
+ assertThat(main.parse(new String[]{"-fs"}).isFileSystem()).isEqualTo(true);
+ assertThat(main.parse(new String[]{"src", "doc", "-fs"}).isFileSystem()).isEqualTo(true);
+ assertThat(main.getExitStatus()).isEqualTo(0);
}
@Test
public void shouldParseServer() {
- assertThat(main.parse(new String[]{"-ws"}).isServer(), equalTo(true));
- assertThat(main.getExitStatus(), equalTo(0));
+ assertThat(main.parse(new String[]{"-ws"}).isServer()).isEqualTo(true);
+ assertThat(main.getExitStatus()).isEqualTo(0);
}
@Test
public void shouldParseStdIO() {
- assertThat(main.parse(new String[]{"-io"}).isStdOut(), equalTo(true));
- assertThat(main.getExitStatus(), equalTo(0));
+ assertThat(main.parse(new String[]{"-io"}).isStdOut()).isEqualTo(true);
+ assertThat(main.getExitStatus()).isEqualTo(0);
}
@Test
public void shouldParseHelp() {
- assertThat(main.parse(new String[]{"-h"}).showHelp(), equalTo(true));
- assertThat(main.parse(new String[]{"--help"}).showHelp(), equalTo(true));
- assertThat(main.getExitStatus(), equalTo(0));
+ assertThat(main.parse(new String[]{"-h"}).showHelp()).isEqualTo(true);
+ assertThat(main.parse(new String[]{"--help"}).showHelp()).isEqualTo(true);
+ assertThat(main.getExitStatus()).isEqualTo(0);
}
@Test
public void shouldShowHelpIfNoArgumentsProvided() {
- assertThat(main.parse(new String[]{}).showHelp(), equalTo(true));
- assertThat(main.getExitStatus(), equalTo(1));
+ assertThat(main.parse(new String[]{}).showHelp()).isEqualTo(true);
+ assertThat(main.getExitStatus()).isEqualTo(1);
}
@Test
public void shouldParseEncodingHelp() {
- assertThat(main.parse(new String[]{"-ws","encoding"}).showCharSets(), equalTo(false));
- assertThat(main.parse(new String[]{"-h","encoding"}).showCharSets(), equalTo(true));
- assertThat(main.getExitStatus(), equalTo(0));
+ assertThat(main.parse(new String[]{"-ws","encoding"}).showCharSets()).isEqualTo(false);
+ assertThat(main.parse(new String[]{"-h","encoding"}).showCharSets()).isEqualTo(true);
+ assertThat(main.getExitStatus()).isEqualTo(0);
}
@Test
public void shouldParseGenerateFilesTest() {
- assertThat(main.parse(new String[]{"-gf"}).isGenerateFiles(), equalTo(true));
- assertThat(main.getExitStatus(), equalTo(0));
+ assertThat(main.parse(new String[]{"-gf"}).isGenerateFiles()).isEqualTo(true);
+ assertThat(main.getExitStatus()).isEqualTo(0);
}
@Test
public void shouldParseRegularExpressionTest() {
- assertThat(main.parse(new String[]{"-regex-test","/a.*","/ab"}).isRegExpTest(), equalTo(true));
- assertThat(main.getExitStatus(), equalTo(0));
+ assertThat(main.parse(new String[]{"-regex-test","/a.*","/ab"}).isRegExpTest()).isEqualTo(true);
+ assertThat(main.getExitStatus()).isEqualTo(0);
}
@Test
@@ -439,19 +437,19 @@ public void shouldDetectInvalidOptions3() {
}
private void verifyInvalid(String[] args) {
- assertThat(main.parse(args).showHelp(), equalTo(true));
- assertThat(main.getExitStatus(), equalTo(1));
+ assertThat(main.parse(args).showHelp()).isEqualTo(true);
+ assertThat(main.getExitStatus()).isEqualTo(1);
}
@Test
public void shouldDetectInvalidOptionsNoArgs() {
- assertThat(main.parse(new String[]{}).showHelp(), equalTo(true));
- assertThat(main.getExitStatus(), equalTo(1));
+ assertThat(main.parse(new String[]{}).showHelp()).isEqualTo(true);
+ assertThat(main.getExitStatus()).isEqualTo(1);
}
@Test
public void shouldRetrieveHelpText() {
String helpText = new Main().getHelpText();
- assertThat(helpText, containsString("Usage: java -jar jscover.jar [OPTION]..."));
+ assertThat(helpText).contains("Usage: java -jar jscover.jar [OPTION]...");
}
}
diff --git a/src/test/java/jscover/filesystem/ConfigurationForFSTest.java b/src/test/java/jscover/filesystem/ConfigurationForFSTest.java
index f5be97a9..0ef04280 100644
--- a/src/test/java/jscover/filesystem/ConfigurationForFSTest.java
+++ b/src/test/java/jscover/filesystem/ConfigurationForFSTest.java
@@ -352,32 +352,31 @@ You should also get your employer (if you work as a programmer) or your
import static java.util.logging.Level.FINE;
import static java.util.logging.Level.SEVERE;
-import static org.hamcrest.MatcherAssert.assertThat;
-import static org.hamcrest.Matchers.*;
+import static org.assertj.core.api.Assertions.assertThat;
public class ConfigurationForFSTest {
@Test
public void shouldHaveDefaults() {
ConfigurationForFS configuration = ConfigurationForFS.parse(new String[]{"-fs", "src", "doc"});
- assertThat(configuration.showHelp(), is(false));
- assertThat(configuration.isInvalid(), is(false));
- assertThat(configuration.getECMAVersion(), equalTo(CompilerOptions.LanguageMode.ECMASCRIPT_NEXT));
- assertThat(configuration.skipInstrumentation("/"), is(false));
- assertThat(configuration.isIncludeBranch(), is(true));
- assertThat(configuration.isIncludeFunction(), is(true));
- assertThat(configuration.getLogLevel(), is(SEVERE));
- assertThat(configuration.getThreads(), is(Runtime.getRuntime().availableProcessors()));
+ assertThat(configuration.showHelp()).isFalse();
+ assertThat(configuration.isInvalid()).isFalse();
+ assertThat(configuration.getECMAVersion()).isEqualTo(CompilerOptions.LanguageMode.ECMASCRIPT_NEXT);
+ assertThat(configuration.skipInstrumentation("/")).isFalse();
+ assertThat(configuration.isIncludeBranch()).isTrue();
+ assertThat(configuration.isIncludeFunction()).isTrue();
+ assertThat(configuration.getLogLevel()).isEqualTo(SEVERE);
+ assertThat(configuration.getThreads()).isEqualTo(Runtime.getRuntime().availableProcessors());
}
@SuppressWarnings("unchecked")
@Test
public void shouldHaveDefaultsViaConstructor() {
ConfigurationForFS configuration = new ConfigurationForFS();
- assertThat(configuration.getSrcDir(), nullValue());
- assertThat(configuration.getDestDir(), nullValue());
- assertThat(((Set)ReflectionUtils.getField(configuration, "excludes")).size(), is(0));
- assertThat(((Set)ReflectionUtils.getField(configuration, "excludeRegs")).size(), is(0));
+ assertThat(configuration.getSrcDir()).isNull();
+ assertThat(configuration.getDestDir()).isNull();
+ assertThat(((Set)ReflectionUtils.getField(configuration, "excludes")).size()).isEqualTo(0);
+ assertThat(((Set)ReflectionUtils.getField(configuration, "excludeRegs")).size()).isEqualTo(0);
}
@SuppressWarnings("unchecked")
@@ -391,237 +390,237 @@ public void shouldSetValues() {
configuration.addExclude(ConfigurationForFS.EXCLUDE_PREFIX +"/excluded");
configuration.addExcludeReg(ConfigurationForFS.EXCLUDE_REG_PREFIX +"/excludedReg");
- assertThat(configuration.getSrcDir(), sameInstance(src));
- assertThat(configuration.getDestDir(), sameInstance(dest));
+ assertThat(configuration.getSrcDir()).isSameAs(src);
+ assertThat(configuration.getDestDir()).isSameAs(dest);
Set excludes = (Set) ReflectionUtils.getField(configuration, "excludes");
- assertThat(excludes.size(), is(1));
- assertThat(excludes.iterator().next(), is("excluded"));
+ assertThat(excludes.size()).isEqualTo(1);
+ assertThat(excludes.iterator().next()).isEqualTo("excluded");
Set excludeRegs = (Set) ReflectionUtils.getField(configuration, "excludeRegs");
- assertThat(excludeRegs.size(), is(1));
- assertThat(excludeRegs.iterator().next().pattern(), is("/excludedReg"));
+ assertThat(excludeRegs.size()).isEqualTo(1);
+ assertThat(excludeRegs.iterator().next().pattern()).isEqualTo("/excludedReg");
}
@Test
public void shouldNotAllowDestinationDirectoryToEqualSourceDirectory() {
ConfigurationForFS configuration = ConfigurationForFS.parse(new String[]{"-fs", "src", "src"});
- assertThat(configuration.showHelp(), is(true));
- assertThat(configuration.isInvalid(), is(true));
+ assertThat(configuration.showHelp()).isTrue();
+ assertThat(configuration.isInvalid()).isTrue();
}
@Test
public void shouldNotAllowDestinationDirectoryToBeSubDirectoryOfSourceDirectory() {
ConfigurationForFS configuration = ConfigurationForFS.parse(new String[]{"-fs", "src", "src/main/java"});
- assertThat(configuration.showHelp(), is(true));
- assertThat(configuration.isInvalid(), is(true));
+ assertThat(configuration.showHelp()).isTrue();
+ assertThat(configuration.isInvalid()).isTrue();
}
@Test
public void shouldNotAllowDestinationDirectoryToBeSubDirectoryOfSourceDirectorySpecifiedAsCurrentDirectory() {
ConfigurationForFS configuration = ConfigurationForFS.parse(new String[]{"-fs", ".", "src/java"});
- assertThat(configuration.showHelp(), is(true));
- assertThat(configuration.isInvalid(), is(true));
+ assertThat(configuration.showHelp()).isTrue();
+ assertThat(configuration.isInvalid()).isTrue();
}
@Test
public void shouldAllowDestinationDirectoryToBeDifferentDirectoryOfSourceDirectoryButStartingWithTheSameName() {
ConfigurationForFS configuration = ConfigurationForFS.parse(new String[]{"-fs", "src/main/java", "src/main/java-instrumented"});
- assertThat(configuration.showHelp(), is(false));
- assertThat(configuration.isInvalid(), is(false));
+ assertThat(configuration.showHelp()).isFalse();
+ assertThat(configuration.isInvalid()).isFalse();
}
@Test
public void shouldShowHelpOnError() {
ConfigurationForFS configurationForFS = ConfigurationForFS.parse(new String[]{"-fs"});
- assertThat(configurationForFS.showHelp(), is(true));
- assertThat(configurationForFS.isInvalid(), is(true));
+ assertThat(configurationForFS.showHelp()).isTrue();
+ assertThat(configurationForFS.isInvalid()).isTrue();
}
@Test
public void shouldParseHelp() {
- assertThat(ConfigurationForFS.parse(new String[]{"-fs", "-h"}).showHelp(), is(true));
- assertThat(ConfigurationForFS.parse(new String[]{"-fs", "--help"}).showHelp(), is(true));
+ assertThat(ConfigurationForFS.parse(new String[]{"-fs", "-h"}).showHelp()).isTrue();
+ assertThat(ConfigurationForFS.parse(new String[]{"-fs", "--help"}).showHelp()).isTrue();
}
@Test
public void shouldParseBranch() {
- assertThat(ConfigurationForFS.parse(new String[]{"-fs", "--no-branch", "src", "doc"}).isIncludeBranch(), is(false));
+ assertThat(ConfigurationForFS.parse(new String[]{"-fs", "--no-branch", "src", "doc"}).isIncludeBranch()).isFalse();
}
@Test
public void shouldParseFunction() {
- assertThat(ConfigurationForFS.parse(new String[]{"-fs", "--no-function"}).isIncludeFunction(), is(false));
+ assertThat(ConfigurationForFS.parse(new String[]{"-fs", "--no-function"}).isIncludeFunction()).isFalse();
}
@Test
public void shouldParseDirectories() {
ConfigurationForFS configurationForFS = ConfigurationForFS.parse(new String[]{"-fs", "src", "doc"});
- assertThat(configurationForFS.getSrcDir(), equalTo(new File("src")));
- assertThat(configurationForFS.getDestDir(), equalTo(new File("doc")));
+ assertThat(configurationForFS.getSrcDir()).isEqualTo(new File("src"));
+ assertThat(configurationForFS.getDestDir()).isEqualTo(new File("doc"));
}
@Test
public void shouldDetectedInvalidArgs() {
ConfigurationForFS configurationForFS = ConfigurationForFS.parse(new String[]{"-fs", "src", "doc", "config"});
- assertThat(configurationForFS.showHelp(), is(true));
- assertThat(configurationForFS.isInvalid(), is(true));
+ assertThat(configurationForFS.showHelp()).isTrue();
+ assertThat(configurationForFS.isInvalid()).isTrue();
}
@Test
public void shouldParseDirectoriesWithFSOptionLast() {
ConfigurationForFS configurationForFS = ConfigurationForFS.parse(new String[]{"src", "doc", "-fs"});
- assertThat(configurationForFS.getSrcDir(), equalTo(new File("src")));
- assertThat(configurationForFS.getDestDir(), equalTo(new File("doc")));
+ assertThat(configurationForFS.getSrcDir()).isEqualTo(new File("src"));
+ assertThat(configurationForFS.getDestDir()).isEqualTo(new File("doc"));
}
@Test
public void shouldHandleNonExistingDirectory() {
- assertThat(ConfigurationForFS.parse(new String[]{"-fs", "unknown", "doc"}).showHelp(), is(true));
- assertThat(ConfigurationForFS.parse(new String[]{"-fs", "build.xml", "doc"}).showHelp(), is(true));
+ assertThat(ConfigurationForFS.parse(new String[]{"-fs", "unknown", "doc"}).showHelp()).isTrue();
+ assertThat(ConfigurationForFS.parse(new String[]{"-fs", "build.xml", "doc"}).showHelp()).isTrue();
}
@Test
public void shouldParseECMAVersion() {
ConfigurationForFS configuration = ConfigurationForFS.parse(new String[]{"-fs", "--js-version=ECMASCRIPT5", "src", "doc"});
- assertThat(configuration.getECMAVersion(), equalTo(CompilerOptions.LanguageMode.ECMASCRIPT5));
+ assertThat(configuration.getECMAVersion()).isEqualTo(CompilerOptions.LanguageMode.ECMASCRIPT5);
}
@Test
public void shouldParseThreads() {
ConfigurationForFS configuration = ConfigurationForFS.parse(new String[]{"-fs", "--threads=7", "src", "doc"});
- assertThat(configuration.getThreads(), equalTo(7));
+ assertThat(configuration.getThreads()).isEqualTo(7);
}
@Test
public void shouldParseLogLevel() {
- assertThat(ConfigurationForFS.parse(new String[]{"--log=FINE"}).getLogLevel(), equalTo(FINE));
+ assertThat(ConfigurationForFS.parse(new String[]{"--log=FINE"}).getLogLevel()).isEqualTo(FINE);
}
@Test
public void shouldParseNoInstrument() {
ConfigurationForFS configuration = ConfigurationForFS.parse(new String[]{"-fs", "--no-instrument=lib1", "--no-instrument=/lib2", "src", "doc"});
- assertThat(configuration.skipInstrumentation("test.js"), is(false));
- assertThat(configuration.skipInstrumentation("lib1/test.js"), is(true));
- assertThat(configuration.skipInstrumentation("lib2/test.js"), is(true));
- assertThat(configuration.skipInstrumentation("lib3/test.js"), is(false));
+ assertThat(configuration.skipInstrumentation("test.js")).isFalse();
+ assertThat(configuration.skipInstrumentation("lib1/test.js")).isTrue();
+ assertThat(configuration.skipInstrumentation("lib2/test.js")).isTrue();
+ assertThat(configuration.skipInstrumentation("lib3/test.js")).isFalse();
}
@Test
public void shouldParseNoInstrumentReg() {
ConfigurationForFS configuration = ConfigurationForFS.parse(new String[]{"-fs", "--no-instrument-reg=.*/lib/.*", "--no-instrument-reg=.*/test/.*", "--no-instrument-reg=/.*/test2/.*", "src", "doc"});
- assertThat(configuration.skipInstrumentation("test.js"), is(false));
- assertThat(configuration.skipInstrumentation("lib1/lib/test.js"), is(true));
- assertThat(configuration.skipInstrumentation("lib2/test/test.js"), is(true));
- assertThat(configuration.skipInstrumentation("lib3/test2/test.js"), is(true));
- assertThat(configuration.skipInstrumentation("lib4/domain/test.js"), is(false));
+ assertThat(configuration.skipInstrumentation("test.js")).isFalse();
+ assertThat(configuration.skipInstrumentation("lib1/lib/test.js")).isTrue();
+ assertThat(configuration.skipInstrumentation("lib2/test/test.js")).isTrue();
+ assertThat(configuration.skipInstrumentation("lib3/test2/test.js")).isTrue();
+ assertThat(configuration.skipInstrumentation("lib4/domain/test.js")).isFalse();
}
@Test
public void shouldHandleInvalidNoInstrumentRegularExpression() {
ConfigurationForFS configuration = ConfigurationForFS.parse(new String[]{"--no-instrument-reg=*"});
- assertThat(configuration.showHelp(), is(true));
- assertThat(configuration.isInvalid(), is(true));
+ assertThat(configuration.showHelp()).isTrue();
+ assertThat(configuration.isInvalid()).isTrue();
}
@Test
public void shouldParseNoInstrumentWithLeadingSlash() {
ConfigurationForFS configuration = ConfigurationForFS.parse(new String[]{"-fs", "--no-instrument=/lib1", "--no-instrument=/lib2", "src", "doc"});
- assertThat(configuration.skipInstrumentation("test.js"), is(false));
- assertThat(configuration.skipInstrumentation("lib1/test.js"), is(true));
- assertThat(configuration.skipInstrumentation("lib2/test.js"), is(true));
- assertThat(configuration.skipInstrumentation("lib3/test.js"), is(false));
+ assertThat(configuration.skipInstrumentation("test.js")).isFalse();
+ assertThat(configuration.skipInstrumentation("lib1/test.js")).isTrue();
+ assertThat(configuration.skipInstrumentation("lib2/test.js")).isTrue();
+ assertThat(configuration.skipInstrumentation("lib3/test.js")).isFalse();
}
@Test
public void shouldParseInstrumentReg() {
ConfigurationForFS configuration = ConfigurationForFS.parse(new String[]{"--only-instrument-reg=.*/production/.*"});
- assertThat(configuration.skipInstrumentation("test.js"), is(true));
- assertThat(configuration.skipInstrumentation("lib1/production/code.js"), is(false));
- assertThat(configuration.skipInstrumentation("lib2/test/production.js"), is(true));
+ assertThat(configuration.skipInstrumentation("test.js")).isTrue();
+ assertThat(configuration.skipInstrumentation("lib1/production/code.js")).isFalse();
+ assertThat(configuration.skipInstrumentation("lib2/test/production.js")).isTrue();
}
@Test
public void shouldParseInstrumentRegWithLeadingSlash() {
ConfigurationForFS configuration = ConfigurationForFS.parse(new String[]{"--only-instrument-reg=/production/.*"});
- assertThat(configuration.skipInstrumentation("production/code.js"), is(false));
+ assertThat(configuration.skipInstrumentation("production/code.js")).isFalse();
}
@Test
public void shouldHandleInvalidInstrumentRegularExpression() {
ConfigurationForFS configuration = ConfigurationForFS.parse(new String[]{"--only-instrument-reg=*"});
- assertThat(configuration.showHelp(), is(true));
- assertThat(configuration.isInvalid(), is(true));
+ assertThat(configuration.showHelp()).isTrue();
+ assertThat(configuration.isInvalid()).isTrue();
}
@Test
public void shouldParseInstrumentAndNoInstrumentReg1() {
ConfigurationForFS configuration = ConfigurationForFS.parse(new String[]{"--no-instrument=lib1", "--no-instrument-reg=lib2/production/test.*", "--only-instrument-reg=.*/production/.*", "src", "doc"});
- assertThat(configuration.skipInstrumentation("lib1/production/test.js"), is(true));
- assertThat(configuration.skipInstrumentation("lib2/production/test.js"), is(true));
- assertThat(configuration.skipInstrumentation("lib3/production/code.js"), is(false));
- assertThat(configuration.skipInstrumentation("lib4/code.js"), is(true));
+ assertThat(configuration.skipInstrumentation("lib1/production/test.js")).isTrue();
+ assertThat(configuration.skipInstrumentation("lib2/production/test.js")).isTrue();
+ assertThat(configuration.skipInstrumentation("lib3/production/code.js")).isFalse();
+ assertThat(configuration.skipInstrumentation("lib4/code.js")).isTrue();
}
@Test
public void shouldParseInstrumentAndNoInstrumentReg2() {
ConfigurationForFS configuration = ConfigurationForFS.parse(new String[]{"--no-instrument=lib1", "--only-instrument-reg=.*/production/.*", "--no-instrument-reg=lib2/production/test.*", "src", "doc"});
- assertThat(configuration.skipInstrumentation("lib1/production/test.js"), is(true));
- assertThat(configuration.skipInstrumentation("lib2/production/test.js"), is(false));
- assertThat(configuration.skipInstrumentation("lib3/production/code.js"), is(false));
- assertThat(configuration.skipInstrumentation("lib4/code.js"), is(true));
+ assertThat(configuration.skipInstrumentation("lib1/production/test.js")).isTrue();
+ assertThat(configuration.skipInstrumentation("lib2/production/test.js")).isFalse();
+ assertThat(configuration.skipInstrumentation("lib3/production/code.js")).isFalse();
+ assertThat(configuration.skipInstrumentation("lib4/code.js")).isTrue();
}
@Test
public void shouldParseInstrumentAndNoInstrumentReg3() {
ConfigurationForFS configuration = ConfigurationForFS.parse(new String[]{"--only-instrument-reg=.*/production/.*", "--no-instrument=lib1", "--no-instrument-reg=lib2/production/test.*", "src", "doc"});
- assertThat(configuration.skipInstrumentation("lib1/production/test.js"), is(false));
- assertThat(configuration.skipInstrumentation("lib2/production/test.js"), is(false));
- assertThat(configuration.skipInstrumentation("lib3/production/code.js"), is(false));
- assertThat(configuration.skipInstrumentation("lib4/code.js"), is(true));
+ assertThat(configuration.skipInstrumentation("lib1/production/test.js")).isFalse();
+ assertThat(configuration.skipInstrumentation("lib2/production/test.js")).isFalse();
+ assertThat(configuration.skipInstrumentation("lib3/production/code.js")).isFalse();
+ assertThat(configuration.skipInstrumentation("lib4/code.js")).isTrue();
}
@Test
public void shouldParseExclude() {
ConfigurationForFS configuration = ConfigurationForFS.parse(new String[]{"-fs", "--exclude=lib1", "--exclude=/lib2", "src", "doc"});
- assertThat(configuration.exclude("test.js"), is(false));
- assertThat(configuration.exclude("lib1/test.js"), is(true));
- assertThat(configuration.exclude("lib2/test.js"), is(true));
- assertThat(configuration.exclude("lib3/test.js"), is(false));
+ assertThat(configuration.exclude("test.js")).isFalse();
+ assertThat(configuration.exclude("lib1/test.js")).isTrue();
+ assertThat(configuration.exclude("lib2/test.js")).isTrue();
+ assertThat(configuration.exclude("lib3/test.js")).isFalse();
}
@Test
public void shouldParseExcludeReg() {
ConfigurationForFS configuration = ConfigurationForFS.parse(new String[]{"-fs", "--exclude-reg=.*/lib/.*", "--exclude-reg=/.*/test/.*", "--exclude-reg=/.*/test2/.*", "src", "doc"});
- assertThat(configuration.exclude("test.js"), is(false));
- assertThat(configuration.exclude("lib1/lib/test.js"), is(true));
- assertThat(configuration.exclude("/lib2/test/test.js"), is(true));
- assertThat(configuration.exclude("/lib3/test2/test.js"), is(true));
- assertThat(configuration.exclude("lib4/domain/test.js"), is(false));
+ assertThat(configuration.exclude("test.js")).isFalse();
+ assertThat(configuration.exclude("lib1/lib/test.js")).isTrue();
+ assertThat(configuration.exclude("/lib2/test/test.js")).isTrue();
+ assertThat(configuration.exclude("/lib3/test2/test.js")).isTrue();
+ assertThat(configuration.exclude("lib4/domain/test.js")).isFalse();
}
@Test
public void shouldHandleInvalidExcludeRegularExpression() {
ConfigurationForFS configuration = ConfigurationForFS.parse(new String[]{"--exclude-reg=*"});
- assertThat(configuration.showHelp(), is(true));
- assertThat(configuration.isInvalid(), is(true));
+ assertThat(configuration.showHelp()).isTrue();
+ assertThat(configuration.isInvalid()).isTrue();
}
@Test
public void shouldHandleInvalidOption() {
ConfigurationForFS configuration = ConfigurationForFS.parse(new String[]{"--unknownoption"});
- assertThat(configuration.showHelp(), is(true));
- assertThat(configuration.isInvalid(), is(true));
+ assertThat(configuration.showHelp()).isTrue();
+ assertThat(configuration.isInvalid()).isTrue();
}
@Test
public void shouldHandleInvalidShortOption() {
ConfigurationForFS configuration = ConfigurationForFS.parse(new String[]{"-u"});
- assertThat(configuration.showHelp(), is(true));
- assertThat(configuration.isInvalid(), is(true));
+ assertThat(configuration.showHelp()).isTrue();
+ assertThat(configuration.isInvalid()).isTrue();
}
@Test
public void shouldRetrieveHelpText() {
String helpText = new ConfigurationForFS().getHelpText();
- assertThat(helpText, containsString("Usage: java -jar JSCover-all.jar -fs [OPTION]..."));
+ assertThat(helpText).contains("Usage: java -jar JSCover-all.jar -fs [OPTION]...");
}
}
diff --git a/src/test/java/jscover/instrument/BranchHelperTest.java b/src/test/java/jscover/instrument/BranchHelperTest.java
index 68763f6f..6229fa4a 100644
--- a/src/test/java/jscover/instrument/BranchHelperTest.java
+++ b/src/test/java/jscover/instrument/BranchHelperTest.java
@@ -4,8 +4,7 @@
import com.google.javascript.rhino.Token;
import org.junit.jupiter.api.Test;
-import static org.hamcrest.MatcherAssert.assertThat;
-import static org.hamcrest.Matchers.is;
+import static org.assertj.core.api.Assertions.assertThat;
public class BranchHelperTest {
private BranchHelper helper = new BranchHelper();
@@ -16,8 +15,8 @@ public void shouldDetectBoolean() {
Node astRoot = parse(script);
Node orNode = NodeTestHelper.findNode(astRoot, Token.OR);
Node assignNode = NodeTestHelper.findNode(astRoot, Token.ASSIGN);
- assertThat(helper.isBoolean(orNode), is(true));
- assertThat(helper.isBoolean(assignNode), is(false));
+ assertThat(helper.isBoolean(orNode)).isTrue();
+ assertThat(helper.isBoolean(assignNode)).isFalse();
}
@Test
@@ -25,7 +24,7 @@ public void shouldDetectCoalesce() {
String script = "x = y || {};";
Node astRoot = parse(script);
Node orNode = NodeTestHelper.findNode(astRoot, Token.OR);
- assertThat(helper.isCoalesce(orNode), is(true));
+ assertThat(helper.isCoalesce(orNode)).isTrue();
}
@Test
@@ -33,7 +32,7 @@ public void shouldDetectCoalesceOnReturn() {
String script = "function f(y) {return y || {};}";
Node astRoot = parse(script);
Node orNode = NodeTestHelper.findNode(astRoot, Token.OR);
- assertThat(helper.isCoalesce(orNode), is(true));
+ assertThat(helper.isCoalesce(orNode)).isTrue();
}
@Test
@@ -42,7 +41,7 @@ public void shouldDetectCoalesceWithVariableDeclaration() {
Node astRoot = parse(script);
Node orNode = NodeTestHelper.findNode(astRoot, Token.OR);
- assertThat(helper.isCoalesce(orNode), is(true));
+ assertThat(helper.isCoalesce(orNode)).isTrue();
}
@Test
@@ -50,7 +49,7 @@ public void shouldNotDetectCoalesce() {
String script = "if (a || b) ;";
Node astRoot = parse(script);
Node orNode = NodeTestHelper.findNode(astRoot, Token.OR);
- assertThat(helper.isCoalesce(orNode), is(false));
+ assertThat(helper.isCoalesce(orNode)).isFalse();
}
@Test
@@ -58,7 +57,7 @@ public void shouldNotDetectAndAsCoalesce() {
String script = "x = y > 7;";
Node astRoot = parse(script);
Node node = NodeTestHelper.findNode(astRoot, Token.GT);
- assertThat(helper.isCoalesce(node), is(false));
+ assertThat(helper.isCoalesce(node)).isFalse();
}
private Node parse(String source) {
diff --git a/src/test/java/jscover/instrument/BranchInstrumentorTest.java b/src/test/java/jscover/instrument/BranchInstrumentorTest.java
index 5292cc6e..18d09a97 100644
--- a/src/test/java/jscover/instrument/BranchInstrumentorTest.java
+++ b/src/test/java/jscover/instrument/BranchInstrumentorTest.java
@@ -346,8 +346,7 @@ You should also get your employer (if you work as a programmer) or your
import com.google.javascript.rhino.Token;
import org.junit.jupiter.api.Test;
-import static org.hamcrest.MatcherAssert.assertThat;
-import static org.hamcrest.Matchers.equalTo;
+import static org.assertj.core.api.Assertions.assertThat;
public class BranchInstrumentorTest {
@@ -364,7 +363,7 @@ public void shouldCalculateNodePosition() {
String script = "var y = x > 0;";
Node astRoot = parse(script);
Node gtNode = NodeTestHelper.findNode(astRoot, Token.GT);
- assertThat(getBranchInstrumentor().getLinePosition(gtNode), equalTo(8));
+ assertThat(getBranchInstrumentor().getLinePosition(gtNode)).isEqualTo(8);
}
@Test
@@ -372,7 +371,7 @@ public void shouldCalculateNodePositionWhenAtStart() {
String script = "x > 0;";
Node astRoot = parse(script);
Node gtNode = NodeTestHelper.findNode(astRoot, Token.GT);
- assertThat(getBranchInstrumentor().getLinePosition(gtNode), equalTo(0));
+ assertThat(getBranchInstrumentor().getLinePosition(gtNode)).isEqualTo(0);
}
@Test
@@ -380,7 +379,7 @@ public void shouldCalculateNodePositionAsSecondStatement() {
String script = "var x;\nvar y = x > 0;";
Node astRoot = parse(script);
Node gtNode = NodeTestHelper.findNode(astRoot, Token.GT);
- assertThat(getBranchInstrumentor().getLinePosition(gtNode), equalTo(8));
+ assertThat(getBranchInstrumentor().getLinePosition(gtNode)).isEqualTo(8);
}
@Test
@@ -388,7 +387,7 @@ public void shouldCalculateNodePositionWithParent() {
String script = "if (x > y) {a = 1;}";
Node astRoot = parse(script);
Node gtNode = NodeTestHelper.findNode(astRoot, Token.GT);
- assertThat(getBranchInstrumentor().getLinePosition(gtNode), equalTo(4));
+ assertThat(getBranchInstrumentor().getLinePosition(gtNode)).isEqualTo(4);
}
@Test
@@ -400,7 +399,7 @@ public void shouldCalculateNodePositionAsFirstSiblingOfFunction() {
"}";
Node astRoot = parse(script);
Node gtNode = NodeTestHelper.findNode(astRoot, Token.GT);
- assertThat(getBranchInstrumentor().getLinePosition(gtNode), equalTo(8));
+ assertThat(getBranchInstrumentor().getLinePosition(gtNode)).isEqualTo(8);
}
@Test
@@ -413,6 +412,6 @@ public void shouldCalculateNodePositionAsSecondSiblingOfFunction() {
"}";
Node astRoot = parse(script);
Node gtNode = NodeTestHelper.findNode(astRoot, Token.GT);
- assertThat(getBranchInstrumentor().getLinePosition(gtNode), equalTo(8));
+ assertThat(getBranchInstrumentor().getLinePosition(gtNode)).isEqualTo(8);
}
}
\ No newline at end of file
diff --git a/src/test/java/jscover/instrument/BranchStatementBuilderTest.java b/src/test/java/jscover/instrument/BranchStatementBuilderTest.java
index 838d4aee..6050cbb5 100644
--- a/src/test/java/jscover/instrument/BranchStatementBuilderTest.java
+++ b/src/test/java/jscover/instrument/BranchStatementBuilderTest.java
@@ -348,8 +348,8 @@ You should also get your employer (if you work as a programmer) or your
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
-import static org.hamcrest.CoreMatchers.equalTo;
-import static org.hamcrest.MatcherAssert.assertThat;
+import static org.assertj.core.api.Assertions.assertThat;
+
public class BranchStatementBuilderTest {
private BranchStatementBuilder builder = new BranchStatementBuilder();
@@ -361,41 +361,42 @@ public void setUp() {
}
@Test
- public void shoudlBuildLineDeclaration() {
+ public void shouldBuildLineDeclaration() {
Node statement = builder.buildLineDeclaration("test.js", 4);
- assertThat(new CodePrinter.Builder(statement).setCompilerOptions(options).build(), equalTo("_$jscoverage['test.js'].branchData['4']"));
+ assertThat(new CodePrinter.Builder(statement).setCompilerOptions(options).build()).isEqualTo("_$jscoverage['test.js'].branchData['4']");
}
@Test
public void shouldBuildLineAndConditionInitialisation() {
Node statement = builder.buildLineAndConditionInitialisation("test.js", 4, 2, 12, 15);
- assertThat(new CodePrinter.Builder(statement).setCompilerOptions(options).build(), equalTo("_$jscoverage['test.js'].branchData['4'][2].init(12,15)"));
+ assertThat(new CodePrinter.Builder(statement).setCompilerOptions(options).build()).isEqualTo("_$jscoverage['test.js'].branchData['4'][2].init(12,15)");
}
@Test
public void shouldRemoveInstrumentationFromSource() {
- assertThat(builder.removeInstrumentation(" _$jscoverage['/dir/code.js'].someOtherData[101]++;\n"), equalTo(""));
- assertThat(builder.removeInstrumentation("x++;\n _$jscoverage['/dir/code.js'].lineData[100]++;\n"), equalTo("x++;\n"));
+ assertThat(builder.removeInstrumentation(" _$jscoverage['/dir/code.js'].someOtherData[101]++;\n")).isEqualTo("");
+ assertThat(builder.removeInstrumentation("x++;\n _$jscoverage['/dir/code.js'].lineData[100]++;\n")).isEqualTo("x++;\n");
}
@Test
public void shouldRemoveInstrumentationFromSourceInInitialisation() {
Node statement = builder.buildLineAndConditionInitialisation("test.js", 4, 2, 12, 15);
- assertThat(new CodePrinter.Builder(statement).setCompilerOptions(options).build(), equalTo("_$jscoverage['test.js'].branchData['4'][2].init(12,15)"));
+ assertThat(new CodePrinter.Builder(statement).setCompilerOptions(options).build()).isEqualTo("_$jscoverage['test.js'].branchData['4'][2].init(12,15)");
}
@Test
public void shouldBuildLineAndConditionCall() {
Node statement = builder.buildLineAndConditionCall("test.js", 4, 2);
- assertThat(new CodePrinter.Builder(statement).setCompilerOptions(options).build(), equalTo("_$jscoverage['test.js'].branchData['4'][2].ranCondition(result)"));
+ assertThat(new CodePrinter.Builder(statement).setCompilerOptions(options).build()).isEqualTo("_$jscoverage['test.js'].branchData['4'][2].ranCondition(result)");
}
@Test
public void shouldBuildLineAndConditionRecordingFunction() {
Node statement = builder.buildBranchRecordingFunction("test.js", 1, 4, 2);
- assertThat(new CodePrinter.Builder(statement).setCompilerOptions(options).build(), equalTo("function visit1_4_2(result){" +
+ String expected = "function visit1_4_2(result){" +
"_$jscoverage['test.js'].branchData['4'][2].ranCondition(result);" +
"return result" +
- "}"));
+ "}";
+ assertThat(new CodePrinter.Builder(statement).setCompilerOptions(options).build()).isEqualTo(expected);
}
}
diff --git a/src/test/java/jscover/instrument/CommentsHandlerTest.java b/src/test/java/jscover/instrument/CommentsHandlerTest.java
index 96e39881..1edc7803 100644
--- a/src/test/java/jscover/instrument/CommentsHandlerTest.java
+++ b/src/test/java/jscover/instrument/CommentsHandlerTest.java
@@ -350,8 +350,7 @@ You should also get your employer (if you work as a programmer) or your
import java.util.List;
import static jscover.instrument.CommentsHandler.*;
-import static org.hamcrest.MatcherAssert.assertThat;
-import static org.hamcrest.Matchers.equalTo;
+import static org.assertj.core.api.Assertions.assertThat;
@ExtendWith(MockitoExtension.class)
public class CommentsHandlerTest {
@@ -362,45 +361,45 @@ public class CommentsHandlerTest {
public void shouldDetectJSCoverageIgnoreComments() {
List comments = parse("//#JSCOVERAGE_IF x < 10\nvar x = 0;\n//#JSCOVERAGE_ENDIF");
handler.processComments(comments);
- assertThat(handler.getJsCoverageIgnoreComments().size(), equalTo(1));
+ assertThat(handler.getJsCoverageIgnoreComments().size()).isEqualTo(1);
JSCoverageIgnoreComment comment = handler.getJsCoverageIgnoreComments().iterator().next();
- assertThat(comment.getStart(), equalTo(1));
- assertThat(comment.getCondition(), equalTo("x < 10"));
- assertThat(comment.getEnd(), equalTo(3));
+ assertThat(comment.getStart()).isEqualTo(1);
+ assertThat(comment.getCondition()).isEqualTo("x < 10");
+ assertThat(comment.getEnd()).isEqualTo(3);
}
@Test
public void shouldDetectJSCoverIgnoreLine() {
List comments = parse("var x;\nx < 10;" + EXCL_LINE);
handler.processComments(comments);
- assertThat(handler.ignoreLine(1), equalTo(false));
- assertThat(handler.ignoreLine(2), equalTo(true));
+ assertThat(handler.ignoreLine(1)).isEqualTo(false);
+ assertThat(handler.ignoreLine(2)).isEqualTo(true);
}
@Test
public void shouldDetectJSCoverIgnoreLineRange() {
List comments = parse(EXCL_START + "\nvar x;\nx < 10;" + EXCL_STOP);
handler.processComments(comments);
- assertThat(handler.ignoreLine(1), equalTo(true));
- assertThat(handler.ignoreLine(2), equalTo(true));
- assertThat(handler.ignoreLine(4), equalTo(false));
+ assertThat(handler.ignoreLine(1)).isEqualTo(true);
+ assertThat(handler.ignoreLine(2)).isEqualTo(true);
+ assertThat(handler.ignoreLine(4)).isEqualTo(false);
}
@Test
public void shouldDetectJSCoverIgnoreBranch() {
List comments = parse("var x;\nx < 10;" + EXCL_BR_LINE);
handler.processComments(comments);
- assertThat(handler.ignoreBranch(1), equalTo(false));
- assertThat(handler.ignoreBranch(2), equalTo(true));
+ assertThat(handler.ignoreBranch(1)).isEqualTo(false);
+ assertThat(handler.ignoreBranch(2)).isEqualTo(true);
}
@Test
public void shouldDetectJSCoverIgnoreBranchRange() {
List comments = parse(EXCL_BR_START + "\nvar x;\nx < 10;" + EXCL_BR_STOP);
handler.processComments(comments);
- assertThat(handler.ignoreBranch(1), equalTo(true));
- assertThat(handler.ignoreBranch(2), equalTo(true));
- assertThat(handler.ignoreBranch(4), equalTo(false));
+ assertThat(handler.ignoreBranch(1)).isEqualTo(true);
+ assertThat(handler.ignoreBranch(2)).isEqualTo(true);
+ assertThat(handler.ignoreBranch(4)).isEqualTo(false);
}
private List parse(String source) {
diff --git a/src/test/java/jscover/instrument/InstrumenterServiceTest.java b/src/test/java/jscover/instrument/InstrumenterServiceTest.java
index c700582c..82ae210d 100644
--- a/src/test/java/jscover/instrument/InstrumenterServiceTest.java
+++ b/src/test/java/jscover/instrument/InstrumenterServiceTest.java
@@ -354,8 +354,7 @@ You should also get your employer (if you work as a programmer) or your
import java.io.File;
-import static org.hamcrest.MatcherAssert.assertThat;
-import static org.hamcrest.Matchers.containsString;
+import static org.assertj.core.api.Assertions.assertThat;
import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.mockito.BDDMockito.given;
@@ -386,8 +385,8 @@ public void shouldInstrumentForFileSystem() {
service.instrumentJSForFileSystem(config, src, dest, "src.js");
String jsInstrumented = ioUtils.loadFromFileSystem(dest);
- assertThat(jsInstrumented, containsString("x++;"));
- assertThat(jsInstrumented, containsString("_$jscoverage['/src.js'].lineData[1]++;"));
+ assertThat(jsInstrumented).contains("x++;");
+ assertThat(jsInstrumented).contains("_$jscoverage['/src.js'].lineData[1]++;");
}
@Test
@@ -395,8 +394,8 @@ public void shouldInstrumentForWebServer() {
addMockBehaviour();
String jsInstrumented = service.instrumentJSForWebServer(config, src, "/src.js");
- assertThat(jsInstrumented, containsString("x++;"));
- assertThat(jsInstrumented, containsString("_$jscoverage['/src.js'].lineData[1]++;"));
+ assertThat(jsInstrumented).contains("x++;");
+ assertThat(jsInstrumented).contains("_$jscoverage['/src.js'].lineData[1]++;");
}
@Test
@@ -409,7 +408,7 @@ public void shouldInstrumentForProxyServer() {
addMockBehaviour();
String jsInstrumented = service.instrumentJSForProxyServer(config, "x++;", "/src.js");
- assertThat(jsInstrumented, containsString("x++;"));
- assertThat(jsInstrumented, containsString("_$jscoverage['/src.js'].lineData[1]++;"));
+ assertThat(jsInstrumented).contains("x++;");
+ assertThat(jsInstrumented).contains("_$jscoverage['/src.js'].lineData[1]++;");
}
}
diff --git a/src/test/java/jscover/instrument/InstrumenterTest.java b/src/test/java/jscover/instrument/InstrumenterTest.java
index df5f6854..d91d3318 100644
--- a/src/test/java/jscover/instrument/InstrumenterTest.java
+++ b/src/test/java/jscover/instrument/InstrumenterTest.java
@@ -351,9 +351,7 @@ You should also get your employer (if you work as a programmer) or your
import org.mockito.Mock;
import org.mockito.junit.jupiter.MockitoExtension;
-import static org.hamcrest.MatcherAssert.assertThat;
-import static org.hamcrest.Matchers.equalTo;
-import static org.hamcrest.Matchers.hasItem;
+import static org.assertj.core.api.Assertions.assertThat;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.mockito.BDDMockito.given;
@@ -579,9 +577,9 @@ public void shouldInstrumentFunctionDeclarationAndAssignment() {
" _$jscoverage['test.js'].lineData[3]++;\n" +
"};\n";
assertEquals(expectedSource, instrumentedSource);
- assertThat(instrumenter.getValidLines().size(), equalTo(2));
- assertThat(instrumenter.getValidLines(), hasItem(1));
- assertThat(instrumenter.getValidLines(), hasItem(3));
+ assertThat(instrumenter.getValidLines().size()).isEqualTo(2);
+ assertThat(instrumenter.getValidLines()).contains(1);
+ assertThat(instrumenter.getValidLines()).contains(3);
}
@Test
@@ -600,9 +598,9 @@ public void shouldInstrumentFunctionDeclarationInInfix() {
" return 1;\n" +
"}};\n";
assertEquals(expectedSource, instrumentedSource);
- assertThat(instrumenter.getValidLines().size(), equalTo(2));
- assertThat(instrumenter.getValidLines(), hasItem(1));
- assertThat(instrumenter.getValidLines(), hasItem(3));
+ assertThat(instrumenter.getValidLines().size()).isEqualTo(2);
+ assertThat(instrumenter.getValidLines()).contains(1);
+ assertThat(instrumenter.getValidLines()).contains(3);
}
@Test
@@ -626,10 +624,10 @@ public void shouldInstrumentFunctionInTernary() {
" return false;\n" +
"};\n";
assertEquals(expectedSource, instrumentedSource);
- assertThat(instrumenter.getValidLines().size(), equalTo(3));
- assertThat(instrumenter.getValidLines(), hasItem(1));
- assertThat(instrumenter.getValidLines(), hasItem(3));
- assertThat(instrumenter.getValidLines(), hasItem(5));
+ assertThat(instrumenter.getValidLines().size()).isEqualTo(3);
+ assertThat(instrumenter.getValidLines()).contains(1);
+ assertThat(instrumenter.getValidLines()).contains(3);
+ assertThat(instrumenter.getValidLines()).contains(5);
}
@Test
@@ -646,9 +644,9 @@ public void shouldInstrumentFunctionInArray() {
" return true;\n" +
"}];\n";
assertEquals(expectedSource, instrumentedSource);
- assertThat(instrumenter.getValidLines().size(), equalTo(2));
- assertThat(instrumenter.getValidLines(), hasItem(1));
- assertThat(instrumenter.getValidLines(), hasItem(3));
+ assertThat(instrumenter.getValidLines().size()).isEqualTo(2);
+ assertThat(instrumenter.getValidLines()).contains(1);
+ assertThat(instrumenter.getValidLines()).contains(3);
}
@Test
@@ -665,9 +663,9 @@ public void shouldInstrumentFunctionInBraces() {
" return true;\n" +
"};\n";
assertEquals(expectedSource, instrumentedSource);
- assertThat(instrumenter.getValidLines().size(), equalTo(2));
- assertThat(instrumenter.getValidLines(), hasItem(1));
- assertThat(instrumenter.getValidLines(), hasItem(3));
+ assertThat(instrumenter.getValidLines().size()).isEqualTo(2);
+ assertThat(instrumenter.getValidLines()).contains(1);
+ assertThat(instrumenter.getValidLines()).contains(3);
}
@Test
diff --git a/src/test/java/jscover/instrument/NodeTestHelper.java b/src/test/java/jscover/instrument/NodeTestHelper.java
index 2f31abae..7fd33083 100644
--- a/src/test/java/jscover/instrument/NodeTestHelper.java
+++ b/src/test/java/jscover/instrument/NodeTestHelper.java
@@ -1,6 +1,5 @@
package jscover.instrument;
-
import com.google.javascript.rhino.Node;
import com.google.javascript.rhino.Token;
diff --git a/src/test/java/jscover/instrument/SourceProcessorTest.java b/src/test/java/jscover/instrument/SourceProcessorTest.java
index afe434d7..5d77e604 100644
--- a/src/test/java/jscover/instrument/SourceProcessorTest.java
+++ b/src/test/java/jscover/instrument/SourceProcessorTest.java
@@ -354,9 +354,7 @@ You should also get your employer (if you work as a programmer) or your
import java.util.TreeSet;
-import static org.hamcrest.MatcherAssert.assertThat;
-import static org.hamcrest.Matchers.equalTo;
-import static org.hamcrest.Matchers.startsWith;
+import static org.assertj.core.api.Assertions.assertThat;
import static org.mockito.BDDMockito.given;
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;
@@ -382,7 +380,7 @@ public void shouldNotIncludeBranchLogicForJsLineInitialization() {
" _$jscoverage['test.js'].lineData = [];\n" +
" _$jscoverage['test.js'].lineData[1] = 0;\n" +
"}\n";
- assertThat(actual, equalTo(expected));
+ assertThat(actual).isEqualTo(expected);
}
@Test
@@ -394,7 +392,7 @@ public void shouldIncludeBranchLogicForJsLineInitialization() {
" _$jscoverage['test.js'].lineData = [];\n" +
" _$jscoverage['test.js'].lineData[1] = 0;\n" +
"}\n";
- assertThat(actual, equalTo(expected));
+ assertThat(actual).isEqualTo(expected);
}
@Test
@@ -403,7 +401,7 @@ public void shouldIncludeBranchLogicForProcessSourceEvenIfIncludeBranchCoverageI
given(ioUtils.loadFromClassPath("/jscoverage-common.js")).willReturn("");
given(ioUtils.loadFromClassPath("/jscoverage-branch.js")).willReturn("");
- assertThat(sourceProcessor.processSource(), startsWith("var jsCover_isolateBrowser = false;\n"));
+ assertThat(sourceProcessor.processSource()).startsWith("var jsCover_isolateBrowser = false;\n");
verify(ioUtils, times(1)).loadFromClassPath("/jscoverage-branch.js");
}
@@ -414,7 +412,7 @@ public void shouldIncludeBranchLogicForProcessSource() {
given(ioUtils.loadFromClassPath("/jscoverage-common.js")).willReturn("");
given(ioUtils.loadFromClassPath("/jscoverage-branch.js")).willReturn("");
- assertThat(sourceProcessor.processSource(), startsWith("var jsCover_isolateBrowser = false;\n"));
+ assertThat(sourceProcessor.processSource()).startsWith("var jsCover_isolateBrowser = false;\n");
verify(ioUtils, times(1)).loadFromClassPath("/jscoverage-branch.js");
}
@@ -426,7 +424,7 @@ public void shouldIncludeLocalStorageLogicForProcessSource() {
given(ioUtils.loadFromClassPath("/jscoverage-branch.js")).willReturn("");
given(ioUtils.loadFromClassPath("/jscoverage-localstorage.js")).willReturn("");
- assertThat(sourceProcessor.processSource(), startsWith("var jsCover_isolateBrowser = false;\n"));
+ assertThat(sourceProcessor.processSource()).startsWith("var jsCover_isolateBrowser = false;\n");
verify(ioUtils, times(1)).loadFromClassPath("/jscoverage-localstorage.js");
}
@@ -437,6 +435,6 @@ public void shouldIncludeIsolateBrowserLogicForProcessSource() {
given(ioUtils.loadFromClassPath("/jscoverage-common.js")).willReturn("");
given(ioUtils.loadFromClassPath("/jscoverage-branch.js")).willReturn("");
- assertThat(sourceProcessor.processSource(), startsWith("var jsCover_isolateBrowser = true;\n"));
+ assertThat(sourceProcessor.processSource()).startsWith("var jsCover_isolateBrowser = true;\n");
}
}
diff --git a/src/test/java/jscover/instrument/StatementBuilderTest.java b/src/test/java/jscover/instrument/StatementBuilderTest.java
index b9ce6515..b0aa1447 100644
--- a/src/test/java/jscover/instrument/StatementBuilderTest.java
+++ b/src/test/java/jscover/instrument/StatementBuilderTest.java
@@ -351,8 +351,7 @@ You should also get your employer (if you work as a programmer) or your
import java.util.SortedSet;
import java.util.TreeSet;
-import static org.hamcrest.MatcherAssert.assertThat;
-import static org.hamcrest.Matchers.*;
+import static org.assertj.core.api.Assertions.assertThat;
import static org.junit.jupiter.api.Assertions.assertThrows;
public class StatementBuilderTest {
@@ -368,20 +367,20 @@ public void setUp() {
@Test
public void shouldBuildInstrumentationIncrementer() {
Node statement = builder.buildInstrumentationIncrementer(7, "/dir/file.js", "lineData");
- assertThat(new CodePrinter.Builder(statement).setCompilerOptions(options).build(), equalTo("_$jscoverage['/dir/file.js'].lineData[7]++"));
+ assertThat(new CodePrinter.Builder(statement).setCompilerOptions(options).build()).isEqualTo("_$jscoverage['/dir/file.js'].lineData[7]++");
}
@Test
public void shouldCreateInstrumentationStatement2() {
Node statement = builder.buildLineNumberExpression(7, "/dir/file.js", "lineData");
- assertThat(new CodePrinter.Builder(statement).setCompilerOptions(options).build(), equalTo("_$jscoverage['/dir/file.js'].lineData[7]"));
+ assertThat(new CodePrinter.Builder(statement).setCompilerOptions(options).build()).isEqualTo("_$jscoverage['/dir/file.js'].lineData[7]");
}
@Test
public void shouldCreateInstrumentationStatement() {
Node statement = builder.buildInstrumentationStatement(7, "/dir/file.js", validLines);
- assertThat(new CodePrinter.Builder(statement).setCompilerOptions(options).build(), equalTo("_$jscoverage['/dir/file.js'].lineData[7]++"));
- assertThat(validLines, hasItem(7));
+ assertThat(new CodePrinter.Builder(statement).setCompilerOptions(options).build()).isEqualTo("_$jscoverage['/dir/file.js'].lineData[7]++");
+ assertThat(validLines).contains(7);
}
@Test
@@ -392,13 +391,13 @@ public void shouldThrowExceptionIfLineNumberInvalid() {
@Test
public void shouldCreateConditionalIgnoreStatement() {
Node statement = builder.buildConditionalStatement(7, 12, "/dir/file.js");
- assertThat(new CodePrinter.Builder(statement).setCompilerOptions(options).build(), equalTo("_$jscoverage['/dir/file.js'].conditionals[7]=12"));
+ assertThat(new CodePrinter.Builder(statement).setCompilerOptions(options).build()).isEqualTo("_$jscoverage['/dir/file.js'].conditionals[7]=12");
}
@Test
public void shouldCreateFunctionInstrumentationStatement() {
Node statement = builder.buildFunctionInstrumentationStatement(7, "/dir/file.js");
- assertThat(new CodePrinter.Builder(statement).setCompilerOptions(options).build(), equalTo("_$jscoverage['/dir/file.js'].functionData[7]++"));
+ assertThat(new CodePrinter.Builder(statement).setCompilerOptions(options).build()).isEqualTo("_$jscoverage['/dir/file.js'].functionData[7]++");
}
@Test
@@ -407,9 +406,9 @@ public void shouldDetectInstrumentation() {
Node getProp = IR.getprop(jscover, "someval");
Node call = IR.call(getProp);
- assertThat(builder.isInstrumentation(call), is(true));//No source so must be synthetic
+ assertThat(builder.isInstrumentation(call)).isTrue();//No source so must be synthetic
call.setSourceFileForTesting("Hey");
- assertThat(builder.isInstrumentation(call), is(true));
+ assertThat(builder.isInstrumentation(call)).isTrue();
}
@Test
@@ -419,6 +418,6 @@ public void shouldNotDetectInstrumentation() {
Node call = IR.call(getProp);
call.setSourceFileForTesting("Hey");
- assertThat(builder.isInstrumentation(call), is(false));
+ assertThat(builder.isInstrumentation(call)).isFalse();
}
}
diff --git a/src/test/java/jscover/report/BranchDataTest.java b/src/test/java/jscover/report/BranchDataTest.java
index 878bf9a7..a53e3bac 100644
--- a/src/test/java/jscover/report/BranchDataTest.java
+++ b/src/test/java/jscover/report/BranchDataTest.java
@@ -344,9 +344,7 @@ You should also get your employer (if you work as a programmer) or your
import org.junit.jupiter.api.Test;
-import static org.hamcrest.CoreMatchers.equalTo;
-import static org.hamcrest.MatcherAssert.assertThat;
-import static org.hamcrest.Matchers.is;
+import static org.assertj.core.api.Assertions.assertThat;
import static org.junit.jupiter.api.Assertions.assertThrows;
public class BranchDataTest {
@@ -364,60 +362,60 @@ public void shouldThrowExceptionIfAddingBranchDataWithMismatchedNodeLength() {
@Test
public void shouldDetectUnloadedIncluded() {
- assertThat(new BranchData(0, 0, 0, 0).isUnloadedJS(), is(true));
- assertThat(new BranchData(1, 0, 0, 0).isUnloadedJS(), is(false));
- assertThat(new BranchData(0, 1, 0, 0).isUnloadedJS(), is(false));
- assertThat(new BranchData(0, 0, 1, 0).isUnloadedJS(), is(false));
- assertThat(new BranchData(0, 0, 0, 1).isUnloadedJS(), is(false));
+ assertThat(new BranchData(0, 0, 0, 0).isUnloadedJS()).isTrue();
+ assertThat(new BranchData(1, 0, 0, 0).isUnloadedJS()).isFalse();
+ assertThat(new BranchData(0, 1, 0, 0).isUnloadedJS()).isFalse();
+ assertThat(new BranchData(0, 0, 1, 0).isUnloadedJS()).isFalse();
+ assertThat(new BranchData(0, 0, 0, 1).isUnloadedJS()).isFalse();
}
@Test
public void shouldIgnoreNodeComparisonIfAddedBranchWasUnloadedIncluded() {
branchData.addCoverage(new BranchData(0, 0, 0, 0));
- assertThat(branchData.getPosition(), equalTo(1));
- assertThat(branchData.getNodeLength(), equalTo(2));
- assertThat(branchData.getEvalFalse(), equalTo(3));
- assertThat(branchData.getEvalTrue(), equalTo(4));
+ assertThat(branchData.getPosition()).isEqualTo(1);
+ assertThat(branchData.getNodeLength()).isEqualTo(2);
+ assertThat(branchData.getEvalFalse()).isEqualTo(3);
+ assertThat(branchData.getEvalTrue()).isEqualTo(4);
}
@Test
public void shouldIgnoreNodeComparisonIfSourceBranchWasUnloadedIncluded() {
BranchData branchData = new BranchData(0, 0, 0, 0);
branchData.addCoverage(new BranchData(1, 2, 3, 4));
- assertThat(branchData.getPosition(), equalTo(1));
- assertThat(branchData.getNodeLength(), equalTo(2));
- assertThat(branchData.getEvalFalse(), equalTo(3));
- assertThat(branchData.getEvalTrue(), equalTo(4));
+ assertThat(branchData.getPosition()).isEqualTo(1);
+ assertThat(branchData.getNodeLength()).isEqualTo(2);
+ assertThat(branchData.getEvalFalse()).isEqualTo(3);
+ assertThat(branchData.getEvalTrue()).isEqualTo(4);
}
@Test
public void shouldAddCounts() {
branchData.addCoverage(new BranchData(1, 2, 10, 100));
- assertThat(branchData.getEvalFalse(), equalTo(13));
- assertThat(branchData.getEvalTrue(), equalTo(104));
+ assertThat(branchData.getEvalFalse()).isEqualTo(13);
+ assertThat(branchData.getEvalTrue()).isEqualTo(104);
}
@Test
public void shouldReturnCoverage00() {
BranchData branchData = new BranchData(1, 2, 0, 0);
- assertThat(branchData.getCoverage(), equalTo(0));
+ assertThat(branchData.getCoverage()).isEqualTo(0);
}
@Test
public void shouldReturnCoverage01() {
BranchData branchData = new BranchData(1, 2, 0, 1);
- assertThat(branchData.getCoverage(), equalTo(50));
+ assertThat(branchData.getCoverage()).isEqualTo(50);
}
@Test
public void shouldReturnCoverage10() {
BranchData branchData = new BranchData(1, 2, 1, 0);
- assertThat(branchData.getCoverage(), equalTo(50));
+ assertThat(branchData.getCoverage()).isEqualTo(50);
}
@Test
public void shouldReturnCoverage11() {
BranchData branchData = new BranchData(1, 2, 1, 1);
- assertThat(branchData.getCoverage(), equalTo(100));
+ assertThat(branchData.getCoverage()).isEqualTo(100);
}
}
diff --git a/src/test/java/jscover/report/ConfigurationForReportTest.java b/src/test/java/jscover/report/ConfigurationForReportTest.java
index eaf9a196..e6c123bb 100644
--- a/src/test/java/jscover/report/ConfigurationForReportTest.java
+++ b/src/test/java/jscover/report/ConfigurationForReportTest.java
@@ -353,8 +353,7 @@ You should also get your employer (if you work as a programmer) or your
import java.util.List;
import static jscover.report.ReportFormat.COBERTURAXML;
-import static org.hamcrest.MatcherAssert.assertThat;
-import static org.hamcrest.Matchers.*;
+import static org.assertj.core.api.Assertions.assertThat;
import static org.mockito.Mockito.mock;
@ExtendWith(MockitoExtension.class)
@@ -371,123 +370,123 @@ public void setUp() {
public void shouldSetJSONDirectory() {
File dir = mock(File.class);
configuration.setJsonDirectory(dir);
- assertThat(configuration.getJsonDirectory(), sameInstance(dir));
+ assertThat(configuration.getJsonDirectory()).isSameAs(dir);
}
@Test
public void shouldSetSourceDirectory() {
File dir = mock(File.class);
configuration.setSourceDirectory(dir);
- assertThat(configuration.getSourceDirectory(), sameInstance(dir));
+ assertThat(configuration.getSourceDirectory()).isSameAs(dir);
}
@Test
public void shouldSetReportFormat() {
configuration.setReportFormat(COBERTURAXML);
- assertThat(configuration.getReportFormat(), is(COBERTURAXML));
+ assertThat(configuration.getReportFormat()).isEqualTo(COBERTURAXML);
}
@Test
public void shouldBeInvalidIfNoArgs() {
configuration.parse(new String[]{});
- assertThat(configuration.showHelp(), equalTo(true));
- assertThat(configuration.isInvalid(), equalTo(true));
- assertThat(configuration.isFormat(), equalTo(false));
- assertThat(configuration.isMerge(), equalTo(false));
+ assertThat(configuration.showHelp()).isEqualTo(true);
+ assertThat(configuration.isInvalid()).isEqualTo(true);
+ assertThat(configuration.isFormat()).isEqualTo(false);
+ assertThat(configuration.isMerge()).isEqualTo(false);
}
@Test
public void shouldParseHelp1() {
configuration.parse(new String[]{"-h"});
- assertThat(configuration.showHelp(), equalTo(true));
- assertThat(configuration.isInvalid(), equalTo(false));
+ assertThat(configuration.showHelp()).isEqualTo(true);
+ assertThat(configuration.isInvalid()).isEqualTo(false);
}
@Test
public void shouldParseHelp2() {
configuration.parse(new String[]{"--help"});
- assertThat(configuration.showHelp(), equalTo(true));
- assertThat(configuration.isInvalid(), equalTo(false));
+ assertThat(configuration.showHelp()).isEqualTo(true);
+ assertThat(configuration.isInvalid()).isEqualTo(false);
}
@Test
public void shouldBeInvalidIfFormatAndMergePrefixesPResent() {
configuration.parse(new String[]{"--format=XMLSUMMARY", "--merge"});
- assertThat(configuration.showHelp(), equalTo(true));
- assertThat(configuration.isInvalid(), equalTo(true));
- assertThat(configuration.isFormat(), equalTo(true));
- assertThat(configuration.isMerge(), equalTo(true));
+ assertThat(configuration.showHelp()).isEqualTo(true);
+ assertThat(configuration.isInvalid()).isEqualTo(true);
+ assertThat(configuration.isFormat()).isEqualTo(true);
+ assertThat(configuration.isMerge()).isEqualTo(true);
}
@Test
public void shouldBeInvalidIfXmlSummaryWithTooManyArgs() {
configuration.parse(new String[]{"--format=XMLSUMMARY", "target", "src"});
- assertThat(configuration.showHelp(), equalTo(true));
- assertThat(configuration.isInvalid(), equalTo(true));
- assertThat(configuration.isFormat(), equalTo(true));
+ assertThat(configuration.showHelp()).isEqualTo(true);
+ assertThat(configuration.isInvalid()).isEqualTo(true);
+ assertThat(configuration.isFormat()).isEqualTo(true);
}
@Test
public void shouldBeInvalidIfXmlSummaryWithTooFewArgs() {
configuration.parse(new String[]{"--format=XMLSUMMARY"});
- assertThat(configuration.showHelp(), equalTo(true));
- assertThat(configuration.isInvalid(), equalTo(true));
+ assertThat(configuration.showHelp()).isEqualTo(true);
+ assertThat(configuration.isInvalid()).isEqualTo(true);
}
@Test
public void shouldBeInvalidIfLCovWithTooManyArgs() {
configuration.parse(new String[]{"--format=XMLSUMMARY", "target", "src", "extra"});
- assertThat(configuration.showHelp(), equalTo(true));
- assertThat(configuration.isInvalid(), equalTo(true));
+ assertThat(configuration.showHelp()).isEqualTo(true);
+ assertThat(configuration.isInvalid()).isEqualTo(true);
}
@Test
public void shouldBeInvalidIfLCovWithTooFewArgs() {
configuration.parse(new String[]{"--format=LCOV", "target"});
- assertThat(configuration.showHelp(), equalTo(true));
- assertThat(configuration.isInvalid(), equalTo(true));
+ assertThat(configuration.showHelp()).isEqualTo(true);
+ assertThat(configuration.isInvalid()).isEqualTo(true);
}
@Test
public void shouldBeInvalidIfLCovWithNonExistentReportDir() {
configuration.parse(new String[]{"--format=LCOV", "invalid", "invalid"});
- assertThat(configuration.showHelp(), equalTo(true));
- assertThat(configuration.isInvalid(), equalTo(true));
+ assertThat(configuration.showHelp()).isEqualTo(true);
+ assertThat(configuration.isInvalid()).isEqualTo(true);
}
@Test
public void shouldBeInvalidIfLCovWithFileAsReportDir() {
configuration.parse(new String[]{"--format=LCOV", "build.xml", "build.xml"});
- assertThat(configuration.showHelp(), equalTo(true));
- assertThat(configuration.isInvalid(), equalTo(true));
+ assertThat(configuration.showHelp()).isEqualTo(true);
+ assertThat(configuration.isInvalid()).isEqualTo(true);
}
@Test
public void shouldParseXmlSummary() {
configuration.parse(new String[]{"--format=XMLSUMMARY", "target"});
- assertThat(configuration.showHelp(), equalTo(false));
- assertThat(configuration.isInvalid(), equalTo(false));
- assertThat(configuration.getReportFormat(), equalTo(ReportFormat.XMLSUMMARY));
- assertThat(configuration.getJsonDirectory(), equalTo(new File("target")));
+ assertThat(configuration.showHelp()).isEqualTo(false);
+ assertThat(configuration.isInvalid()).isEqualTo(false);
+ assertThat(configuration.getReportFormat()).isEqualTo(ReportFormat.XMLSUMMARY);
+ assertThat(configuration.getJsonDirectory()).isEqualTo(new File("target"));
}
@Test
public void shouldParseCoberturaXml() {
configuration.parse(new String[]{"--format=COBERTURAXML", "target", "src"});
- assertThat(configuration.showHelp(), equalTo(false));
- assertThat(configuration.isInvalid(), equalTo(false));
- assertThat(configuration.getReportFormat(), equalTo(COBERTURAXML));
- assertThat(configuration.getJsonDirectory(), equalTo(new File("target")));
+ assertThat(configuration.showHelp()).isEqualTo(false);
+ assertThat(configuration.isInvalid()).isEqualTo(false);
+ assertThat(configuration.getReportFormat()).isEqualTo(COBERTURAXML);
+ assertThat(configuration.getJsonDirectory()).isEqualTo(new File("target"));
}
@Test
public void shouldParseLCov() {
configuration.parse(new String[]{"--format=LCOV", "target", "src"});
- assertThat(configuration.showHelp(), equalTo(false));
- assertThat(configuration.isInvalid(), equalTo(false));
- assertThat(configuration.getReportFormat(), equalTo(ReportFormat.LCOV));
- assertThat(configuration.getJsonDirectory(), equalTo(new File("target")));
- assertThat(configuration.getSourceDirectory(), equalTo(new File("src")));
+ assertThat(configuration.showHelp()).isEqualTo(false);
+ assertThat(configuration.isInvalid()).isEqualTo(false);
+ assertThat(configuration.getReportFormat()).isEqualTo(ReportFormat.LCOV);
+ assertThat(configuration.getJsonDirectory()).isEqualTo(new File("target"));
+ assertThat(configuration.getSourceDirectory()).isEqualTo(new File("src"));
}
@Test
@@ -500,30 +499,30 @@ public void shouldParseMerge() {
File merged = new File(destDir);
configuration.parse(new String[]{"--merge", dir1, dir2, destDir});
- assertThat(configuration.showHelp(), equalTo(false));
- assertThat(configuration.isInvalid(), equalTo(false));
- assertThat(configuration.getMergeDirs().size(), equalTo(2));
- assertThat(configuration.getMergeDirs(), hasItem(report1));
- assertThat(configuration.getMergeDirs(), hasItem(report2));
- assertThat(configuration.getMergeDestDir(), equalTo(merged));
+ assertThat(configuration.showHelp()).isEqualTo(false);
+ assertThat(configuration.isInvalid()).isEqualTo(false);
+ assertThat(configuration.getMergeDirs().size()).isEqualTo(2);
+ assertThat(configuration.getMergeDirs()).contains(report1);
+ assertThat(configuration.getMergeDirs()).contains(report2);
+ assertThat(configuration.getMergeDestDir()).isEqualTo(merged);
}
@Test
public void shouldDetectInsufficientMergeArguments() {
configuration.parse(new String[]{"--merge", "dir1"});
- assertThat(configuration.showHelp(), equalTo(true));
- assertThat(configuration.isInvalid(), equalTo(true));
+ assertThat(configuration.showHelp()).isEqualTo(true);
+ assertThat(configuration.isInvalid()).isEqualTo(true);
}
@Test
public void shouldDetectInvalidFile() {
- assertThat(configuration.isValidFile(new File("doesntExists")), equalTo(false));
- assertThat(configuration.isValidFile(new File("src")), equalTo(false));
+ assertThat(configuration.isValidFile(new File("doesntExists"))).isEqualTo(false);
+ assertThat(configuration.isValidFile(new File("src"))).isEqualTo(false);
}
@Test
public void shouldDetectInvalidReportDirectory() {
- assertThat(configuration.isValidReportDirectory(new File("build.xml")), equalTo(false));
+ assertThat(configuration.isValidReportDirectory(new File("build.xml"))).isEqualTo(false);
}
@Test
@@ -534,8 +533,8 @@ public void shouldDetectBadDirForMerge() {
String destDir = "target/merged";
configuration.parse(new String[]{"--merge", dir1, dir2, destDir});
- assertThat(configuration.showHelp(), equalTo(true));
- assertThat(configuration.isInvalid(), equalTo(true));
+ assertThat(configuration.showHelp()).isEqualTo(true);
+ assertThat(configuration.isInvalid()).isEqualTo(true);
}
private File createValidReportDir(String dir) {
@@ -548,19 +547,19 @@ private File createValidReportDir(String dir) {
@Test
public void shouldRetrieveHelpText() {
String helpText = configuration.getHelpText();
- assertThat(helpText, containsString("Usage: java -cp JSCover-all.jar jscover.report.Main --format=XMLSUMMARY REPORT-DIR"));
- assertThat(helpText, containsString("or java -cp JSCover-all.jar jscover.report.Main --format=[ LCOV | COBERTURAXML ] REPORT-DIR SRC-DIRECTORY"));
- assertThat(helpText, containsString("or java -cp JSCover-all.jar jscover.report.Main --merge REPORT-DIR1 REPORT-DIR2... DEST-DIR"));
+ assertThat(helpText).contains("Usage: java -cp JSCover-all.jar jscover.report.Main --format=XMLSUMMARY REPORT-DIR");
+ assertThat(helpText).contains("or java -cp JSCover-all.jar jscover.report.Main --format=[ LCOV | COBERTURAXML ] REPORT-DIR SRC-DIRECTORY");
+ assertThat(helpText).contains("or java -cp JSCover-all.jar jscover.report.Main --merge REPORT-DIR1 REPORT-DIR2... DEST-DIR");
}
@Test
public void shouldSetProperties() {
List mergeDirs = new ArrayList<>();
configuration.setMergeDirs(mergeDirs);
- assertThat(mergeDirs, sameInstance(mergeDirs));
+ assertThat(mergeDirs).isSameAs(mergeDirs);
File mergeDestDir = new File(".");
configuration.setMergeDestDir(mergeDestDir);
- assertThat(mergeDestDir, sameInstance(mergeDestDir));
+ assertThat(mergeDestDir).isSameAs(mergeDestDir);
}
}
diff --git a/src/test/java/jscover/report/FileDataTest.java b/src/test/java/jscover/report/FileDataTest.java
index f4300d3c..22fac219 100644
--- a/src/test/java/jscover/report/FileDataTest.java
+++ b/src/test/java/jscover/report/FileDataTest.java
@@ -350,14 +350,14 @@ You should also get your employer (if you work as a programmer) or your
import java.util.TreeMap;
import static java.util.Arrays.asList;
-import static org.hamcrest.CoreMatchers.equalTo;
-import static org.hamcrest.MatcherAssert.assertThat;
+
+import static org.assertj.core.api.Assertions.assertThat;
public class FileDataTest {
@Test
public void shouldReturnUri() {
FileData lineData = new FileData("/test/test.js", null, null, null);
- assertThat(lineData.getUri(), equalTo("/test/test.js"));
+ assertThat(lineData.getUri()).isEqualTo("/test/test.js");
}
@Test
@@ -370,11 +370,11 @@ public void shouldReturnLinesStats() {
lines.add(0);
lines.add(5);
FileData lineData = new FileData("test.js", lines, null, null);
- assertThat(lineData.getCodeLineCount(), equalTo(4));
- assertThat(lineData.getCodeLineCount(), equalTo(4));//Check cache
- assertThat(lineData.getCodeLinesCoveredCount(), equalTo(3));
- assertThat(lineData.getCodeLinesCoveredCount(), equalTo(3));//Check cache
- assertThat(lineData.getLineCoverRate(), equalTo((double)3 / 4));
+ assertThat(lineData.getCodeLineCount()).isEqualTo(4);
+ assertThat(lineData.getCodeLineCount()).isEqualTo(4);//Check cache
+ assertThat(lineData.getCodeLinesCoveredCount()).isEqualTo(3);
+ assertThat(lineData.getCodeLinesCoveredCount()).isEqualTo(3);//Check cache
+ assertThat(lineData.getLineCoverRate()).isEqualTo((double)3 / 4);
}
@Test
@@ -385,14 +385,14 @@ public void shouldReturnFunctionStats() {
functions.add(0);
functions.add(5);
FileData functionData = new FileData("test.js", null, functions, null);
- assertThat(functionData.getCodeFunctionCount(), equalTo(4));
- assertThat(functionData.getCodeFunctionCount(), equalTo(4));//Check cache
- assertThat(functionData.getCodeFunctionCoveredCount(), equalTo(3));
- assertThat(functionData.getCodeFunctionCoveredCount(), equalTo(3));//Check cache
- assertThat(functionData.getFunctionCoverRate(), equalTo((double)3 / 4));
+ assertThat(functionData.getCodeFunctionCount()).isEqualTo(4);
+ assertThat(functionData.getCodeFunctionCount()).isEqualTo(4);//Check cache
+ assertThat(functionData.getCodeFunctionCoveredCount()).isEqualTo(3);
+ assertThat(functionData.getCodeFunctionCoveredCount()).isEqualTo(3);//Check cache
+ assertThat(functionData.getFunctionCoverRate()).isEqualTo((double)3 / 4);
functionData = new FileData("test.js", null, new ArrayList<>(), null);
- assertThat(functionData.getFunctionCoverRate(), equalTo(1.0));
+ assertThat(functionData.getFunctionCoverRate()).isEqualTo(1.0);
}
@Test
@@ -401,11 +401,11 @@ public void shouldReturnBranchStats() {
lines.put(3, asList(null, getBranchData(1, 0), getBranchData(0, 1)));
lines.put(9, asList(null, getBranchData(1, 1)));
FileData lineData = new FileData("test.js", null, null, lines);
- assertThat(lineData.getBranchCount(), equalTo(6));
- assertThat(lineData.getBranchCount(), equalTo(6));//Check cache
- assertThat(lineData.getBranchesCoveredCount(), equalTo(4));
- assertThat(lineData.getBranchesCoveredCount(), equalTo(4));//Check cache
- assertThat(lineData.getBranchRate(), equalTo((double)2 / 3));
+ assertThat(lineData.getBranchCount()).isEqualTo(6);
+ assertThat(lineData.getBranchCount()).isEqualTo(6);//Check cache
+ assertThat(lineData.getBranchesCoveredCount()).isEqualTo(4);
+ assertThat(lineData.getBranchesCoveredCount()).isEqualTo(4);//Check cache
+ assertThat(lineData.getBranchRate()).isEqualTo((double)2 / 3);
}
private BranchData getBranchData(int evalFalse, int evalTrue) {
diff --git a/src/test/java/jscover/report/JSONDataMergerTest.java b/src/test/java/jscover/report/JSONDataMergerTest.java
index 636ea4fa..1c8cb55e 100644
--- a/src/test/java/jscover/report/JSONDataMergerTest.java
+++ b/src/test/java/jscover/report/JSONDataMergerTest.java
@@ -347,9 +347,7 @@ You should also get your employer (if you work as a programmer) or your
import java.util.*;
-import static org.hamcrest.CoreMatchers.equalTo;
-import static org.hamcrest.CoreMatchers.nullValue;
-import static org.hamcrest.MatcherAssert.assertThat;
+import static org.assertj.core.api.Assertions.assertThat;
import static org.junit.jupiter.api.Assertions.assertThrows;
//Function Coverage added by Howard Abrams, CA Technologies (HA-CA) - May 20 2013
@@ -365,7 +363,7 @@ public void shouldMergeData() {
String merged = jsonMerger.toJSON(jsonMerger.mergeJSONCoverageStrings(data1, data2));
- assertThat(merged, equalTo(expected));
+ assertThat(merged).isEqualTo(expected);
}
@Test
@@ -376,7 +374,7 @@ public void shouldMergeBranchData() {
String merged = jsonMerger.toJSON(jsonMerger.mergeJSONCoverageStrings(data1, data2));
- assertThat(merged, equalTo(expected));
+ assertThat(merged).isEqualTo(expected);
}
@Test
@@ -387,7 +385,7 @@ public void shouldMergeFunctionData() {
String merged = jsonMerger.toJSON(jsonMerger.mergeJSONCoverageStrings(data1, data2));
- assertThat(merged, equalTo(expected));
+ assertThat(merged).isEqualTo(expected);
}
@Test
@@ -398,7 +396,7 @@ public void shouldMergeDataWithDifferentFiles() {
String merged = jsonMerger.toJSON(jsonMerger.mergeJSONCoverageStrings(data1, data2));
- assertThat(merged, equalTo(expected));
+ assertThat(merged).isEqualTo(expected);
}
@Test
@@ -406,11 +404,11 @@ public void shouldParseData() {
String data = "{\"/test.js\":{\"lineData\":[null,0,1]}}";
SortedMap map = jsonMerger.jsonToMap(data);
- assertThat(map.keySet().size(), equalTo(1));
- assertThat(map.keySet().iterator().next(), equalTo("/test.js"));
- assertThat(map.values().iterator().next().getLines().get(0), nullValue());
- assertThat(map.values().iterator().next().getLines().get(1), equalTo(0));
- assertThat(map.values().iterator().next().getLines().get(2), equalTo(1));
+ assertThat(map.keySet().size()).isEqualTo(1);
+ assertThat(map.keySet().iterator().next()).isEqualTo("/test.js");
+ assertThat(map.values().iterator().next().getLines().get(0)).isNull();
+ assertThat(map.values().iterator().next().getLines().get(1)).isEqualTo(0);
+ assertThat(map.values().iterator().next().getLines().get(2)).isEqualTo(1);
}
@Test
@@ -419,22 +417,22 @@ public void shouldParseBranchData() {
SortedMap map = jsonMerger.jsonToMap(data);
- assertThat(map.keySet().size(), equalTo(1));
- assertThat(map.keySet().iterator().next(), equalTo("/test.js"));
+ assertThat(map.keySet().size()).isEqualTo(1);
+ assertThat(map.keySet().iterator().next()).isEqualTo("/test.js");
FileData coverageData = map.values().iterator().next();
- assertThat(coverageData.getLines().get(0), nullValue());
-
- assertThat(coverageData.getLines().get(1), equalTo(1));
-
- assertThat(coverageData.getLines().get(2), equalTo(2));
- assertThat(coverageData.getBranchData().size(), equalTo(1));
- assertThat(coverageData.getBranchData().get(2).size(), equalTo(2));
- assertThat(coverageData.getBranchData().get(2).get(0), nullValue());
- assertThat(coverageData.getBranchData().get(2).get(1).getPosition(), equalTo(13));
- assertThat(coverageData.getBranchData().get(2).get(1).getNodeLength(), equalTo(4));
- assertThat(coverageData.getBranchData().get(2).get(1).getEvalFalse(), equalTo(1));
- assertThat(coverageData.getBranchData().get(2).get(1).getEvalTrue(), equalTo(2));
+ assertThat(coverageData.getLines().get(0)).isNull();
+
+ assertThat(coverageData.getLines().get(1)).isEqualTo(1);
+
+ assertThat(coverageData.getLines().get(2)).isEqualTo(2);
+ assertThat(coverageData.getBranchData().size()).isEqualTo(1);
+ assertThat(coverageData.getBranchData().get(2).size()).isEqualTo(2);
+ assertThat(coverageData.getBranchData().get(2).get(0)).isNull();
+ assertThat(coverageData.getBranchData().get(2).get(1).getPosition()).isEqualTo(13);
+ assertThat(coverageData.getBranchData().get(2).get(1).getNodeLength()).isEqualTo(4);
+ assertThat(coverageData.getBranchData().get(2).get(1).getEvalFalse()).isEqualTo(1);
+ assertThat(coverageData.getBranchData().get(2).get(1).getEvalTrue()).isEqualTo(2);
}
@Test
@@ -449,7 +447,7 @@ public void shouldConvertBranchMapToJSONString() {
String jsonString = jsonMerger.toJSON(map);
- assertThat(jsonString, equalTo(data));
+ assertThat(jsonString).isEqualTo(data);
}
@Test
@@ -459,7 +457,7 @@ public void shouldConvertMapToJSONString() {
String jsonString = jsonMerger.toJSON(map);
- assertThat(jsonString, equalTo(data));
+ assertThat(jsonString).isEqualTo(data);
}
@Test
@@ -469,11 +467,11 @@ public void shouldGenerateEmptyCoverageJSONString() {
final ScriptCoverageCount script = new ScriptCoverageCount("/test.js", lines, 0, branchData);
SortedMap map = jsonMerger.createEmptyJSON(new ArrayList(){{add(script);}});
- assertThat(map.keySet().iterator().next(), equalTo("/test.js"));
- assertThat(map.values().iterator().next().getLines().get(0), nullValue());
- assertThat(map.values().iterator().next().getLines().get(1), equalTo(0));
- assertThat(map.values().iterator().next().getLines().get(2), equalTo(0));
- assertThat(map.values().iterator().next().getLines().get(3), equalTo(0));
+ assertThat(map.keySet().iterator().next()).isEqualTo("/test.js");
+ assertThat(map.values().iterator().next().getLines().get(0)).isNull();
+ assertThat(map.values().iterator().next().getLines().get(1)).isEqualTo(0);
+ assertThat(map.values().iterator().next().getLines().get(2)).isEqualTo(0);
+ assertThat(map.values().iterator().next().getLines().get(3)).isEqualTo(0);
}
@Test
@@ -483,8 +481,8 @@ public void shouldGenerateEmptyCoverageJSONStringForEmptyJS() {
final ScriptCoverageCount script = new ScriptCoverageCount("/test.js", lines, 0, branchData);
SortedMap map = jsonMerger.createEmptyJSON(new ArrayList(){{add(script);}});
- assertThat(map.keySet().iterator().next(), equalTo("/test.js"));
- assertThat(map.values().iterator().next().getLines().size(), equalTo(0));
+ assertThat(map.keySet().iterator().next()).isEqualTo("/test.js");
+ assertThat(map.values().iterator().next().getLines().size()).isEqualTo(0);
}
@Test
@@ -493,11 +491,11 @@ public void shouldGenerateEmptyCoverageJSONStringWithComments() {
final ScriptCoverageCount script = new ScriptCoverageCount("/test.js", lines, 0, new TreeMap<>());
SortedMap map = jsonMerger.createEmptyJSON(new ArrayList(){{add(script);}});
- assertThat(map.keySet().iterator().next(), equalTo("/test.js"));
- assertThat(map.values().iterator().next().getLines().get(0), nullValue());
- assertThat(map.values().iterator().next().getLines().get(1), equalTo(0));
- assertThat(map.values().iterator().next().getLines().get(2), nullValue());
- assertThat(map.values().iterator().next().getLines().get(3), equalTo(0));
+ assertThat(map.keySet().iterator().next()).isEqualTo("/test.js");
+ assertThat(map.values().iterator().next().getLines().get(0)).isNull();
+ assertThat(map.values().iterator().next().getLines().get(1)).isEqualTo(0);
+ assertThat(map.values().iterator().next().getLines().get(2)).isNull();
+ assertThat(map.values().iterator().next().getLines().get(3)).isEqualTo(0);
}
@Test
@@ -506,12 +504,12 @@ public void shouldGenerateEmptyCoverageJSONStringWithFunctions() {
final ScriptCoverageCount script = new ScriptCoverageCount("/test.js", lines, 4, new TreeMap<>());
SortedMap map = jsonMerger.createEmptyJSON(new ArrayList(){{add(script);}});
- assertThat(map.keySet().iterator().next(), equalTo("/test.js"));
- assertThat(map.values().iterator().next().getFunctions().size(), equalTo(4));
- assertThat(map.values().iterator().next().getFunctions().get(0), equalTo(0));
- assertThat(map.values().iterator().next().getFunctions().get(1), equalTo(0));
- assertThat(map.values().iterator().next().getFunctions().get(2), equalTo(0));
- assertThat(map.values().iterator().next().getFunctions().get(3), equalTo(0));
+ assertThat(map.keySet().iterator().next()).isEqualTo("/test.js");
+ assertThat(map.values().iterator().next().getFunctions().size()).isEqualTo(4);
+ assertThat(map.values().iterator().next().getFunctions().get(0)).isEqualTo(0);
+ assertThat(map.values().iterator().next().getFunctions().get(1)).isEqualTo(0);
+ assertThat(map.values().iterator().next().getFunctions().get(2)).isEqualTo(0);
+ assertThat(map.values().iterator().next().getFunctions().get(3)).isEqualTo(0);
}
@Test
@@ -522,18 +520,18 @@ public void shouldGenerateEmptyCoverageJSONStringWithBranchData() {
final ScriptCoverageCount script = new ScriptCoverageCount("/test.js", lines, 4, branchData);
SortedMap map = jsonMerger.createEmptyJSON(new ArrayList(){{add(script);}});
- assertThat(map.keySet().iterator().next(), equalTo("/test.js"));
+ assertThat(map.keySet().iterator().next()).isEqualTo("/test.js");
Map> branchMap = map.values().iterator().next().getBranchData();
- assertThat(branchMap.size(), equalTo(1));
- assertThat(branchMap.get(5), nullValue());
- assertThat(branchMap.get(12).size(), equalTo(3));
- assertThat(branchMap.get(12).get(0), nullValue());
+ assertThat(branchMap.size()).isEqualTo(1);
+ assertThat(branchMap.get(5)).isNull();
+ assertThat(branchMap.get(12).size()).isEqualTo(3);
+ assertThat(branchMap.get(12).get(0)).isNull();
checkCondition(branchMap, 1);
checkCondition(branchMap, 2);
}
private void checkCondition(Map> branchMap, int index) {
- assertThat(branchMap.get(12).get(index).getEvalFalse(), equalTo(0));
- assertThat(branchMap.get(12).get(index).getEvalTrue(), equalTo(0));
+ assertThat(branchMap.get(12).get(index).getEvalFalse()).isEqualTo(0);
+ assertThat(branchMap.get(12).get(index).getEvalTrue()).isEqualTo(0);
}
}
diff --git a/src/test/java/jscover/report/JSONDataSaverTest.java b/src/test/java/jscover/report/JSONDataSaverTest.java
index 730244b5..8000bcf4 100644
--- a/src/test/java/jscover/report/JSONDataSaverTest.java
+++ b/src/test/java/jscover/report/JSONDataSaverTest.java
@@ -360,8 +360,7 @@ You should also get your employer (if you work as a programmer) or your
import java.util.SortedMap;
import java.util.TreeMap;
-import static org.hamcrest.CoreMatchers.equalTo;
-import static org.hamcrest.MatcherAssert.assertThat;
+import static org.assertj.core.api.Assertions.assertThat;
import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.mockito.ArgumentMatchers.argThat;
import static org.mockito.BDDMockito.given;
@@ -392,7 +391,7 @@ public void shouldSaveData() {
jsonDataSaver.saveJSONData(destDir, "data", null, uriFileTranslator);
String json = ioUtils.loadFromFileSystem(new File(destDir, "jscoverage.json"));
- assertThat(json, equalTo("data"));
+ assertThat(json).isEqualTo("data");
}
@Test
@@ -410,7 +409,7 @@ public void shouldSaveDataWithTranslatedUris() {
jsonDataSaver.saveJSONData(destDir, data, null, uriFileTranslator);
String json = ioUtils.loadFromFileSystem(new File(destDir, "jscoverage.json"));
- assertThat(json, equalTo("dataTranslated"));
+ assertThat(json).isEqualTo("dataTranslated");
}
@Test
@@ -440,8 +439,8 @@ public void shouldSaveDataAfterFirstThread() throws InterruptedException {
thread.join();
String json = ioUtils.loadFromFileSystem(new File(destDir, "jscoverage.json"));
- assertThat(json, equalTo("data"));
- assertThat(sb.toString(), equalTo("1243"));
+ assertThat(json).isEqualTo("data");
+ assertThat(sb.toString()).isEqualTo("1243");
}
@Test
@@ -477,7 +476,7 @@ public void shouldSaveAndMergeData() {
jsonDataSaver.saveJSONData(destDir, "json2", null, uriFileTranslator);
String json = ioUtils.loadFromFileSystem(jsonFile);
- assertThat(json, equalTo("jsonMerged"));
+ assertThat(json).isEqualTo("jsonMerged");
}
@Test
@@ -501,7 +500,7 @@ public void shouldSaveAndMergeDataWithTranslatedUris() {
jsonDataSaver.saveJSONData(destDir, "jsonSubmitted", null, uriFileTranslator);
String json = ioUtils.loadFromFileSystem(jsonFile);
- assertThat(json, equalTo("jsonMerged"));
+ assertThat(json).isEqualTo("jsonMerged");
}
ArgumentMatcher> isMapWithKey(final String url) {
@@ -529,7 +528,7 @@ public void shouldSaveAndIncludeUnloadedJS() {
jsonDataSaver.saveJSONData(destDir, "json1", unloadJSData, uriFileTranslator);
String json = ioUtils.loadFromFileSystem(jsonFile);
- assertThat(json, equalTo("jsonMerged"));
+ assertThat(json).isEqualTo("jsonMerged");
}
@Test
@@ -555,7 +554,7 @@ public void shouldSaveAndIncludeUnloadedJSWithTranslatedUris() {
jsonDataSaver.saveJSONData(destDir, "json1", unloadJSData, uriFileTranslator);
String json = ioUtils.loadFromFileSystem(jsonFile);
- assertThat(json, equalTo("jsonMerged"));
+ assertThat(json).isEqualTo("jsonMerged");
}
ArgumentMatcher> isMapWithKeys(final String url1, final String url2) {
diff --git a/src/test/java/jscover/report/MainTest.java b/src/test/java/jscover/report/MainTest.java
index bb66524e..b55c1b63 100644
--- a/src/test/java/jscover/report/MainTest.java
+++ b/src/test/java/jscover/report/MainTest.java
@@ -343,7 +343,6 @@ You should also get your employer (if you work as a programmer) or your
package jscover.report;
import jscover.ExitHelper;
-import jscover.report.coberturaxml.CoberturaData;
import jscover.report.coberturaxml.CoberturaXmlGenerator;
import jscover.report.lcov.LCovGenerator;
import jscover.report.xml.XMLSummary;
@@ -351,8 +350,6 @@ You should also get your employer (if you work as a programmer) or your
import jscover.util.IoUtils;
import jscover.util.ReflectionUtils;
import org.apache.commons.io.FileUtils;
-import org.hamcrest.Description;
-import org.hamcrest.TypeSafeMatcher;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
@@ -369,12 +366,9 @@ You should also get your employer (if you work as a programmer) or your
import java.util.TreeMap;
import static jscover.Main.reportSrcSubDir;
-import static org.hamcrest.CoreMatchers.is;
-import static org.hamcrest.CoreMatchers.sameInstance;
-import static org.hamcrest.MatcherAssert.assertThat;
+import static org.assertj.core.api.Assertions.assertThat;
import static org.mockito.BDDMockito.given;
import static org.mockito.Mockito.*;
-import static org.mockito.hamcrest.MockitoHamcrest.argThat;
//Function Coverage added by Howard Abrams, CA Technologies (HA-CA) - May 20 2013
@ExtendWith(MockitoExtension.class)
@@ -413,7 +407,7 @@ public void shouldExitIfInvalid() throws IOException {
public void shouldSetConfig() {
ConfigurationForReport configuration = mock(ConfigurationForReport.class);
main.setConfig(configuration);
- assertThat(ReflectionUtils.getField(main, "config"), sameInstance(configuration));
+ assertThat(ReflectionUtils.getField(main, "config")).isSameAs(configuration);
}
@Test
@@ -467,20 +461,12 @@ public void shouldRunCoberturaXmlReport() throws IOException {
main.runMain(new String[]{});
- TypeSafeMatcher coberturaDataMatcher = new TypeSafeMatcher() {
- @Override
- protected boolean matchesSafely(CoberturaData coverable) {
- return true;
- }
-
- public void describeTo(Description description) {
-
- }
- };
-
-
File xmlFile = new File(jsonDirectory, "cobertura-coverage.xml");
- verify(coberturaXmlGenerator).generateXml(argThat(coberturaDataMatcher), argThat(is(srcDir.getCanonicalPath())), argThat(is("version")));
+ verify(coberturaXmlGenerator).generateXml(
+ argThat(argument -> true),
+ eq(srcDir.getCanonicalPath()),
+ eq("version")
+ );
verify(ioUtils).copy("", xmlFile);
verifyNoInteractions(exitHelper);
}
@@ -504,29 +490,11 @@ public void shouldRunXMLSummaryReport() throws IOException {
main.runMain(new String[]{});
- TypeSafeMatcher fileMatcher = new TypeSafeMatcher() {
- @Override
- protected boolean matchesSafely(File file) {
- return file.equals(jsonDirectory);
- }
-
- public void describeTo(Description description) {
-
- }
- };
-
- TypeSafeMatcher coverableMatcher = new TypeSafeMatcher() {
- @Override
- protected boolean matchesSafely(Coverable coverable) {
- return coverable.getCodeLineCount() == 42;
- }
-
- public void describeTo(Description description) {
-
- }
- };
-
- verify(xmlSummary).saveSummary(argThat(coverableMatcher), argThat(fileMatcher), argThat(is("version")));
+ verify(xmlSummary).saveSummary(
+ argThat(c -> c.getCodeLineCount() == 42),
+ eq(jsonDirectory),
+ eq("version")
+ );
verifyNoInteractions(exitHelper);
}
@@ -569,7 +537,7 @@ private void testMergeLogic(boolean hasOriginalSrc) throws IOException {
given(jsonDataMerger.jsonToMap("json1")).willReturn(map1);
given(jsonDataMerger.jsonToMap("json2")).willReturn(map2);
given(jsonDataMerger.mergeJSONCoverageMaps(mergedMapTemp, map2)).willReturn(mergedMap);
- given(jsonDataMerger.toJSON(argThat(sameInstance(mergedMap)))).willReturn("mergedJSON");
+ given(jsonDataMerger.toJSON(same(mergedMap))).willReturn("mergedJSON");
main.runMain(new String[]{});
@@ -592,17 +560,4 @@ private void testMergeLogic(boolean hasOriginalSrc) throws IOException {
verifyNoInteractions(exitHelper);
}
-
- private TypeSafeMatcher> getTypeSafeMatcher() {
- return new TypeSafeMatcher>() {
- public void describeTo(Description description) {
-
- }
-
- @Override
- protected boolean matchesSafely(SortedMap item) {
- return true;
- }
- };
- }
}
diff --git a/src/test/java/jscover/report/SummaryDataTest.java b/src/test/java/jscover/report/SummaryDataTest.java
index c46989df..03f60b77 100644
--- a/src/test/java/jscover/report/SummaryDataTest.java
+++ b/src/test/java/jscover/report/SummaryDataTest.java
@@ -350,8 +350,7 @@ You should also get your employer (if you work as a programmer) or your
import java.util.ArrayList;
import java.util.List;
-import static org.hamcrest.CoreMatchers.equalTo;
-import static org.hamcrest.MatcherAssert.assertThat;
+import static org.assertj.core.api.Assertions.assertThat;
import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.mockito.BDDMockito.given;
@@ -380,9 +379,9 @@ public void shouldAddLineStatistics() {
SummaryData summaryData = new SummaryData(files);
- assertThat(summaryData.getCodeLineCount(), equalTo(10));
- assertThat(summaryData.getCodeLinesCoveredCount(), equalTo(7));
- assertThat(summaryData.getLineCoverRate(), equalTo((double)7/10));
+ assertThat(summaryData.getCodeLineCount()).isEqualTo(10);
+ assertThat(summaryData.getCodeLinesCoveredCount()).isEqualTo(7);
+ assertThat(summaryData.getLineCoverRate()).isEqualTo((double)7/10);
}
@Test
@@ -398,9 +397,9 @@ public void shouldAddBranchStatistics() {
SummaryData summaryData = new SummaryData(files);
- assertThat(summaryData.getBranchCount(), equalTo(10));
- assertThat(summaryData.getBranchesCoveredCount(), equalTo(7));
- assertThat(summaryData.getBranchRate(), equalTo((double)7/10));
+ assertThat(summaryData.getBranchCount()).isEqualTo(10);
+ assertThat(summaryData.getBranchesCoveredCount()).isEqualTo(7);
+ assertThat(summaryData.getBranchRate()).isEqualTo((double)7/10);
}
@Test
@@ -416,8 +415,8 @@ public void shouldAddFunctionStatistics() {
SummaryData summaryData = new SummaryData(files);
- assertThat(summaryData.getCodeFunctionCount(), equalTo(10));
- assertThat(summaryData.getCodeFunctionCoveredCount(), equalTo(7));
- assertThat(summaryData.getFunctionCoverRate(), equalTo((double)7/10));
+ assertThat(summaryData.getCodeFunctionCount()).isEqualTo(10);
+ assertThat(summaryData.getCodeFunctionCoveredCount()).isEqualTo(7);
+ assertThat(summaryData.getFunctionCoverRate()).isEqualTo((double)7/10);
}
}
diff --git a/src/test/java/jscover/report/coberturaxml/CoberturaDataTest.java b/src/test/java/jscover/report/coberturaxml/CoberturaDataTest.java
index 83f2f771..66dd3301 100644
--- a/src/test/java/jscover/report/coberturaxml/CoberturaDataTest.java
+++ b/src/test/java/jscover/report/coberturaxml/CoberturaDataTest.java
@@ -351,8 +351,7 @@ You should also get your employer (if you work as a programmer) or your
import java.util.ArrayList;
import java.util.List;
-import static org.hamcrest.CoreMatchers.equalTo;
-import static org.hamcrest.MatcherAssert.assertThat;
+import static org.assertj.core.api.Assertions.assertThat;
import static org.mockito.BDDMockito.given;
@ExtendWith(MockitoExtension.class)
@@ -364,11 +363,11 @@ public class CoberturaDataTest {
public void shouldExtractPackage() {
CoberturaData data = new CoberturaData(new ArrayList<>());
- assertThat(data.getPackage(null), equalTo(""));
- assertThat(data.getPackage("test.js"), equalTo(""));
- assertThat(data.getPackage("/test.js"), equalTo(""));
- assertThat(data.getPackage("/level1/test.js"), equalTo("/level1"));
- assertThat(data.getPackage("/level1/level2/test.js"), equalTo("/level1/level2"));
+ assertThat(data.getPackage(null)).isEqualTo("");
+ assertThat(data.getPackage("test.js")).isEqualTo("");
+ assertThat(data.getPackage("/test.js")).isEqualTo("");
+ assertThat(data.getPackage("/level1/test.js")).isEqualTo("/level1");
+ assertThat(data.getPackage("/level1/level2/test.js")).isEqualTo("/level1/level2");
}
@Test
@@ -384,9 +383,9 @@ public void shouldAddLineStatistics() {
CoberturaData data = new CoberturaData(files);
- assertThat(data.getCodeLineCount(), equalTo(10));
- assertThat(data.getCodeLinesCoveredCount(), equalTo(7));
- assertThat(data.getLineCoverRate(), equalTo((double)7/10));
+ assertThat(data.getCodeLineCount()).isEqualTo(10);
+ assertThat(data.getCodeLinesCoveredCount()).isEqualTo(7);
+ assertThat(data.getLineCoverRate()).isEqualTo((double)7/10);
}
@Test
@@ -402,8 +401,8 @@ public void shouldAddBranchStatistics() {
CoberturaData data = new CoberturaData(files);
- assertThat(data.getBranchCount(), equalTo(10));
- assertThat(data.getBranchesCoveredCount(), equalTo(7));
- assertThat(data.getBranchRate(), equalTo((double)7/10));
+ assertThat(data.getBranchCount()).isEqualTo(10);
+ assertThat(data.getBranchesCoveredCount()).isEqualTo(7);
+ assertThat(data.getBranchRate()).isEqualTo((double)7/10);
}
}
diff --git a/src/test/java/jscover/report/coberturaxml/CoberturaXmlGeneratorTest.java b/src/test/java/jscover/report/coberturaxml/CoberturaXmlGeneratorTest.java
index c79d2b68..d3caf6f8 100644
--- a/src/test/java/jscover/report/coberturaxml/CoberturaXmlGeneratorTest.java
+++ b/src/test/java/jscover/report/coberturaxml/CoberturaXmlGeneratorTest.java
@@ -361,8 +361,7 @@ You should also get your employer (if you work as a programmer) or your
import java.io.IOException;
import java.util.*;
-import static org.hamcrest.MatcherAssert.assertThat;
-import static org.hamcrest.Matchers.equalTo;
+import static org.assertj.core.api.Assertions.assertThat;
import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.mockito.BDDMockito.given;
import static org.mockito.Mockito.mock;
@@ -384,8 +383,8 @@ public void shouldGenerateXmlSourceAndVersion() throws Exception {
Document document = parseXml(xml);
XPath xpath = XPathFactory.newInstance().newXPath();
- assertThat(getXPath(xpath, document, "/coverage/@version"), equalTo("version"));
- assertThat(getXPath(xpath, document, "/coverage/sources/source"), equalTo("c:/sourceDir"));
+ assertThat(getXPath(xpath, document, "/coverage/@version")).isEqualTo("version");
+ assertThat(getXPath(xpath, document, "/coverage/sources/source")).isEqualTo("c:/sourceDir");
}
@Test
@@ -407,27 +406,27 @@ public void shouldGenerateXmlForOneFile() throws Exception {
Document document = parseXml(xml);
XPath xpath = XPathFactory.newInstance().newXPath();
- assertThat(getXPath(xpath, document, "/coverage/@line-rate"), equalTo("0.5"));
- assertThat(getXPath(xpath, document, "/coverage/@branch-rate"), equalTo("0.4"));
- assertThat(getXPath(xpath, document, "/coverage/@lines-covered"), equalTo("5"));
- assertThat(getXPath(xpath, document, "/coverage/@lines-valid"), equalTo("10"));
- assertThat(getXPath(xpath, document, "/coverage/@branches-covered"), equalTo("2"));
- assertThat(getXPath(xpath, document, "/coverage/@branches-valid"), equalTo("5"));
+ assertThat(getXPath(xpath, document, "/coverage/@line-rate")).isEqualTo("0.5");
+ assertThat(getXPath(xpath, document, "/coverage/@branch-rate")).isEqualTo("0.4");
+ assertThat(getXPath(xpath, document, "/coverage/@lines-covered")).isEqualTo("5");
+ assertThat(getXPath(xpath, document, "/coverage/@lines-valid")).isEqualTo("10");
+ assertThat(getXPath(xpath, document, "/coverage/@branches-covered")).isEqualTo("2");
+ assertThat(getXPath(xpath, document, "/coverage/@branches-valid")).isEqualTo("5");
//Check package
- assertThat(getXPath(xpath, document, "count(/coverage/packages/package)"), equalTo("1"));
+ assertThat(getXPath(xpath, document, "count(/coverage/packages/package)")).isEqualTo("1");
String packageXPath = "/coverage/packages/package[@name='/dir']";
- assertThat(getXPath(xpath, document, packageXPath + "/@name"), equalTo("/dir"));
- assertThat(getXPath(xpath, document, packageXPath + "/@complexity"), equalTo("0"));
- assertThat(getXPath(xpath, document, packageXPath + "/@line-rate"), equalTo("0.5"));
- assertThat(getXPath(xpath, document, packageXPath + "/@branch-rate"), equalTo("0.4"));
+ assertThat(getXPath(xpath, document, packageXPath + "/@name")).isEqualTo("/dir");
+ assertThat(getXPath(xpath, document, packageXPath + "/@complexity")).isEqualTo("0");
+ assertThat(getXPath(xpath, document, packageXPath + "/@line-rate")).isEqualTo("0.5");
+ assertThat(getXPath(xpath, document, packageXPath + "/@branch-rate")).isEqualTo("0.4");
//Check class
String classXPath = packageXPath + "/classes/class[@name='/dir/file.js']";
- assertThat(getXPath(xpath, document, classXPath + "/@branch-rate"), equalTo("0.4"));
- assertThat(getXPath(xpath, document, classXPath + "/@line-rate"), equalTo("0.5"));
- assertThat(getXPath(xpath, document, classXPath + "/@complexity"), equalTo("0"));
- assertThat(getXPath(xpath, document, classXPath + "/@filename"), equalTo("dir/file.js"));
+ assertThat(getXPath(xpath, document, classXPath + "/@branch-rate")).isEqualTo("0.4");
+ assertThat(getXPath(xpath, document, classXPath + "/@line-rate")).isEqualTo("0.5");
+ assertThat(getXPath(xpath, document, classXPath + "/@complexity")).isEqualTo("0");
+ assertThat(getXPath(xpath, document, classXPath + "/@filename")).isEqualTo("dir/file.js");
}
@Test
@@ -459,20 +458,20 @@ public void shouldGenerateXmlForTwoFiles() throws Exception {
Document document = parseXml(xml);
XPath xpath = XPathFactory.newInstance().newXPath();
- assertThat(getXPath(xpath, document, "/coverage/@line-rate"), equalTo("0.6"));
- assertThat(getXPath(xpath, document, "/coverage/@branch-rate"), equalTo("0.7"));
- assertThat(getXPath(xpath, document, "/coverage/@lines-covered"), equalTo("6"));
- assertThat(getXPath(xpath, document, "/coverage/@lines-valid"), equalTo("10"));
- assertThat(getXPath(xpath, document, "/coverage/@branches-covered"), equalTo("7"));
- assertThat(getXPath(xpath, document, "/coverage/@branches-valid"), equalTo("10"));
+ assertThat(getXPath(xpath, document, "/coverage/@line-rate")).isEqualTo("0.6");
+ assertThat(getXPath(xpath, document, "/coverage/@branch-rate")).isEqualTo("0.7");
+ assertThat(getXPath(xpath, document, "/coverage/@lines-covered")).isEqualTo("6");
+ assertThat(getXPath(xpath, document, "/coverage/@lines-valid")).isEqualTo("10");
+ assertThat(getXPath(xpath, document, "/coverage/@branches-covered")).isEqualTo("7");
+ assertThat(getXPath(xpath, document, "/coverage/@branches-valid")).isEqualTo("10");
//Check package
- assertThat(getXPath(xpath, document, "count(/coverage/packages/package)"), equalTo("1"));
+ assertThat(getXPath(xpath, document, "count(/coverage/packages/package)")).isEqualTo("1");
String packageXPath = "/coverage/packages/package[@name='/dir']";
- assertThat(getXPath(xpath, document, packageXPath + "/@name"), equalTo("/dir"));
- assertThat(getXPath(xpath, document, packageXPath + "/@complexity"), equalTo("0"));
- assertThat(getXPath(xpath, document, packageXPath + "/@line-rate"), equalTo("0.6"));
- assertThat(getXPath(xpath, document, packageXPath + "/@branch-rate"), equalTo("0.7"));
+ assertThat(getXPath(xpath, document, packageXPath + "/@name")).isEqualTo("/dir");
+ assertThat(getXPath(xpath, document, packageXPath + "/@complexity")).isEqualTo("0");
+ assertThat(getXPath(xpath, document, packageXPath + "/@line-rate")).isEqualTo("0.6");
+ assertThat(getXPath(xpath, document, packageXPath + "/@branch-rate")).isEqualTo("0.7");
}
@Test
@@ -487,10 +486,10 @@ public void shouldGenerateXmlLineNoBranch() throws Exception {
Document document = parseXml(xml);
XPath xpath = XPathFactory.newInstance().newXPath();
- assertThat(getXPath(xpath, document, "count(//line)"), equalTo("1"));
- assertThat(getXPath(xpath, document, "//line/@number"), equalTo("1"));
- assertThat(getXPath(xpath, document, "//line/@hits"), equalTo("10"));
- assertThat(getXPath(xpath, document, "//line/@branch"), equalTo("false"));
+ assertThat(getXPath(xpath, document, "count(//line)")).isEqualTo("1");
+ assertThat(getXPath(xpath, document, "//line/@number")).isEqualTo("1");
+ assertThat(getXPath(xpath, document, "//line/@hits")).isEqualTo("10");
+ assertThat(getXPath(xpath, document, "//line/@branch")).isEqualTo("false");
}
@Test
@@ -509,16 +508,16 @@ public void shouldGenerateXmlBranchNoLine() throws Exception {
Document document = parseXml(xml);
XPath xpath = XPathFactory.newInstance().newXPath();
- assertThat(getXPath(xpath, document, "count(//line)"), equalTo("1"));
- assertThat(getXPath(xpath, document, "//line/@number"), equalTo("1"));
- assertThat(getXPath(xpath, document, "//line/@hits"), equalTo("1"));
- assertThat(getXPath(xpath, document, "//line/@branch"), equalTo("true"));
- assertThat(getXPath(xpath, document, "//line/@condition-coverage"), equalTo("50% (1/2)"));
-
- assertThat(getXPath(xpath, document, "count(//condition)"), equalTo("1"));
- assertThat(getXPath(xpath, document, "//condition/@coverage"), equalTo("50%"));
- assertThat(getXPath(xpath, document, "//condition/@number"), equalTo("1"));
- assertThat(getXPath(xpath, document, "//condition/@type"), equalTo("jump"));
+ assertThat(getXPath(xpath, document, "count(//line)")).isEqualTo("1");
+ assertThat(getXPath(xpath, document, "//line/@number")).isEqualTo("1");
+ assertThat(getXPath(xpath, document, "//line/@hits")).isEqualTo("1");
+ assertThat(getXPath(xpath, document, "//line/@branch")).isEqualTo("true");
+ assertThat(getXPath(xpath, document, "//line/@condition-coverage")).isEqualTo("50% (1/2)");
+
+ assertThat(getXPath(xpath, document, "count(//condition)")).isEqualTo("1");
+ assertThat(getXPath(xpath, document, "//condition/@coverage")).isEqualTo("50%");
+ assertThat(getXPath(xpath, document, "//condition/@number")).isEqualTo("1");
+ assertThat(getXPath(xpath, document, "//condition/@type")).isEqualTo("jump");
}
@Test
@@ -537,16 +536,16 @@ public void shouldGenerateXmlLineAndBranch() throws Exception {
Document document = parseXml(xml);
XPath xpath = XPathFactory.newInstance().newXPath();
- assertThat(getXPath(xpath, document, "count(//line)"), equalTo("1"));
- assertThat(getXPath(xpath, document, "//line/@number"), equalTo("1"));
- assertThat(getXPath(xpath, document, "//line/@hits"), equalTo("1"));
- assertThat(getXPath(xpath, document, "//line/@branch"), equalTo("true"));
- assertThat(getXPath(xpath, document, "//line/@condition-coverage"), equalTo("50% (1/2)"));
-
- assertThat(getXPath(xpath, document, "count(//condition)"), equalTo("1"));
- assertThat(getXPath(xpath, document, "//condition/@coverage"), equalTo("50%"));
- assertThat(getXPath(xpath, document, "//condition/@number"), equalTo("1"));
- assertThat(getXPath(xpath, document, "//condition/@type"), equalTo("jump"));
+ assertThat(getXPath(xpath, document, "count(//line)")).isEqualTo("1");
+ assertThat(getXPath(xpath, document, "//line/@number")).isEqualTo("1");
+ assertThat(getXPath(xpath, document, "//line/@hits")).isEqualTo("1");
+ assertThat(getXPath(xpath, document, "//line/@branch")).isEqualTo("true");
+ assertThat(getXPath(xpath, document, "//line/@condition-coverage")).isEqualTo("50% (1/2)");
+
+ assertThat(getXPath(xpath, document, "count(//condition)")).isEqualTo("1");
+ assertThat(getXPath(xpath, document, "//condition/@coverage")).isEqualTo("50%");
+ assertThat(getXPath(xpath, document, "//condition/@number")).isEqualTo("1");
+ assertThat(getXPath(xpath, document, "//condition/@type")).isEqualTo("jump");
}
@Test
@@ -565,16 +564,16 @@ public void shouldGenerateXmlBranchNoLineNoHit() throws Exception {
Document document = parseXml(xml);
XPath xpath = XPathFactory.newInstance().newXPath();
- assertThat(getXPath(xpath, document, "count(//line)"), equalTo("1"));
- assertThat(getXPath(xpath, document, "//line/@number"), equalTo("1"));
- assertThat(getXPath(xpath, document, "//line/@hits"), equalTo("0"));
- assertThat(getXPath(xpath, document, "//line/@branch"), equalTo("true"));
- assertThat(getXPath(xpath, document, "//line/@condition-coverage"), equalTo("0% (0/2)"));
-
- assertThat(getXPath(xpath, document, "count(//condition)"), equalTo("1"));
- assertThat(getXPath(xpath, document, "//condition/@coverage"), equalTo("0%"));
- assertThat(getXPath(xpath, document, "//condition/@number"), equalTo("1"));
- assertThat(getXPath(xpath, document, "//condition/@type"), equalTo("jump"));
+ assertThat(getXPath(xpath, document, "count(//line)")).isEqualTo("1");
+ assertThat(getXPath(xpath, document, "//line/@number")).isEqualTo("1");
+ assertThat(getXPath(xpath, document, "//line/@hits")).isEqualTo("0");
+ assertThat(getXPath(xpath, document, "//line/@branch")).isEqualTo("true");
+ assertThat(getXPath(xpath, document, "//line/@condition-coverage")).isEqualTo("0% (0/2)");
+
+ assertThat(getXPath(xpath, document, "count(//condition)")).isEqualTo("1");
+ assertThat(getXPath(xpath, document, "//condition/@coverage")).isEqualTo("0%");
+ assertThat(getXPath(xpath, document, "//condition/@number")).isEqualTo("1");
+ assertThat(getXPath(xpath, document, "//condition/@type")).isEqualTo("jump");
}
public static Document parseXml(String xml) throws ParserConfigurationException, SAXException, IOException {
diff --git a/src/test/java/jscover/report/lcov/LCovGeneratorTest.java b/src/test/java/jscover/report/lcov/LCovGeneratorTest.java
index 56642b0d..535297e9 100644
--- a/src/test/java/jscover/report/lcov/LCovGeneratorTest.java
+++ b/src/test/java/jscover/report/lcov/LCovGeneratorTest.java
@@ -352,8 +352,8 @@ You should also get your employer (if you work as a programmer) or your
import java.util.TreeMap;
import static java.util.Arrays.asList;
-import static org.hamcrest.CoreMatchers.equalTo;
-import static org.hamcrest.MatcherAssert.assertThat;
+
+import static org.assertj.core.api.Assertions.assertThat;
//Function Coverage added by Howard Abrams, CA Technologies (HA-CA) - May 20 2013
public class LCovGeneratorTest {
@@ -400,7 +400,7 @@ public void shouldGenerateLcovDataForFile() {
"DA:4,0\n" +
"DA:5,5\n" +
"end_of_record\n";
- assertThat(result, equalTo(expected));
+ assertThat(result).isEqualTo(expected);
}
private BranchData getBranchData(int evalFalse, int evalTrue) {
diff --git a/src/test/java/jscover/report/xml/XMLSummaryTest.java b/src/test/java/jscover/report/xml/XMLSummaryTest.java
index 2dd1d246..284606f5 100644
--- a/src/test/java/jscover/report/xml/XMLSummaryTest.java
+++ b/src/test/java/jscover/report/xml/XMLSummaryTest.java
@@ -358,8 +358,7 @@ You should also get your employer (if you work as a programmer) or your
import java.io.ByteArrayInputStream;
import java.util.Locale;
-import static org.hamcrest.CoreMatchers.equalTo;
-import static org.hamcrest.MatcherAssert.assertThat;
+import static org.assertj.core.api.Assertions.assertThat;
import static org.mockito.BDDMockito.given;
@ExtendWith(MockitoExtension.class)
@@ -386,13 +385,13 @@ public void shouldGenerateSummaryXML() throws Exception {
DocumentBuilder builder = DocumentBuilderFactory.newInstance().newDocumentBuilder();
Document document = builder.parse(new ByteArrayInputStream(xml.getBytes()));
- assertThat(getXPath(xpath, document, "/coverage/@line-rate"), equalTo("0.333333"));
- assertThat(getXPath(xpath, document, "/coverage/@branch-rate"), equalTo("0.666667"));
- assertThat(getXPath(xpath, document, "/coverage/@lines-covered"), equalTo("2"));
- assertThat(getXPath(xpath, document, "/coverage/@lines"), equalTo("1"));
- assertThat(getXPath(xpath, document, "/coverage/@branches-covered"), equalTo("5"));
- assertThat(getXPath(xpath, document, "/coverage/@branches"), equalTo("4"));
- assertThat(getXPath(xpath, document, "/coverage/@version"), equalTo("theVersion"));
+ assertThat(getXPath(xpath, document, "/coverage/@line-rate")).isEqualTo("0.333333");
+ assertThat(getXPath(xpath, document, "/coverage/@branch-rate")).isEqualTo("0.666667");
+ assertThat(getXPath(xpath, document, "/coverage/@lines-covered")).isEqualTo("2");
+ assertThat(getXPath(xpath, document, "/coverage/@lines")).isEqualTo("1");
+ assertThat(getXPath(xpath, document, "/coverage/@branches-covered")).isEqualTo("5");
+ assertThat(getXPath(xpath, document, "/coverage/@branches")).isEqualTo("4");
+ assertThat(getXPath(xpath, document, "/coverage/@version")).isEqualTo("theVersion");
}
private String getXPath(XPath xpath, Document document, String expression) throws Exception {
diff --git a/src/test/java/jscover/server/ConfigurationForServerTest.java b/src/test/java/jscover/server/ConfigurationForServerTest.java
index a4b013e3..de68889c 100644
--- a/src/test/java/jscover/server/ConfigurationForServerTest.java
+++ b/src/test/java/jscover/server/ConfigurationForServerTest.java
@@ -352,29 +352,28 @@ You should also get your employer (if you work as a programmer) or your
import static com.google.javascript.jscomp.CompilerOptions.LanguageMode.ECMASCRIPT_NEXT;
import static java.util.logging.Level.FINE;
import static java.util.logging.Level.SEVERE;
-import static org.hamcrest.MatcherAssert.assertThat;
-import static org.hamcrest.Matchers.*;
+import static org.assertj.core.api.Assertions.assertThat;
public class ConfigurationForServerTest {
@Test
public void shouldHaveDefaults() {
ConfigurationForServer configuration = ConfigurationForServer.parse(new String[]{});
- assertThat(configuration.showHelp(), is(false));
- assertThat(configuration.isInvalid(), is(false));
- assertThat(configuration.getDocumentRoot().toString(), equalTo(System.getProperty("user.dir")));
- assertThat(configuration.getPort(), equalTo(8080));
- assertThat(configuration.getReportDir(), is(new File(System.getProperty("user.dir"))));
- assertThat(configuration.getECMAVersion(), equalTo(ECMASCRIPT_NEXT));
- assertThat(configuration.skipInstrumentation("/"), is(false));
- assertThat(configuration.isProxy(), is(false));
- assertThat(configuration.isSaveJSONOnly(), is(false));
- assertThat(configuration.isIncludeBranch(), is(true));
- assertThat(configuration.isIncludeFunction(), is(true));
- assertThat(configuration.getUriToFileMatcher(), nullValue());
- assertThat(configuration.getUriToFileReplace(), nullValue());
- assertThat(configuration.getUriFileTranslator(), instanceOf(UriFileTranslatorNoOp.class));
- assertThat(configuration.getLogLevel(), is(SEVERE));
+ assertThat(configuration.showHelp()).isFalse();
+ assertThat(configuration.isInvalid()).isFalse();
+ assertThat(configuration.getDocumentRoot().toString()).isEqualTo(System.getProperty("user.dir"));
+ assertThat(configuration.getPort()).isEqualTo(8080);
+ assertThat(configuration.getReportDir()).isEqualTo(new File(System.getProperty("user.dir")));
+ assertThat(configuration.getECMAVersion()).isEqualTo(ECMASCRIPT_NEXT);
+ assertThat(configuration.skipInstrumentation("/")).isFalse();
+ assertThat(configuration.isProxy()).isFalse();
+ assertThat(configuration.isSaveJSONOnly()).isFalse();
+ assertThat(configuration.isIncludeBranch()).isTrue();
+ assertThat(configuration.isIncludeFunction()).isTrue();
+ assertThat(configuration.getUriToFileMatcher()).isNull();
+ assertThat(configuration.getUriToFileReplace()).isNull();
+ assertThat(configuration.getUriFileTranslator()).isInstanceOf(UriFileTranslatorNoOp.class);
+ assertThat(configuration.getLogLevel()).isEqualTo(SEVERE);
}
@Test
@@ -387,219 +386,219 @@ public void shouldSetValues() {
configuration.setReportDir(reportDir);
configuration.setProxy(true);
- assertThat(configuration.getDocumentRoot(), sameInstance(dir));
- assertThat(configuration.getPort(), is(1234));
- assertThat(configuration.getReportDir(), sameInstance(reportDir));
- assertThat(configuration.isProxy(), is(true));
+ assertThat(configuration.getDocumentRoot()).isSameAs(dir);
+ assertThat(configuration.getPort()).isEqualTo(1234);
+ assertThat(configuration.getReportDir()).isSameAs(reportDir);
+ assertThat(configuration.isProxy()).isTrue();
}
@Test
public void shouldIgnoreServerSwitch() {
ConfigurationForServer configuration = ConfigurationForServer.parse(new String[]{"-ws"});
- assertThat(configuration.showHelp(), is(false));
- assertThat(configuration.getDocumentRoot().toString(), equalTo(System.getProperty("user.dir")));
- assertThat(configuration.getPort(), equalTo(8080));
- assertThat(configuration.isProxy(), is(false));
- assertThat(configuration.getECMAVersion(), equalTo(ECMASCRIPT_NEXT));
- assertThat(configuration.skipInstrumentation("/"), is(false));
- assertThat(configuration.isIncludeBranch(), is(true));
- assertThat(configuration.isIncludeFunction(), is(true));
+ assertThat(configuration.showHelp()).isFalse();
+ assertThat(configuration.getDocumentRoot().toString()).isEqualTo(System.getProperty("user.dir"));
+ assertThat(configuration.getPort()).isEqualTo(8080);
+ assertThat(configuration.isProxy()).isFalse();
+ assertThat(configuration.getECMAVersion()).isEqualTo(ECMASCRIPT_NEXT);
+ assertThat(configuration.skipInstrumentation("/")).isFalse();
+ assertThat(configuration.isIncludeBranch()).isTrue();
+ assertThat(configuration.isIncludeFunction()).isTrue();
}
@Test
public void shouldShowHelpOnError() {
ConfigurationForServer configuration = ConfigurationForServer.parse(new String[]{"unknown"});
- assertThat(configuration.showHelp(), is(true));
- assertThat(configuration.isInvalid(), is(true));
+ assertThat(configuration.showHelp()).isTrue();
+ assertThat(configuration.isInvalid()).isTrue();
}
@Test
public void shouldParseHelp() {
- assertThat(ConfigurationForServer.parse(new String[]{"-h"}).showHelp(), is(true));
- assertThat(ConfigurationForServer.parse(new String[]{"--help"}).showHelp(), is(true));
- assertThat(ConfigurationForServer.parse(new String[]{"-h"}).isInvalid(), is(false));
- assertThat(ConfigurationForServer.parse(new String[]{"--help"}).isInvalid(), is(false));
+ assertThat(ConfigurationForServer.parse(new String[]{"-h"}).showHelp()).isTrue();
+ assertThat(ConfigurationForServer.parse(new String[]{"--help"}).showHelp()).isTrue();
+ assertThat(ConfigurationForServer.parse(new String[]{"-h"}).isInvalid()).isFalse();
+ assertThat(ConfigurationForServer.parse(new String[]{"--help"}).isInvalid()).isFalse();
}
@Test
public void shouldParseBranch() {
- assertThat(ConfigurationForServer.parse(new String[]{"-ws", "--no-branch"}).isIncludeBranch(), is(false));
+ assertThat(ConfigurationForServer.parse(new String[]{"-ws", "--no-branch"}).isIncludeBranch()).isFalse();
}
@Test
public void shouldParseFunction() {
- assertThat(ConfigurationForServer.parse(new String[]{"-ws", "--no-function"}).isIncludeFunction(), is(false));
+ assertThat(ConfigurationForServer.parse(new String[]{"-ws", "--no-function"}).isIncludeFunction()).isFalse();
}
@Test
public void shouldParseDocumentRoot() {
- assertThat(ConfigurationForServer.parse(new String[]{"--document-root=/"}).getDocumentRoot(), equalTo(new File("/")));
+ assertThat(ConfigurationForServer.parse(new String[]{"--document-root=/"}).getDocumentRoot()).isEqualTo(new File("/"));
}
@Test
public void shouldDisallowDocumentRootThatIsNonExistent() {
- assertThat(ConfigurationForServer.parse(new String[]{"--document-root=xxx"}).isInvalid(), is(true));
+ assertThat(ConfigurationForServer.parse(new String[]{"--document-root=xxx"}).isInvalid()).isTrue();
}
@Test
public void shouldDisallowDocumentRootThatIsAFile() {
- assertThat(ConfigurationForServer.parse(new String[]{"--document-root=build.xml"}).isInvalid(), is(true));
+ assertThat(ConfigurationForServer.parse(new String[]{"--document-root=build.xml"}).isInvalid()).isTrue();
}
@Test
public void shouldParsePort() {
- assertThat(ConfigurationForServer.parse(new String[]{"--port=80"}).getPort(), equalTo(80));
+ assertThat(ConfigurationForServer.parse(new String[]{"--port=80"}).getPort()).isEqualTo(80);
}
@Test
public void shouldParseProxy() {
- assertThat(ConfigurationForServer.parse(new String[]{"--proxy"}).isProxy(), is(true));
+ assertThat(ConfigurationForServer.parse(new String[]{"--proxy"}).isProxy()).isTrue();
}
@Test
public void shouldParseSaveJSONOnly() {
- assertThat(ConfigurationForServer.parse(new String[]{"--save-json-only"}).isSaveJSONOnly(), is(true));
+ assertThat(ConfigurationForServer.parse(new String[]{"--save-json-only"}).isSaveJSONOnly()).isTrue();
}
@Test
public void shouldParseECMAVersion() {
ConfigurationForServer configuration = ConfigurationForServer.parse(new String[]{"--js-version=ECMASCRIPT5"});
- assertThat(configuration.getECMAVersion(), equalTo(CompilerOptions.LanguageMode.ECMASCRIPT5));
+ assertThat(configuration.getECMAVersion()).isEqualTo(CompilerOptions.LanguageMode.ECMASCRIPT5);
}
@Test
public void shouldParseReportDir() {
- assertThat(ConfigurationForServer.parse(new String[]{"--report-dir=/"}).getReportDir(), equalTo(new File("/")));
+ assertThat(ConfigurationForServer.parse(new String[]{"--report-dir=/"}).getReportDir()).isEqualTo(new File("/"));
}
@Test
public void shouldParseLogLevel() {
- assertThat(ConfigurationForServer.parse(new String[]{"--log=FINE"}).getLogLevel(), equalTo(FINE));
+ assertThat(ConfigurationForServer.parse(new String[]{"--log=FINE"}).getLogLevel()).isEqualTo(FINE);
}
@Test
public void shouldParseNoInstrument() {
ConfigurationForServer configuration = ConfigurationForServer.parse(new String[]{"--no-instrument=lib1", "--no-instrument=lib2", "--no-instrument=/lib3"});
- assertThat(configuration.skipInstrumentation("test.js"), is(false));
- assertThat(configuration.skipInstrumentation("lib1/test.js"), is(true));
- assertThat(configuration.skipInstrumentation("lib2/test.js"), is(true));
- assertThat(configuration.skipInstrumentation("lib3/test.js"), is(true));
- assertThat(configuration.skipInstrumentation("lib4/test.js"), is(false));
+ assertThat(configuration.skipInstrumentation("test.js")).isFalse();
+ assertThat(configuration.skipInstrumentation("lib1/test.js")).isTrue();
+ assertThat(configuration.skipInstrumentation("lib2/test.js")).isTrue();
+ assertThat(configuration.skipInstrumentation("lib3/test.js")).isTrue();
+ assertThat(configuration.skipInstrumentation("lib4/test.js")).isFalse();
}
@Test
public void shouldParseNoInstrumentReg() {
ConfigurationForServer configuration = ConfigurationForServer.parse(new String[]{"--no-instrument-reg=.*/lib/.*", "--no-instrument-reg=.*/test/.*", "--no-instrument-reg=/.*/test2/.*"});
- assertThat(configuration.skipInstrumentation("test.js"), is(false));
- assertThat(configuration.skipInstrumentation("lib1/lib/test.js"), is(true));
- assertThat(configuration.skipInstrumentation("lib2/test/test.js"), is(true));
- assertThat(configuration.skipInstrumentation("lib3/test2/test.js"), is(true));
- assertThat(configuration.skipInstrumentation("lib4/domain/test.js"), is(false));
+ assertThat(configuration.skipInstrumentation("test.js")).isFalse();
+ assertThat(configuration.skipInstrumentation("lib1/lib/test.js")).isTrue();
+ assertThat(configuration.skipInstrumentation("lib2/test/test.js")).isTrue();
+ assertThat(configuration.skipInstrumentation("lib3/test2/test.js")).isTrue();
+ assertThat(configuration.skipInstrumentation("lib4/domain/test.js")).isFalse();
}
@Test
public void shouldHandleInvalidRegularExpression() {
ConfigurationForServer configuration = ConfigurationForServer.parse(new String[]{"--no-instrument-reg=*"});
- assertThat(configuration.showHelp(), is(true));
- assertThat(configuration.isInvalid(), is(true));
+ assertThat(configuration.showHelp()).isTrue();
+ assertThat(configuration.isInvalid()).isTrue();
}
@Test
public void shouldParseNoInstrumentWithLeadingSlash() {
ConfigurationForServer configuration = ConfigurationForServer.parse(new String[]{"--no-instrument=/lib1", "--no-instrument=/lib2"});
- assertThat(configuration.skipInstrumentation("test.js"), is(false));
- assertThat(configuration.skipInstrumentation("lib1/test.js"), is(true));
- assertThat(configuration.skipInstrumentation("lib2/test.js"), is(true));
- assertThat(configuration.skipInstrumentation("lib3/test.js"), is(false));
+ assertThat(configuration.skipInstrumentation("test.js")).isFalse();
+ assertThat(configuration.skipInstrumentation("lib1/test.js")).isTrue();
+ assertThat(configuration.skipInstrumentation("lib2/test.js")).isTrue();
+ assertThat(configuration.skipInstrumentation("lib3/test.js")).isFalse();
}
@Test
public void shouldRequireBothUriToFileSwitches() {
- assertThat(ConfigurationForServer.parse(new String[]{"--uri-to-file-matcher=src/(.*)/tests(.*)"}).isInvalid(), is(true));
- assertThat(ConfigurationForServer.parse(new String[]{"--uri-to-file-replace=$1$2"}).isInvalid(), is(true));
- assertThat(ConfigurationForServer.parse(new String[]{"--uri-to-file-matcher=src/(.*)/tests(.*)", "--uri-to-file-replace=$1$2"}).isInvalid(), is(false));
+ assertThat(ConfigurationForServer.parse(new String[]{"--uri-to-file-matcher=src/(.*)/tests(.*)"}).isInvalid()).isTrue();
+ assertThat(ConfigurationForServer.parse(new String[]{"--uri-to-file-replace=$1$2"}).isInvalid()).isTrue();
+ assertThat(ConfigurationForServer.parse(new String[]{"--uri-to-file-matcher=src/(.*)/tests(.*)", "--uri-to-file-replace=$1$2"}).isInvalid()).isFalse();
}
@Test
public void shouldParseUriToFileSwitches() {
ConfigurationForServer configuration = ConfigurationForServer.parse(new String[]{"--uri-to-file-matcher=src/(.*)/tests(.*)", "--uri-to-file-replace=$1$2"});
- assertThat(configuration.getUriToFileMatcher().pattern(), equalTo("src/(.*)/tests(.*)"));
- assertThat(configuration.getUriToFileReplace(), equalTo("$1$2"));
- assertThat(configuration.getUriFileTranslator(), instanceOf(UriFileTranslatorReg.class));
+ assertThat(configuration.getUriToFileMatcher().pattern()).isEqualTo("src/(.*)/tests(.*)");
+ assertThat(configuration.getUriToFileReplace()).isEqualTo("$1$2");
+ assertThat(configuration.getUriFileTranslator()).isInstanceOf(UriFileTranslatorReg.class);
}
@Test
public void shouldHandleInvalidUriToFileReg() {
ConfigurationForServer configuration = ConfigurationForServer.parse(new String[]{"--uri-to-file-matcher=src/(*)/tests(.*)", "--uri-to-file-replace=$1$2"});
- assertThat(configuration.showHelp(), is(true));
- assertThat(configuration.isInvalid(), is(true));
+ assertThat(configuration.showHelp()).isTrue();
+ assertThat(configuration.isInvalid()).isTrue();
}
@Test
public void shouldRetrieveHelpText() {
String helpText = new ConfigurationForServer().getHelpText();
- assertThat(helpText, containsString("Usage: java -jar JSCover-all.jar -ws [OPTION]..."));
+ assertThat(helpText).contains("Usage: java -jar JSCover-all.jar -ws [OPTION]...");
}
@Test
public void shouldParseInstrumentReg() {
ConfigurationForServer configuration = ConfigurationForServer.parse(new String[]{"--only-instrument-reg=.*/production/.*"});
- assertThat(configuration.skipInstrumentation("test.js"), is(true));
- assertThat(configuration.skipInstrumentation("lib1/production/code.js"), is(false));
- assertThat(configuration.skipInstrumentation("lib2/test/production.js"), is(true));
+ assertThat(configuration.skipInstrumentation("test.js")).isTrue();
+ assertThat(configuration.skipInstrumentation("lib1/production/code.js")).isFalse();
+ assertThat(configuration.skipInstrumentation("lib2/test/production.js")).isTrue();
}
@Test
public void shouldParseInstrumentRegWithLeadingSlash() {
ConfigurationForServer configuration = ConfigurationForServer.parse(new String[]{"--only-instrument-reg=/production/.*"});
- assertThat(configuration.skipInstrumentation("production/code.js"), is(false));
+ assertThat(configuration.skipInstrumentation("production/code.js")).isFalse();
}
@Test
public void shouldHandleInvalidInstrumentRegularExpression() {
ConfigurationForServer configuration = ConfigurationForServer.parse(new String[]{"--only-instrument-reg=*"});
- assertThat(configuration.showHelp(), is(true));
- assertThat(configuration.isInvalid(), is(true));
+ assertThat(configuration.showHelp()).isTrue();
+ assertThat(configuration.isInvalid()).isTrue();
}
@Test
public void shouldHandleInvalidOption() {
ConfigurationForServer configuration = ConfigurationForServer.parse(new String[]{"--unknownoption"});
- assertThat(configuration.showHelp(), is(true));
- assertThat(configuration.isInvalid(), is(true));
+ assertThat(configuration.showHelp()).isTrue();
+ assertThat(configuration.isInvalid()).isTrue();
}
@Test
public void shouldHandleInvalidShortOption() {
ConfigurationForServer configuration = ConfigurationForServer.parse(new String[]{"-u"});
- assertThat(configuration.showHelp(), is(true));
- assertThat(configuration.isInvalid(), is(true));
+ assertThat(configuration.showHelp()).isTrue();
+ assertThat(configuration.isInvalid()).isTrue();
}
@Test
public void shouldParseInstrumentAndNoInstrumentReg1() {
ConfigurationForServer configuration = ConfigurationForServer.parse(new String[]{"--no-instrument=lib1", "--no-instrument-reg=lib2/production/test.*", "--only-instrument-reg=.*/production/.*"});
- assertThat(configuration.skipInstrumentation("lib1/production/test.js"), is(true));
- assertThat(configuration.skipInstrumentation("lib2/production/test.js"), is(true));
- assertThat(configuration.skipInstrumentation("lib3/production/code.js"), is(false));
- assertThat(configuration.skipInstrumentation("lib4/code.js"), is(true));
+ assertThat(configuration.skipInstrumentation("lib1/production/test.js")).isTrue();
+ assertThat(configuration.skipInstrumentation("lib2/production/test.js")).isTrue();
+ assertThat(configuration.skipInstrumentation("lib3/production/code.js")).isFalse();
+ assertThat(configuration.skipInstrumentation("lib4/code.js")).isTrue();
}
@Test
public void shouldParseInstrumentAndNoInstrumentReg2() {
ConfigurationForServer configuration = ConfigurationForServer.parse(new String[]{"--no-instrument=lib1", "--only-instrument-reg=.*/production/.*", "--no-instrument-reg=lib2/production/test.*"});
- assertThat(configuration.skipInstrumentation("lib1/production/test.js"), is(true));
- assertThat(configuration.skipInstrumentation("lib2/production/test.js"), is(false));
- assertThat(configuration.skipInstrumentation("lib3/production/code.js"), is(false));
- assertThat(configuration.skipInstrumentation("lib4/code.js"), is(true));
+ assertThat(configuration.skipInstrumentation("lib1/production/test.js")).isTrue();
+ assertThat(configuration.skipInstrumentation("lib2/production/test.js")).isFalse();
+ assertThat(configuration.skipInstrumentation("lib3/production/code.js")).isFalse();
+ assertThat(configuration.skipInstrumentation("lib4/code.js")).isTrue();
}
@Test
public void shouldParseInstrumentAndNoInstrumentReg3() {
ConfigurationForServer configuration = ConfigurationForServer.parse(new String[]{"--only-instrument-reg=.*/production/.*", "--no-instrument=lib1", "--no-instrument-reg=lib2/production/test.*"});
- assertThat(configuration.skipInstrumentation("lib1/production/test.js"), is(false));
- assertThat(configuration.skipInstrumentation("lib2/production/test.js"), is(false));
- assertThat(configuration.skipInstrumentation("lib3/production/code.js"), is(false));
- assertThat(configuration.skipInstrumentation("lib4/code.js"), is(true));
+ assertThat(configuration.skipInstrumentation("lib1/production/test.js")).isFalse();
+ assertThat(configuration.skipInstrumentation("lib2/production/test.js")).isFalse();
+ assertThat(configuration.skipInstrumentation("lib3/production/code.js")).isFalse();
+ assertThat(configuration.skipInstrumentation("lib4/code.js")).isTrue();
}
}
diff --git a/src/test/java/jscover/server/HttpRequestTest.java b/src/test/java/jscover/server/HttpRequestTest.java
index 2bbb5a6d..4fea439a 100644
--- a/src/test/java/jscover/server/HttpRequestTest.java
+++ b/src/test/java/jscover/server/HttpRequestTest.java
@@ -351,75 +351,73 @@ You should also get your employer (if you work as a programmer) or your
import java.util.List;
import java.util.Map;
-import static org.hamcrest.CoreMatchers.equalTo;
-import static org.hamcrest.CoreMatchers.sameInstance;
-import static org.hamcrest.MatcherAssert.assertThat;
+import static org.assertj.core.api.Assertions.assertThat;
import static org.mockito.Mockito.mock;
public class HttpRequestTest {
@Test
public void shouldReadSimplePath() {
HttpRequest httpRequest = new HttpRequest("/test.html", null, null, 0, null);
- assertThat(httpRequest.getPath(), equalTo("/test.html"));
- assertThat(httpRequest.getMime().getContentType(), equalTo("text/html"));
+ assertThat(httpRequest.getPath()).isEqualTo("/test.html");
+ assertThat(httpRequest.getMime().getContentType()).isEqualTo("text/html");
}
@Test
public void shouldReplaceDoubleSlashes() {
HttpRequest httpRequest = new HttpRequest("//lib//test.html", null, null, 0, null);
- assertThat(httpRequest.getPath(), equalTo("/lib/test.html"));
- assertThat(httpRequest.getMime().getContentType(), equalTo("text/html"));
+ assertThat(httpRequest.getPath()).isEqualTo("/lib/test.html");
+ assertThat(httpRequest.getMime().getContentType()).isEqualTo("text/html");
}
@Test
public void shouldReadSimpleURL() {
HttpRequest httpRequest = new HttpRequest("http://localhost:8080/test.html", null, null, 0, null);
- assertThat(httpRequest.getPath(), equalTo("/test.html"));
- assertThat(httpRequest.getMime().getContentType(), equalTo("text/html"));
+ assertThat(httpRequest.getPath()).isEqualTo("/test.html");
+ assertThat(httpRequest.getMime().getContentType()).isEqualTo("text/html");
}
@Test
public void shouldHaveDefaultForUnknownExtension() {
HttpRequest httpRequest = new HttpRequest("/test.unknown", null, null, 0, null);
- assertThat(httpRequest.getPath(), equalTo("/test.unknown"));
- assertThat(httpRequest.getMime().getContentType(), equalTo("application/octet-stream"));
+ assertThat(httpRequest.getPath()).isEqualTo("/test.unknown");
+ assertThat(httpRequest.getMime().getContentType()).isEqualTo("application/octet-stream");
}
@Test
public void shouldHaveDefaultForNoExtension() {
HttpRequest httpRequest = new HttpRequest("/test", null, null, 0, null);
- assertThat(httpRequest.getPath(), equalTo("/test"));
- assertThat(httpRequest.getMime().getContentType(), equalTo("application/octet-stream"));
+ assertThat(httpRequest.getPath()).isEqualTo("/test");
+ assertThat(httpRequest.getMime().getContentType()).isEqualTo("application/octet-stream");
}
@Test
public void shouldHandleQueryString() {
HttpRequest httpRequest = new HttpRequest("/test.html?a=b", null, null, 0, null);
- assertThat(httpRequest.getPath(), equalTo("/test.html"));
- assertThat(httpRequest.getMime().getContentType(), equalTo("text/html"));
+ assertThat(httpRequest.getPath()).isEqualTo("/test.html");
+ assertThat(httpRequest.getMime().getContentType()).isEqualTo("text/html");
}
@Test
public void shouldHandleSpecialChars() {
- assertThat(new HttpRequest("/test%20space.html", null, null, 0, null).getPath(), equalTo("/test space.html"));
+ assertThat(new HttpRequest("/test%20space.html", null, null, 0, null).getPath()).isEqualTo("/test space.html");
}
@Test
public void shouldHandleSpecialCharsWithFullURL() {
- assertThat(new HttpRequest("http://localhost/test%20space.html", null, null, 0, null).getPath(), equalTo("/test space.html"));
+ assertThat(new HttpRequest("http://localhost/test%20space.html", null, null, 0, null).getPath()).isEqualTo("/test space.html");
}
@Test
public void shouldNotSkipInstrumentationIfNoHeaders() {
HttpRequest httpRequest = new HttpRequest("/test.js", null, null, 0, null);
- assertThat(httpRequest.skipInstrumentation(), equalTo(false));
+ assertThat(httpRequest.skipInstrumentation()).isEqualTo(false);
}
@Test
public void shouldNotSkipInstrumentationIfNoInstrumentHeaderNotPresent() {
HttpRequest httpRequest = new HttpRequest("/test.js", null, null, 0, null);
httpRequest.setHeaders(new HashMap<>());
- assertThat(httpRequest.skipInstrumentation(), equalTo(false));
+ assertThat(httpRequest.skipInstrumentation()).isEqualTo(false);
}
@Test
@@ -428,14 +426,14 @@ public void shouldSkipInstrumentationIfNoInstrumentHeaderPresent() {
Map> headers = new HashMap<>();
headers.put("NoInstrument", new ArrayList<>());
httpRequest.setHeaders(headers);
- assertThat(httpRequest.skipInstrumentation(), equalTo(true));
+ assertThat(httpRequest.skipInstrumentation()).isEqualTo(true);
}
@Test
public void shouldGetRelativePath() {
- assertThat(new HttpRequest("test.js", null, null, 0, null).getRelativePath(), equalTo("test.js"));
- assertThat(new HttpRequest("/test.js", null, null, 0, null).getRelativePath(), equalTo("test.js"));
- assertThat(new HttpRequest("/js/test.js", null, null, 0, null).getRelativePath(), equalTo("js/test.js"));
+ assertThat(new HttpRequest("test.js", null, null, 0, null).getRelativePath()).isEqualTo("test.js");
+ assertThat(new HttpRequest("/test.js", null, null, 0, null).getRelativePath()).isEqualTo("test.js");
+ assertThat(new HttpRequest("/js/test.js", null, null, 0, null).getRelativePath()).isEqualTo("js/test.js");
}
@Test
@@ -446,8 +444,8 @@ public void shouldReturnContentLength() {
}});
HttpRequest request = new HttpRequest("test.js", null, null, 0, null);
request.setHeaders(headers);
- assertThat(request.getHeaders(), sameInstance(headers));
- assertThat(request.getContentLength(), equalTo(1234));
+ assertThat(request.getHeaders()).isSameAs(headers);
+ assertThat(request.getContentLength()).isEqualTo(1234);
}
@Test
@@ -456,8 +454,8 @@ public void shouldConstructorParameters() {
OutputStream os = mock(OutputStream.class);
Integer postIndex = 7;
HttpRequest httpRequest = new HttpRequest("/test.html", is, os, postIndex, null);
- assertThat(httpRequest.getInputStream(), sameInstance(is));
- assertThat(httpRequest.getOutputStream(), sameInstance(os));
- assertThat(httpRequest.getPostIndex(), sameInstance(postIndex));
+ assertThat(httpRequest.getInputStream()).isSameAs(is);
+ assertThat(httpRequest.getOutputStream()).isSameAs(os);
+ assertThat(httpRequest.getPostIndex()).isSameAs(postIndex);
}
}
diff --git a/src/test/java/jscover/server/HttpServerTest.java b/src/test/java/jscover/server/HttpServerTest.java
index 80cd0b02..5cd6d7b7 100644
--- a/src/test/java/jscover/server/HttpServerTest.java
+++ b/src/test/java/jscover/server/HttpServerTest.java
@@ -351,8 +351,7 @@ You should also get your employer (if you work as a programmer) or your
import java.util.Map;
import static jscover.server.HTTP_STATUS.HTTP_OK;
-import static org.hamcrest.MatcherAssert.assertThat;
-import static org.hamcrest.Matchers.*;
+import static org.assertj.core.api.Assertions.assertThat;
public class HttpServerTest {
private HttpServer httpServer = new HttpServer(null, null, null);
@@ -371,9 +370,9 @@ public void shouldReadSimpleHeader() throws IOException {
Map> headers = httpServer.readHeaders(br);
List header = headers.get("Host");
- assertThat(headers.size(), equalTo(1));
- assertThat(header.size(), equalTo(1));
- assertThat(header.get(0), equalTo("localhost:8080"));
+ assertThat(headers.size()).isEqualTo(1);
+ assertThat(header.size()).isEqualTo(1);
+ assertThat(header.get(0)).isEqualTo("localhost:8080");
}
@Test
@@ -383,10 +382,10 @@ public void shouldReadDuplicateHeaders() throws IOException {
Map> headers = httpServer.readHeaders(br);
List header = headers.get("Cookie");
- assertThat(headers.size(), equalTo(1));
- assertThat(header.size(), equalTo(2));
- assertThat(header, hasItem("cookie1"));
- assertThat(header, hasItem("cookie2"));
+ assertThat(headers.size()).isEqualTo(1);
+ assertThat(header.size()).isEqualTo(2);
+ assertThat(header).contains("cookie1");
+ assertThat(header).contains("cookie2");
}
private BufferedReader getBufferedReader(String s) {
@@ -400,14 +399,14 @@ public void shouldHandleNoLineTerminatorAfterHeader() throws IOException {
Map> headers = httpServer.readHeaders(br);
- assertThat(headers.containsKey("Host"), is(true));
+ assertThat(headers.containsKey("Host")).isTrue();
}
@Test
public void shouldSetContentLength() {
httpServer.sendResponse(HTTP_OK, MIME.TEXT_PLAIN, "Hey");
- assertThat(stringWriter.toString(), equalTo("HTTP/1.0 200 OK\nServer: JSCover/null\nContent-Type: text/plain\nConnection: close\nContent-Length: 3\n\nHey"));
+ assertThat(stringWriter.toString()).isEqualTo("HTTP/1.0 200 OK\nServer: JSCover/null\nContent-Type: text/plain\nConnection: close\nContent-Length: 3\n\nHey");
}
@Test
@@ -415,6 +414,6 @@ public void shouldSetContentLengthForUTF8() throws IOException {
String data = new String("小方".getBytes("UTF-8"));
httpServer.sendResponse(HTTP_OK, MIME.TEXT_PLAIN, data);
- assertThat(stringWriter.toString(), equalTo("HTTP/1.0 200 OK\nServer: JSCover/null\nContent-Type: text/plain\nConnection: close\nContent-Length: 6\n\n"+data));
+ assertThat(stringWriter.toString()).isEqualTo("HTTP/1.0 200 OK\nServer: JSCover/null\nContent-Type: text/plain\nConnection: close\nContent-Length: 6\n\n"+data);
}
}
diff --git a/src/test/java/jscover/server/InstrumentingRequestHandlerTest.java b/src/test/java/jscover/server/InstrumentingRequestHandlerTest.java
index cd5e9a85..3824e28e 100644
--- a/src/test/java/jscover/server/InstrumentingRequestHandlerTest.java
+++ b/src/test/java/jscover/server/InstrumentingRequestHandlerTest.java
@@ -365,9 +365,7 @@ You should also get your employer (if you work as a programmer) or your
import static java.lang.String.format;
import static jscover.server.InstrumentingRequestHandler.JSCOVERAGE_STORE;
-import static org.hamcrest.MatcherAssert.assertThat;
-import static org.hamcrest.Matchers.containsString;
-import static org.hamcrest.Matchers.equalTo;
+import static org.assertj.core.api.Assertions.assertThat;
import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.mockito.BDDMockito.given;
import static org.mockito.Mockito.*;
@@ -431,7 +429,7 @@ public void shouldStoreJSCoverageJSON() {
verify(ioService).generateJSCoverFilesForWebServer(reportDir, "theVersion");
verify(bais).skip(50);
verifyNoInteractions(instrumenterService);
- assertThat(stringWriter.toString(), containsString(format("Coverage data stored at %s", reportDir)));
+ assertThat(stringWriter.toString()).contains(format("Coverage data stored at %s", reportDir));
}
@Test//NB This test must be run with assertions enabled (i.e. JVM arg -ea)
@@ -469,7 +467,7 @@ public void shouldDirectPOSTToHttpServer() {
verifyNoInteractions(ioService);
verifyNoInteractions(jsonDataSaver);
verifyNoInteractions(instrumenterService);
- assertThat(stringWriter.toString(), containsString("thePostData"));
+ assertThat(stringWriter.toString()).contains("thePostData");
}
@Test
@@ -527,7 +525,7 @@ public void shouldHandleErrorOnStoreJSCoverageJSON() {
verifyNoInteractions(ioService);
verify(bais).skip(50);
verifyNoInteractions(instrumenterService);
- assertThat(stringWriter.toString(), containsString(format("Error saving coverage data. Try deleting JSON file at %s", reportDir)));
+ assertThat(stringWriter.toString()).contains(format("Error saving coverage data. Try deleting JSON file at %s", reportDir));
}
@Test
@@ -546,7 +544,7 @@ public void shouldStoreJSCoverageJSONInSpecifiedSubDirectory() {
verify(bais).skip(50);
verify(ioService).generateJSCoverFilesForWebServer(subdirectory, "theVersion");
verifyNoInteractions(instrumenterService);
- assertThat(stringWriter.toString(), containsString(format("Coverage data stored at %s", subdirectory)));
+ assertThat(stringWriter.toString()).contains(format("Coverage data stored at %s", subdirectory));
}
@Test
@@ -577,7 +575,7 @@ private void testStoreJSCoverageJSONInSpecifiedSubDirectory(boolean saveJSONOnly
verify(bais).skip(50);
verify(ioUtils, times(saveJSONOnly ? 0 : 1)).copy(new File("js/util.js"), new File(configuration.getReportDir(), "subdirectory/" + Main.reportSrcSubDir + "/js/util.js"));
verifyNoInteractions(instrumenterService);
- assertThat(stringWriter.toString(), containsString(format("Coverage data stored at %s", subdirectory)));
+ assertThat(stringWriter.toString()).contains(format("Coverage data stored at %s", subdirectory));
}
@Test
@@ -614,7 +612,7 @@ private void testStoreJSCoverageJSONInSpecifiedSubDirectoryForProxy(boolean save
verify(bais).skip(50);
verify(ioUtils, times(saveJSONOnly ? 0 : 1)).copy("someJavaScript", new File(configuration.getReportDir(), "subdirectory/" + Main.reportSrcSubDir + "/js/util.js"));
verifyNoInteractions(instrumenterService);
- assertThat(stringWriter.toString(), containsString(format("Coverage data stored at %s", subdirectory)));
+ assertThat(stringWriter.toString()).contains(format("Coverage data stored at %s", subdirectory));
}
@Test
@@ -650,7 +648,7 @@ private void testStoreJSCoverageJSONWithUnloadedJS(boolean saveJSONOnly) {
verify(bais).skip(50);
verify(ioUtils, times(saveJSONOnly ? 0 : 1)).copy(new File("/js/unloaded.js"), new File(configuration.getReportDir(), Main.reportSrcSubDir + "/js/unloaded.js"));
verifyNoInteractions(instrumenterService);
- assertThat(stringWriter.toString(), containsString(format("Coverage data stored at %s", reportDir)));
+ assertThat(stringWriter.toString()).contains(format("Coverage data stored at %s", reportDir));
}
@Test
@@ -663,13 +661,13 @@ public void shouldServeJSCoverageHTML() {
verify(ioService).generateJSCoverageHtml("123");
verifyNoInteractions(jsonDataSaver);
verifyNoInteractions(instrumenterService);
- assertThat(stringWriter.toString(), equalTo("HTTP/1.0 200 OK\n" +
+ assertThat(stringWriter.toString()).isEqualTo("HTTP/1.0 200 OK\n" +
"Server: JSCover/testVersion\n" +
"Content-Type: text/html\n" +
"Connection: close\n" +
"Content-Length: 7\n" +
"\n" +
- "theHtml"));
+ "theHtml");
}
@Test
@@ -692,8 +690,8 @@ public void shouldServeInstrumentedJSForWebServer() {
verifyNoInteractions(ioService);
verifyNoInteractions(jsonDataSaver);
verifyNoInteractions(proxyService);
- assertThat(InstrumentingRequestHandler.uris.size(), equalTo(1));
- assertThat(InstrumentingRequestHandler.uris.keySet().iterator().next(), equalTo("js/production.js"));
+ assertThat(InstrumentingRequestHandler.uris.size()).isEqualTo(1);
+ assertThat(InstrumentingRequestHandler.uris.keySet().iterator().next()).isEqualTo("js/production.js");
}
@@ -708,14 +706,14 @@ public void shouldNotRecordInstrumentedURIsForWebServerIfNotFound() {
verifyNoInteractions(ioService);
verifyNoInteractions(jsonDataSaver);
verifyNoInteractions(proxyService);
- assertThat(InstrumentingRequestHandler.uris.size(), equalTo(0));
- assertThat(stringWriter.toString(), equalTo("HTTP/1.0 404 File Not Found\n" +
+ assertThat(InstrumentingRequestHandler.uris.size()).isEqualTo(0);
+ assertThat(stringWriter.toString()).isEqualTo("HTTP/1.0 404 File Not Found\n" +
"Server: JSCover/testVersion\n" +
"Content-Type: text/plain\n" +
"Connection: close\n" +
"Content-Length: 5\n" +
"\n" +
- "Ouch!"));
+ "Ouch!");
}
@Test
@@ -733,9 +731,9 @@ public void shouldServeInstrumentedJSForProxyServer() throws IOException {
verify(instrumenterService).instrumentJSForProxyServer(configuration, "someJavaScript;", "/exclude/js/production.js");
verifyNoInteractions(ioService);
verifyNoInteractions(jsonDataSaver);
- assertThat(InstrumentingRequestHandler.uris.size(), equalTo(1));
- assertThat(InstrumentingRequestHandler.uris.keySet().iterator().next(), equalTo("js/production.js"));
- assertThat(InstrumentingRequestHandler.uris.values().iterator().next(), equalTo("someJavaScript;"));
+ assertThat(InstrumentingRequestHandler.uris.size()).isEqualTo(1);
+ assertThat(InstrumentingRequestHandler.uris.keySet().iterator().next()).isEqualTo("js/production.js");
+ assertThat(InstrumentingRequestHandler.uris.values().iterator().next()).isEqualTo("someJavaScript;");
}
@Test
diff --git a/src/test/java/jscover/server/MIMETest.java b/src/test/java/jscover/server/MIMETest.java
index 46a3a31f..b2d39f38 100644
--- a/src/test/java/jscover/server/MIMETest.java
+++ b/src/test/java/jscover/server/MIMETest.java
@@ -344,18 +344,17 @@ You should also get your employer (if you work as a programmer) or your
import org.junit.jupiter.api.Test;
-import static org.hamcrest.MatcherAssert.assertThat;
-import static org.hamcrest.Matchers.equalTo;
+import static org.assertj.core.api.Assertions.assertThat;
public class MIMETest {
@Test
public void shouldGetJpegMimeType() {
- assertThat(MIME.getMime("jpg"), equalTo(MIME.JPG));
- assertThat(MIME.getMime("jpeg"), equalTo(MIME.JPG));
+ assertThat(MIME.getMime("jpg")).isEqualTo(MIME.JPG);
+ assertThat(MIME.getMime("jpeg")).isEqualTo(MIME.JPG);
}
@Test
public void shouldGetXmlMimeType() {
- assertThat(MIME.getMime("xml"), equalTo(MIME.XML));
+ assertThat(MIME.getMime("xml")).isEqualTo(MIME.XML);
}
}
diff --git a/src/test/java/jscover/server/ProxyRequestHandlerTest.java b/src/test/java/jscover/server/ProxyRequestHandlerTest.java
index 093c39f8..50f91d90 100644
--- a/src/test/java/jscover/server/ProxyRequestHandlerTest.java
+++ b/src/test/java/jscover/server/ProxyRequestHandlerTest.java
@@ -348,8 +348,7 @@ You should also get your employer (if you work as a programmer) or your
import java.net.URI;
import java.net.URL;
-import static org.hamcrest.CoreMatchers.equalTo;
-import static org.hamcrest.MatcherAssert.assertThat;
+import static org.assertj.core.api.Assertions.assertThat;
public class ProxyRequestHandlerTest {
private final ProxyService proxyRequestHandler = new ProxyService();
@@ -357,12 +356,12 @@ public class ProxyRequestHandlerTest {
@Test
public void shouldGetRequestURIFromURL() throws MalformedURLException {
URL url = URI.create("http://localhost/test.html").toURL();
- assertThat(proxyRequestHandler.getRawURI(url), equalTo("/test.html"));
+ assertThat(proxyRequestHandler.getRawURI(url)).isEqualTo("/test.html");
}
@Test
public void shouldGetRequestURIFromURLWithQueryParameters() throws MalformedURLException {
URL url = URI.create("http://localhost/test.html?a=b").toURL();
- assertThat(proxyRequestHandler.getRawURI(url), equalTo("/test.html?a=b"));
+ assertThat(proxyRequestHandler.getRawURI(url)).isEqualTo("/test.html?a=b");
}
}
diff --git a/src/test/java/jscover/server/ProxyServiceTest.java b/src/test/java/jscover/server/ProxyServiceTest.java
index 445a5589..614d4b29 100644
--- a/src/test/java/jscover/server/ProxyServiceTest.java
+++ b/src/test/java/jscover/server/ProxyServiceTest.java
@@ -342,7 +342,6 @@ You should also get your employer (if you work as a programmer) or your
package jscover.server;
-import org.hamcrest.Matchers;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
@@ -354,20 +353,20 @@ You should also get your employer (if you work as a programmer) or your
import java.io.IOException;
import java.net.HttpURLConnection;
import java.nio.charset.Charset;
+import java.nio.charset.StandardCharsets;
import java.util.*;
-import static org.hamcrest.MatcherAssert.assertThat;
-import static org.hamcrest.Matchers.startsWith;
+import static org.assertj.core.api.Assertions.assertThat;
import static org.mockito.Mockito.*;
@ExtendWith(MockitoExtension.class)
public class ProxyServiceTest {
- private static final Charset UTF8 = Charset.forName("UTF-8");
- private ProxyService proxyService = new ProxyService();
- private HttpRequest request = new HttpRequest("test.js", null, null, 0, null);
+ private static final Charset UTF8 = StandardCharsets.UTF_8;
+ private final ProxyService proxyService = new ProxyService();
+ private final HttpRequest request = new HttpRequest("test.js", null, null, 0, null);
@Mock private HttpURLConnection conn;
- private Map> headers = new HashMap<>();
+ private final Map> headers = new HashMap<>();
@BeforeEach
public void setUp() {
@@ -376,7 +375,7 @@ public void setUp() {
@Test
public void shouldAddHeaders() {
- headers.put("Cookie", new ArrayList(){{add("123");}{add("456");}});
+ headers.put("Cookie", new ArrayList<>(){{add("123");}{add("456");}});
proxyService.copyHeadersExceptEncoding(request, conn);
@@ -395,7 +394,7 @@ public void shouldHandleNull() {
@Test
public void shouldNotAddEncodingHeaders() {
- headers.put("Accept-Encoding", new ArrayList() {{
+ headers.put("Accept-Encoding", new ArrayList<>() {{
add("GZIP");
}});
@@ -406,7 +405,7 @@ public void shouldNotAddEncodingHeaders() {
@Test
public void shouldNotAddKeepAliveHeaders() {
- headers.put("Proxy-Connection", new ArrayList() {{
+ headers.put("Proxy-Connection", new ArrayList<>() {{
add("keep-alive");
}});
@@ -422,8 +421,8 @@ public void shouldConvertToHTTP10() throws Exception {
String url = "http://somehost/someURL";
String requestString = "POST " + url + " HTTP/1.1\r\nContent-Length: 0\r\n\r\n";
- String result = sendMethodAndHeaders(url, requestString, headers).toString("UTF-8");
- assertThat(result, startsWith("POST /someURL HTTP/1.0"));
+ String result = sendMethodAndHeaders(url, requestString, headers).toString(StandardCharsets.UTF_8);
+ assertThat(result).startsWith("POST /someURL HTTP/1.0");
}
@Test
@@ -433,8 +432,8 @@ public void shouldChangeURLToPath() throws Exception {
String url = "http://somehost/someURL";
String requestString = "POST " + url + " HTTP/1.1\r\nContent-Length: 0\r\n\r\n";
- String result = sendMethodAndHeaders(url, requestString, headers).toString("UTF-8");
- assertThat(result, startsWith("POST /someURL"));
+ String result = sendMethodAndHeaders(url, requestString, headers).toString(StandardCharsets.UTF_8);
+ assertThat(result).startsWith("POST /someURL");
}
@Test
@@ -446,10 +445,10 @@ public void shouldNotAddKeepAliveHeadersPost() throws Exception {
String url = "http://somehost/someURL";
String requestString = "POST " + url + " HTTP/1.1\r\nProxy-Connection: keep-alive\r\nConnection: keep-alive\r\nContent-Length: 0\r\n\r\n";
- String result = sendMethodAndHeaders(url, requestString, headers).toString("UTF-8");
+ String result = sendMethodAndHeaders(url, requestString, headers).toString(StandardCharsets.UTF_8);
- assertThat(result, Matchers.not(Matchers.containsString("Connection")));
- assertThat(result, Matchers.not(Matchers.containsString("keep-alive")));
+ assertThat(result).doesNotContain("Connection");
+ assertThat(result).doesNotContain("keep-alive");
}
private ByteArrayOutputStream sendMethodAndHeaders(String path, String requestString, Map> headers) throws IOException {
diff --git a/src/test/java/jscover/stdout/ConfigurationForStdOutTest.java b/src/test/java/jscover/stdout/ConfigurationForStdOutTest.java
index ec1ddd1a..a9d9dabd 100644
--- a/src/test/java/jscover/stdout/ConfigurationForStdOutTest.java
+++ b/src/test/java/jscover/stdout/ConfigurationForStdOutTest.java
@@ -348,73 +348,72 @@ You should also get your employer (if you work as a programmer) or your
import static com.google.javascript.jscomp.CompilerOptions.LanguageMode.ECMASCRIPT5;
import static java.util.logging.Level.SEVERE;
-import static org.hamcrest.MatcherAssert.assertThat;
-import static org.hamcrest.Matchers.*;
+import static org.assertj.core.api.Assertions.assertThat;
public class ConfigurationForStdOutTest {
@Test
public void shouldHaveDefaults() {
ConfigurationForStdOut configuration = ConfigurationForStdOut.parse(new String[]{"-io", "doc/example/script.js"});
- assertThat(configuration.showHelp(), is(false));
- assertThat(configuration.isInvalid(), is(false));
- assertThat(configuration.skipInstrumentation("/"), is(false));
- assertThat(configuration.isIncludeBranch(), is(true));
- assertThat(configuration.isIncludeFunction(), is(true));
- assertThat(configuration.getLogLevel(), is(SEVERE));
+ assertThat(configuration.showHelp()).isFalse();
+ assertThat(configuration.isInvalid()).isFalse();
+ assertThat(configuration.skipInstrumentation("/")).isFalse();
+ assertThat(configuration.isIncludeBranch()).isTrue();
+ assertThat(configuration.isIncludeFunction()).isTrue();
+ assertThat(configuration.getLogLevel()).isEqualTo(SEVERE);
}
@Test
public void shouldGetSourceFile() {
ConfigurationForStdOut configuration = ConfigurationForStdOut.parse(new String[]{"-io", "doc/example/script.js"});
- assertThat(configuration.getSrcFile(), equalTo(new File("doc/example/script.js")));
+ assertThat(configuration.getSrcFile()).isEqualTo(new File("doc/example/script.js"));
}
@Test
public void shouldSetHelp() {
ConfigurationForStdOut configuration = ConfigurationForStdOut.parse(new String[]{"-io", "-h"});
- assertThat(configuration.showHelp(), is(true));
+ assertThat(configuration.showHelp()).isTrue();
}
@Test
public void shouldGetSourceFileAndCommonConfiguration() {
ConfigurationForStdOut configuration = ConfigurationForStdOut.parse(new String[]{"-io", "--js-version=ECMASCRIPT5", "doc/example/script.js"});
- assertThat(configuration.getSrcFile(), equalTo(new File("doc/example/script.js")));
- assertThat(configuration.getECMAVersion(), equalTo(ECMASCRIPT5));
+ assertThat(configuration.getSrcFile()).isEqualTo(new File("doc/example/script.js"));
+ assertThat(configuration.getECMAVersion()).isEqualTo(ECMASCRIPT5);
}
@Test
public void shouldDetectInvalidFileIfDir() {
ConfigurationForStdOut configuration = ConfigurationForStdOut.parse(new String[]{"-io", "doc"});
- assertThat(configuration.showHelp(), is(true));
- assertThat(configuration.isInvalid(), is(true));
+ assertThat(configuration.showHelp()).isTrue();
+ assertThat(configuration.isInvalid()).isTrue();
}
@Test
public void shouldDetectInvalidFileIfInvalid() {
ConfigurationForStdOut configuration = ConfigurationForStdOut.parse(new String[]{"-io", "not-there"});
- assertThat(configuration.showHelp(), is(true));
- assertThat(configuration.isInvalid(), is(true));
+ assertThat(configuration.showHelp()).isTrue();
+ assertThat(configuration.isInvalid()).isTrue();
}
@Test
public void shouldDetectTooFewArgCount() {
ConfigurationForStdOut configuration = ConfigurationForStdOut.parse(new String[]{"-io"});
- assertThat(configuration.showHelp(), is(true));
- assertThat(configuration.isInvalid(), is(true));
+ assertThat(configuration.showHelp()).isTrue();
+ assertThat(configuration.isInvalid()).isTrue();
}
@Test
public void shouldDetectTooManyArgCount() {
ConfigurationForStdOut configuration = ConfigurationForStdOut.parse(new String[]{"-io", "doc/example/script.js", "extra"});
- assertThat(configuration.showHelp(), is(true));
- assertThat(configuration.isInvalid(), is(true));
+ assertThat(configuration.showHelp()).isTrue();
+ assertThat(configuration.isInvalid()).isTrue();
}
@Test
public void shouldRetrieveHelpText() {
String helpText = new ConfigurationForStdOut().getHelpText();
- assertThat(helpText, containsString("Usage: java -jar JSCover-all.jar -io [OPTION]... SOURCE-FILE"));
+ assertThat(helpText).contains("Usage: java -jar JSCover-all.jar -io [OPTION]... SOURCE-FILE");
}
}
diff --git a/src/test/java/jscover/util/ExceptionRecordingHandlerTest.java b/src/test/java/jscover/util/ExceptionRecordingHandlerTest.java
index bf351eb9..9d443bea 100644
--- a/src/test/java/jscover/util/ExceptionRecordingHandlerTest.java
+++ b/src/test/java/jscover/util/ExceptionRecordingHandlerTest.java
@@ -349,8 +349,7 @@ You should also get your employer (if you work as a programmer) or your
import java.util.logging.LogRecord;
-import static org.hamcrest.MatcherAssert.assertThat;
-import static org.hamcrest.Matchers.is;
+import static org.assertj.core.api.Assertions.assertThat;
import static org.mockito.BDDMockito.given;
@ExtendWith(MockitoExtension.class)
@@ -364,14 +363,14 @@ public void shouldRecordException() {
handler.publish(logRecord);
- assertThat(handler.isExceptionThrown(), is(true));
+ assertThat(handler.isExceptionThrown()).isTrue();
}
@Test
public void shouldNotRecordException() {
handler.publish(logRecord);
- assertThat(handler.isExceptionThrown(), is(false));
+ assertThat(handler.isExceptionThrown()).isFalse();
}
@Test
diff --git a/src/test/java/jscover/util/FileScannerTest.java b/src/test/java/jscover/util/FileScannerTest.java
index 36a8e690..c04a3e26 100644
--- a/src/test/java/jscover/util/FileScannerTest.java
+++ b/src/test/java/jscover/util/FileScannerTest.java
@@ -352,9 +352,7 @@ You should also get your employer (if you work as a programmer) or your
import java.util.HashSet;
import java.util.Set;
-import static org.hamcrest.CoreMatchers.equalTo;
-import static org.hamcrest.MatcherAssert.assertThat;
-import static org.hamcrest.core.IsIterableContaining.hasItem;
+import static org.assertj.core.api.Assertions.assertThat;
public class FileScannerTest {
private ConfigurationForServer configuration;
@@ -377,13 +375,13 @@ public void shouldFindAllJavaScriptFiles() {
fileScanner = new FileScanner(configuration, file);
Set files = fileScanner.getFiles(urisAlreadyProcessed);
- assertThat(files.size(), equalTo(6));
- assertThat(files, hasItem(new File("src/test-integration/resources/jsSearch/root.js")));
- assertThat(files, hasItem(new File("src/test-integration/resources/jsSearch/root-empty.js")));
- assertThat(files, hasItem(new File("src/test-integration/resources/jsSearch/level1/level1.js")));
- assertThat(files, hasItem(new File("src/test-integration/resources/jsSearch/level1/level2/level2.js")));
- assertThat(files, hasItem(new File("src/test-integration/resources/jsSearch/level1/level2/level2-empty.js")));
- assertThat(files, hasItem(new File("src/test-integration/resources/jsSearch/noInstrument/noInstrument.js")));
+ assertThat(files.size()).isEqualTo(6);
+ assertThat(files).contains(new File("src/test-integration/resources/jsSearch/root.js"));
+ assertThat(files).contains(new File("src/test-integration/resources/jsSearch/root-empty.js"));
+ assertThat(files).contains(new File("src/test-integration/resources/jsSearch/level1/level1.js"));
+ assertThat(files).contains(new File("src/test-integration/resources/jsSearch/level1/level2/level2.js"));
+ assertThat(files).contains(new File("src/test-integration/resources/jsSearch/level1/level2/level2-empty.js"));
+ assertThat(files).contains(new File("src/test-integration/resources/jsSearch/noInstrument/noInstrument.js"));
}
@Test
@@ -394,13 +392,13 @@ public void shouldFindAllJavaScriptFilesForFileConfig() {
fileScanner = new FileScanner(configuration, file);
Set files = fileScanner.getFiles(urisAlreadyProcessed);
- assertThat(files.size(), equalTo(6));
- assertThat(files, hasItem(new File("src/test-integration/resources/jsSearch/root.js")));
- assertThat(files, hasItem(new File("src/test-integration/resources/jsSearch/root-empty.js")));
- assertThat(files, hasItem(new File("src/test-integration/resources/jsSearch/level1/level1.js")));
- assertThat(files, hasItem(new File("src/test-integration/resources/jsSearch/level1/level2/level2.js")));
- assertThat(files, hasItem(new File("src/test-integration/resources/jsSearch/level1/level2/level2-empty.js")));
- assertThat(files, hasItem(new File("src/test-integration/resources/jsSearch/noInstrument/noInstrument.js")));
+ assertThat(files.size()).isEqualTo(6);
+ assertThat(files).contains(new File("src/test-integration/resources/jsSearch/root.js"));
+ assertThat(files).contains(new File("src/test-integration/resources/jsSearch/root-empty.js"));
+ assertThat(files).contains(new File("src/test-integration/resources/jsSearch/level1/level1.js"));
+ assertThat(files).contains(new File("src/test-integration/resources/jsSearch/level1/level2/level2.js"));
+ assertThat(files).contains(new File("src/test-integration/resources/jsSearch/level1/level2/level2-empty.js"));
+ assertThat(files).contains(new File("src/test-integration/resources/jsSearch/noInstrument/noInstrument.js"));
}
@Test
@@ -413,12 +411,12 @@ public void shouldFindAllJavaScriptFilesExcludingAlreadyParsedScripts() {
urisAlreadyProcessed.add("level2/level2.js");
Set files = fileScanner.getFiles(urisAlreadyProcessed);
- assertThat(files.size(), equalTo(5));
- assertThat(files, hasItem(new File("src/test-integration/resources/jsSearch/root-empty.js")));
- assertThat(files, hasItem(new File("src/test-integration/resources/jsSearch/level1/level1.js")));
- assertThat(files, hasItem(new File("src/test-integration/resources/jsSearch/level1/level2/level2.js")));
- assertThat(files, hasItem(new File("src/test-integration/resources/jsSearch/level1/level2/level2-empty.js")));
- assertThat(files, hasItem(new File("src/test-integration/resources/jsSearch/noInstrument/noInstrument.js")));
+ assertThat(files.size()).isEqualTo(5);
+ assertThat(files).contains(new File("src/test-integration/resources/jsSearch/root-empty.js"));
+ assertThat(files).contains(new File("src/test-integration/resources/jsSearch/level1/level1.js"));
+ assertThat(files).contains(new File("src/test-integration/resources/jsSearch/level1/level2/level2.js"));
+ assertThat(files).contains(new File("src/test-integration/resources/jsSearch/level1/level2/level2-empty.js"));
+ assertThat(files).contains(new File("src/test-integration/resources/jsSearch/noInstrument/noInstrument.js"));
}
@Test
@@ -430,12 +428,12 @@ public void shouldExcludeNoInstrument() {
fileScanner = new FileScanner(configuration, file);
Set files = fileScanner.getFiles(urisAlreadyProcessed);
- assertThat(files.size(), equalTo(5));
- assertThat(files, hasItem(new File("src/test-integration/resources/jsSearch/root.js")));
- assertThat(files, hasItem(new File("src/test-integration/resources/jsSearch/root-empty.js")));
- assertThat(files, hasItem(new File("src/test-integration/resources/jsSearch/level1/level1.js")));
- assertThat(files, hasItem(new File("src/test-integration/resources/jsSearch/level1/level2/level2.js")));
- assertThat(files, hasItem(new File("src/test-integration/resources/jsSearch/level1/level2/level2-empty.js")));
+ assertThat(files.size()).isEqualTo(5);
+ assertThat(files).contains(new File("src/test-integration/resources/jsSearch/root.js"));
+ assertThat(files).contains(new File("src/test-integration/resources/jsSearch/root-empty.js"));
+ assertThat(files).contains(new File("src/test-integration/resources/jsSearch/level1/level1.js"));
+ assertThat(files).contains(new File("src/test-integration/resources/jsSearch/level1/level2/level2.js"));
+ assertThat(files).contains(new File("src/test-integration/resources/jsSearch/level1/level2/level2-empty.js"));
}
@Test
@@ -453,8 +451,8 @@ public void shouldExcludeSrcCopiedForReportWhenReportDirIsInDocumentRoot() {
ioUtils.copy(rootJS, rootJSReportCopy);
Set files = fileScanner.getFiles(urisAlreadyProcessed);
- assertThat(files.size(), equalTo(1));
- assertThat(files, hasItem(rootJSSourceCopy));
+ assertThat(files.size()).isEqualTo(1);
+ assertThat(files).contains(rootJSSourceCopy);
}
@Test
@@ -466,8 +464,8 @@ public void shouldIncludeOnlyInstrument() {
fileScanner = new FileScanner(configuration, file);
Set files = fileScanner.getFiles(urisAlreadyProcessed);
- assertThat(files.size(), equalTo(2));
- assertThat(files, hasItem(new File("src/test-integration/resources/jsSearch/level1/level2/level2.js")));
- assertThat(files, hasItem(new File("src/test-integration/resources/jsSearch/level1/level2/level2-empty.js")));
+ assertThat(files.size()).isEqualTo(2);
+ assertThat(files).contains(new File("src/test-integration/resources/jsSearch/level1/level2/level2.js"));
+ assertThat(files).contains(new File("src/test-integration/resources/jsSearch/level1/level2/level2-empty.js"));
}
}
diff --git a/src/test/java/jscover/util/IoServiceTest.java b/src/test/java/jscover/util/IoServiceTest.java
index 12920d2b..1a464a6d 100644
--- a/src/test/java/jscover/util/IoServiceTest.java
+++ b/src/test/java/jscover/util/IoServiceTest.java
@@ -354,8 +354,7 @@ You should also get your employer (if you work as a programmer) or your
import java.util.Calendar;
import java.util.Date;
-import static org.hamcrest.MatcherAssert.assertThat;
-import static org.hamcrest.Matchers.*;
+import static org.assertj.core.api.Assertions.assertThat;
import static org.mockito.BDDMockito.given;
@ExtendWith(MockitoExtension.class)
@@ -387,8 +386,8 @@ public void shouldGenerateReportVersionAndDate() {
String html = ioService.generateJSCoverageHtml("1.0.18-SNAPSHOT");
- assertThat(html, containsString("This is version 1.0.18-SNAPSHOT of JSCover"));
- assertThat(html, containsString("Report generated at 15:12:55 25 Feb 2015"));
+ assertThat(html).contains("This is version 1.0.18-SNAPSHOT of JSCover");
+ assertThat(html).contains("Report generated at 15:12:55 25 Feb 2015");
}
@Test
@@ -396,12 +395,12 @@ public void shouldGenerateReportForFileSystem() {
ioService.generateJSCoverFilesForFileSystem(destDir, "theVersion");
String html = ioUtils.loadFromFileSystem(new File(destDir,"jscoverage.html"));
- assertThat(html, containsString("This is version theVersion of JSCover"));
+ assertThat(html).contains("This is version theVersion of JSCover");
String js = ioUtils.loadFromFileSystem(new File(destDir,"jscoverage.js"));
- assertThat(js, not(containsString("\njscoverage_isReport = true;")));
- assertThat(js, not(containsString("localStorage")));
- assertThat(new File(destDir,"jscoverage-clear-local-storage.html").exists(), is(false));
+ assertThat(js).doesNotContain("\njscoverage_isReport = true;");
+ assertThat(js).doesNotContain("localStorage");
+ assertThat(new File(destDir,"jscoverage-clear-local-storage.html").exists()).isFalse();
}
@Test
@@ -410,12 +409,12 @@ public void shouldGenerateJSForFileSystemWithLocalStorage() {
ioService.generateJSCoverFilesForFileSystem(destDir, "theVersion");
String html = ioUtils.loadFromFileSystem(new File(destDir,"jscoverage.html"));
- assertThat(html, containsString("This is version theVersion of JSCover"));
+ assertThat(html).contains("This is version theVersion of JSCover");
String js = ioUtils.loadFromFileSystem(new File(destDir, "jscoverage.js"));
- assertThat(js, not(containsString("\njscoverage_isReport = true;")));
- assertThat(js, containsString("localStorage"));
- assertThat(new File(destDir,"jscoverage-clear-local-storage.html").exists(), is(true));
+ assertThat(js).doesNotContain("\njscoverage_isReport = true;");
+ assertThat(js).contains("localStorage");
+ assertThat(new File(destDir,"jscoverage-clear-local-storage.html").exists()).isTrue();
}
@Test
@@ -423,25 +422,25 @@ public void shouldGenerateReportForWebServerStoredReport() {
ioService.generateJSCoverFilesForWebServer(destDir, "theVersion");
String html = ioUtils.loadFromFileSystem(new File(destDir,"jscoverage.html"));
- assertThat(html, containsString("This is version theVersion of JSCover"));
+ assertThat(html).contains("This is version theVersion of JSCover");
String js = ioUtils.loadFromFileSystem(new File(destDir,"jscoverage.js"));
- assertThat(js, containsString("\njscoverage_isReport = true;"));
- assertThat(js, not(containsString("localStorage")));
+ assertThat(js).contains("\njscoverage_isReport = true;");
+ assertThat(js).doesNotContain("localStorage");
}
@Test
public void shouldGenerateJSForWebServer() {
String js = ioService.generateJSCoverageServerJS();
- assertThat(js, containsString("\njscoverage_isServer = true;"));
- assertThat(js, not(containsString("localStorage")));
+ assertThat(js).contains("\njscoverage_isServer = true;");
+ assertThat(js).doesNotContain("localStorage");
}
@Test
public void shouldGenerateJSForWebServerWithLocalStorage() {
IoService ioService = new IoService(true);
String js = ioService.generateJSCoverageServerJS();
- assertThat(js, containsString("\njscoverage_isServer = true;"));
- assertThat(js, containsString("localStorage"));
+ assertThat(js).contains("\njscoverage_isServer = true;");
+ assertThat(js).contains("localStorage");
}
}
diff --git a/src/test/java/jscover/util/IoUtilsTest.java b/src/test/java/jscover/util/IoUtilsTest.java
index 57aa7518..8eb510b4 100644
--- a/src/test/java/jscover/util/IoUtilsTest.java
+++ b/src/test/java/jscover/util/IoUtilsTest.java
@@ -342,7 +342,6 @@ You should also get your employer (if you work as a programmer) or your
package jscover.util;
-import org.hamcrest.Matchers;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.mockito.Mock;
@@ -355,8 +354,7 @@ You should also get your employer (if you work as a programmer) or your
import java.nio.charset.Charset;
import java.util.Properties;
-import static org.hamcrest.CoreMatchers.equalTo;
-import static org.hamcrest.MatcherAssert.assertThat;
+import static org.assertj.core.api.Assertions.assertThat;
import static org.junit.jupiter.api.Assertions.*;
import static org.mockito.BDDMockito.given;
import static org.mockito.Mockito.*;
@@ -409,7 +407,7 @@ public void shouldWrapExceptionsInToStringInputStream() {
public void shouldConvertInputStreamToString() {
String data = "Test";
byte bytes[] = data.getBytes();
- assertThat(ioUtils.toStringNoClose(new ByteArrayInputStream(bytes), bytes.length), equalTo(data));
+ assertThat(ioUtils.toStringNoClose(new ByteArrayInputStream(bytes), bytes.length)).isEqualTo(data);
}
@Test
@@ -464,7 +462,7 @@ public void shouldCopyISToOSNoClose() {
ioUtils.copyNoClose(new ByteArrayInputStream(bytes), baos);
- assertThat(new String(baos.toByteArray()), equalTo(data));
+ assertThat(new String(baos.toByteArray())).isEqualTo(data);
}
@Test
@@ -487,7 +485,7 @@ public void shouldCopyISToOSNoCloseLength() {
ioUtils.copyNoClose(new ByteArrayInputStream(bytes), baos, bytes.length);
- assertThat(new String(baos.toByteArray()), equalTo(data));
+ assertThat(new String(baos.toByteArray())).isEqualTo(data);
}
@Test
@@ -617,21 +615,21 @@ public void shouldWrapExceptionsInIsSubDirectory() throws IOException {
File file = mock(File.class);
given(file.getCanonicalPath()).willThrow(new IOException("Ouch!"));
- assertThat(ioUtils.isSubDirectory(file, file), Matchers.is(false));
+ assertThat(ioUtils.isSubDirectory(file, file)).isFalse();
}
@Test
public void shouldGetRelativePath() {
- assertThat(ioUtils.getRelativePath(new File("target/test.txt"), new File("target")), equalTo("test.txt"));
- assertThat(ioUtils.getRelativePath(new File("target/level1/test.txt"), new File("target")), equalTo("level1/test.txt"));
- assertThat(ioUtils.getRelativePath(new File("target\\test.txt"), new File("target")), equalTo("test.txt"));
- assertThat(ioUtils.getRelativePath(new File("target"), new File("target")), equalTo(""));
+ assertThat(ioUtils.getRelativePath(new File("target/test.txt"), new File("target"))).isEqualTo("test.txt");
+ assertThat(ioUtils.getRelativePath(new File("target/level1/test.txt"), new File("target"))).isEqualTo("level1/test.txt");
+ assertThat(ioUtils.getRelativePath(new File("target\\test.txt"), new File("target"))).isEqualTo("test.txt");
+ assertThat(ioUtils.getRelativePath(new File("target"), new File("target"))).isEqualTo("");
}
@Test
public void shouldGetCanonicalPath() throws IOException {
File file = new File("target/test.txt");
- assertThat(ioUtils.getCanonicalPath(file), equalTo(file.getCanonicalPath()));
+ assertThat(ioUtils.getCanonicalPath(file)).isEqualTo(file.getCanonicalPath());
}
@Test
@@ -642,7 +640,7 @@ public void shouldWrapCanonicalPathException() throws IOException {
ioUtils.getCanonicalPath(file);
fail("Expected exception");
} catch (RuntimeException e) {
- assertThat(e.getMessage(), equalTo("java.io.IOException: Ouch!"));
+ assertThat(e.getMessage()).isEqualTo("java.io.IOException: Ouch!");
}
}
@@ -663,7 +661,7 @@ public void shouldWrapLoadPropertiesException() throws IOException {
ioUtils.loadProperties(properties, is);
fail("Expected exception");
} catch (RuntimeException e) {
- assertThat(e.getMessage(), equalTo("java.io.IOException: Ouch!"));
+ assertThat(e.getMessage()).isEqualTo("java.io.IOException: Ouch!");
}
}
@@ -696,41 +694,41 @@ static class Dummy extends IoUtils {}
public void shouldDetectPostIndexCRLF() {
String post = "POST /data HTTP/1.1\r\nSome Header\r\n\r\nData\r\rLine 3\n\nLine 5";
Charset charset = Charset.forName("UTF-8");
- assertThat(ioUtils.getDataIndex(post.getBytes(charset), charset), Matchers.equalTo(36));
+ assertThat(ioUtils.getDataIndex(post.getBytes(charset), charset)).isEqualTo(36);
}
@Test
public void shouldDetectPostIndexLF() {
String post = "POST /data HTTP/1.1\nSome Header\n\nData\r\n\r\nLine 3";
Charset charset = Charset.forName("UTF-8");
- assertThat(ioUtils.getDataIndex(post.getBytes(charset), charset), Matchers.equalTo(33));
+ assertThat(ioUtils.getDataIndex(post.getBytes(charset), charset)).isEqualTo(33);
}
@Test
public void shouldDetectPostIndexCR() {
String post = "POST /data HTTP/1.1\rSome Header\r\rData\r\n\r\nLine 3";
Charset charset = Charset.forName("UTF-8");
- assertThat(ioUtils.getDataIndex(post.getBytes(charset), charset), Matchers.equalTo(33));
+ assertThat(ioUtils.getDataIndex(post.getBytes(charset), charset)).isEqualTo(33);
}
@Test
public void shouldDetectFirstLineEndIndexCRLF() {
String post = "POST /data HTTP/1.1\r\nSome Header\r\n\r\nData\r\rLine 3\n\nLine 5";
Charset charset = Charset.forName("UTF-8");
- assertThat(ioUtils.getNewLineIndex(post.getBytes(charset), charset), Matchers.equalTo(19));
+ assertThat(ioUtils.getNewLineIndex(post.getBytes(charset), charset)).isEqualTo(19);
}
@Test
public void shouldDetectFirstLineEndIndexLF() {
String post = "POST /data HTTP/1.1\nSome Header\n\nData\r\n\r\nLine 3";
Charset charset = Charset.forName("UTF-8");
- assertThat(ioUtils.getNewLineIndex(post.getBytes(charset), charset), Matchers.equalTo(19));
+ assertThat(ioUtils.getNewLineIndex(post.getBytes(charset), charset)).isEqualTo(19);
}
@Test
public void shouldDetectFirstLineEndIndexCR() {
String post = "POST /data HTTP/1.1\rSome Header\r\rData\r\n\r\nLine 3";
Charset charset = Charset.forName("UTF-8");
- assertThat(ioUtils.getNewLineIndex(post.getBytes(charset), charset), Matchers.equalTo(19));
+ assertThat(ioUtils.getNewLineIndex(post.getBytes(charset), charset)).isEqualTo(19);
}
}
diff --git a/src/test/java/jscover/util/LogFormatterTest.java b/src/test/java/jscover/util/LogFormatterTest.java
index e51ab64f..a206c7ae 100644
--- a/src/test/java/jscover/util/LogFormatterTest.java
+++ b/src/test/java/jscover/util/LogFormatterTest.java
@@ -353,8 +353,7 @@ You should also get your employer (if you work as a programmer) or your
import java.util.logging.LogRecord;
import static java.util.logging.Level.FINER;
-import static org.hamcrest.MatcherAssert.assertThat;
-import static org.hamcrest.Matchers.*;
+import static org.assertj.core.api.Assertions.assertThat;
import static org.mockito.BDDMockito.given;
@ExtendWith(MockitoExtension.class)
@@ -382,7 +381,7 @@ public void tearDown() {
public void shouldFormatLogRecord() {
String actual = logFormatter.format(logRecord);
- assertThat(actual, equalTo("20130806 13:19:45.848,157,FINER,\"Hello\",Loggy,"+ System.lineSeparator()));
+ assertThat(actual).isEqualTo("20130806 13:19:45.848,157,FINER,\"Hello\",Loggy,"+ System.lineSeparator());
}
@Test
@@ -392,7 +391,7 @@ public void shouldFormatLogRecordWithParameters() {
String actual = logFormatter.format(logRecord);
- assertThat(actual, equalTo("20130806 13:19:45.848,157,FINER,\"Hello World!\",Loggy,"+ System.lineSeparator()));
+ assertThat(actual).isEqualTo("20130806 13:19:45.848,157,FINER,\"Hello World!\",Loggy,"+ System.lineSeparator());
}
@Test
@@ -402,7 +401,7 @@ public void shouldFormatLogRecordWithZeroParameters() {
String actual = logFormatter.format(logRecord);
- assertThat(actual, equalTo("20130806 13:19:45.848,157,FINER,\"Hello {0}!\",Loggy,"+ System.lineSeparator()));
+ assertThat(actual).isEqualTo("20130806 13:19:45.848,157,FINER,\"Hello {0}!\",Loggy,"+ System.lineSeparator());
}
@Test
@@ -411,7 +410,7 @@ public void shouldFormatLogRecordWithThrowable() {
String actual = logFormatter.format(logRecord);
- assertThat(actual, startsWith("20130806 13:19:45.848,157,FINER,\"Hello\",Loggy,"));
- assertThat(actual, containsString("java.lang.RuntimeException: Hey"));
+ assertThat(actual).startsWith("20130806 13:19:45.848,157,FINER,\"Hello\",Loggy,");
+ assertThat(actual).contains("java.lang.RuntimeException: Hey");
}
}
diff --git a/src/test/java/jscover/util/PatternMatcherRegExTest.java b/src/test/java/jscover/util/PatternMatcherRegExTest.java
index c7a856fd..85cb1ffb 100644
--- a/src/test/java/jscover/util/PatternMatcherRegExTest.java
+++ b/src/test/java/jscover/util/PatternMatcherRegExTest.java
@@ -344,22 +344,20 @@ You should also get your employer (if you work as a programmer) or your
import org.junit.jupiter.api.Test;
-import static org.hamcrest.MatcherAssert.assertThat;
-import static org.hamcrest.Matchers.*;
+import static org.assertj.core.api.Assertions.assertThat;
public class PatternMatcherRegExTest {
+
@Test
public void shouldMatch() {
- assertThat(PatternMatcherRegEx.getExcludePatternMatcher(".*/level2/.*").matches("/level1/level2/code.js"), is(true));
- assertThat(PatternMatcherRegEx.getIncludePatternMatcher(".*/level2/.*").matches("/level1/level2/code.js"), is(false));
- assertThat(PatternMatcherRegEx.getIncludePatternMatcher(".*/level2/.*").matches("/level1/level3/code.js"), nullValue());
-
+ assertThat(PatternMatcherRegEx.getExcludePatternMatcher(".*/level2/.*").matches("/level1/level2/code.js")).isTrue();
+ assertThat(PatternMatcherRegEx.getIncludePatternMatcher(".*/level2/.*").matches("/level1/level2/code.js")).isFalse();
+ assertThat(PatternMatcherRegEx.getIncludePatternMatcher(".*/level2/.*").matches("/level1/level3/code.js")).isNull();
}
@Test
public void shouldConvertToString() {
- assertThat(PatternMatcherRegEx.getIncludePatternMatcher(".*/level2/.*").toString(), equalTo("PatternMatcherRegEx{regPattern=.*/level2/.*, exclude=false}"));
- assertThat(PatternMatcherRegEx.getExcludePatternMatcher(".*/level2/.*").toString(), equalTo("PatternMatcherRegEx{regPattern=.*/level2/.*, exclude=true}"));
-
+ assertThat(PatternMatcherRegEx.getIncludePatternMatcher(".*/level2/.*").toString()).isEqualTo("PatternMatcherRegEx{regPattern=.*/level2/.*, exclude=false}");
+ assertThat(PatternMatcherRegEx.getExcludePatternMatcher(".*/level2/.*").toString()).isEqualTo("PatternMatcherRegEx{regPattern=.*/level2/.*, exclude=true}");
}
}
diff --git a/src/test/java/jscover/util/PatternMatcherStringTest.java b/src/test/java/jscover/util/PatternMatcherStringTest.java
index d7a07ac2..3a8f2687 100644
--- a/src/test/java/jscover/util/PatternMatcherStringTest.java
+++ b/src/test/java/jscover/util/PatternMatcherStringTest.java
@@ -344,24 +344,23 @@ You should also get your employer (if you work as a programmer) or your
import org.junit.jupiter.api.Test;
-import static org.hamcrest.MatcherAssert.assertThat;
-import static org.hamcrest.Matchers.*;
+import static org.assertj.core.api.Assertions.assertThat;
public class PatternMatcherStringTest {
private PatternMatcherString pattern = new PatternMatcherString("thePattern");
@Test
public void shouldMatch() {
- assertThat(pattern.matches("thePattern/test.js"), is(true));
+ assertThat(pattern.matches("thePattern/test.js")).isTrue();
}
@Test
public void shouldNotMatch() {
- assertThat(pattern.matches("theOtherPattern/test.js"), nullValue());
+ assertThat(pattern.matches("theOtherPattern/test.js")).isNull();
}
@Test
public void shouldConvertToString() {
- assertThat(pattern.toString(), equalTo("PatternMatcherString{pattern='thePattern'}"));
+ assertThat(pattern.toString()).isEqualTo("PatternMatcherString{pattern='thePattern'}");
}
}
diff --git a/src/test/java/jscover/util/UriFileTranslatorRegTest.java b/src/test/java/jscover/util/UriFileTranslatorRegTest.java
index 9185efd9..452575d3 100644
--- a/src/test/java/jscover/util/UriFileTranslatorRegTest.java
+++ b/src/test/java/jscover/util/UriFileTranslatorRegTest.java
@@ -346,8 +346,7 @@ You should also get your employer (if you work as a programmer) or your
import java.util.regex.Pattern;
-import static org.hamcrest.MatcherAssert.assertThat;
-import static org.hamcrest.Matchers.equalTo;
+import static org.assertj.core.api.Assertions.assertThat;
public class UriFileTranslatorRegTest {
@@ -356,7 +355,7 @@ public void shouldTranslateURIToFilePath() {
String uri = "/src/C:/dev/trunk/rpux_trunk/client/tests/src/form/field/TU_DateRange.js";
Pattern pattern = Pattern.compile("/src/(.*)");
UriFileTranslatorReg translator = new UriFileTranslatorReg(pattern, "$1");
- assertThat(translator.convertUriToFile(uri), equalTo("C:/dev/trunk/rpux_trunk/client/tests/src/form/field/TU_DateRange.js"));
+ assertThat(translator.convertUriToFile(uri)).isEqualTo("C:/dev/trunk/rpux_trunk/client/tests/src/form/field/TU_DateRange.js");
}
@Test
@@ -364,7 +363,7 @@ public void shouldTranslateURIToFilePath2() {
String uri = "/src/C:/dev/trunk/rpux_trunk/client/tests/src/form/field/TU_DateRange.js";
Pattern pattern = Pattern.compile(".*/tests/(.*)");
UriFileTranslatorReg translator = new UriFileTranslatorReg(pattern, "$1");
- assertThat(translator.convertUriToFile(uri), equalTo("src/form/field/TU_DateRange.js"));
+ assertThat(translator.convertUriToFile(uri)).isEqualTo("src/form/field/TU_DateRange.js");
}
@Test
@@ -372,7 +371,7 @@ public void shouldTranslateURIToFilePath3() {
String uri = "/src/C:/dev/trunk/rpux_trunk/client/tests/src/form/field/TU_DateRange.js";
Pattern pattern = Pattern.compile("/src/(.*)/tests(.*)");
UriFileTranslatorReg translator = new UriFileTranslatorReg(pattern, "$1$2");
- assertThat(translator.convertUriToFile(uri), equalTo("C:/dev/trunk/rpux_trunk/client/src/form/field/TU_DateRange.js"));
+ assertThat(translator.convertUriToFile(uri)).isEqualTo("C:/dev/trunk/rpux_trunk/client/src/form/field/TU_DateRange.js");
}
@Test
@@ -380,7 +379,7 @@ public void shouldTranslateURIToFilePath4() {
String uri = "/src/C:/dev/trunk/rpux_trunk/client/tests/src/form/field/TU_DateRange.js";
Pattern pattern = Pattern.compile("/src/C:/dev/trunk/rpux_trunk/client(.*)");
UriFileTranslatorReg translator = new UriFileTranslatorReg(pattern, "$1");
- assertThat(translator.convertUriToFile(uri), equalTo("/tests/src/form/field/TU_DateRange.js"));
+ assertThat(translator.convertUriToFile(uri)).isEqualTo("/tests/src/form/field/TU_DateRange.js");
}
@Test
@@ -388,6 +387,6 @@ public void shouldNotTranslateURIToFilePath() {
String uri = "/src/C:/dev/trunk/rpux_trunk/client/tests/src/form/field/TU_DateRange.js";
Pattern pattern = Pattern.compile("/srcy/(.*)/tests(.*)");
UriFileTranslatorReg translator = new UriFileTranslatorReg(pattern, "$1");
- assertThat(translator.convertUriToFile(uri), equalTo("/src/C:/dev/trunk/rpux_trunk/client/tests/src/form/field/TU_DateRange.js"));
+ assertThat(translator.convertUriToFile(uri)).isEqualTo("/src/C:/dev/trunk/rpux_trunk/client/tests/src/form/field/TU_DateRange.js");
}
}