summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorbculkin2442 <bjculkin@mix.wvu.edu>2018-10-28 12:22:24 -0400
committerbculkin2442 <bjculkin@mix.wvu.edu>2018-10-28 12:22:24 -0400
commitaca7e1aba47667f23c2b66d0c8a79d41b7481e07 (patch)
treeee4cd96abce8b334a400b5e99fd7cfc02a7b56d5
parent3e5e991e8c7a6f30b224522efeb2dd177d598ffa (diff)
Testing
Doing more command testing, and introducing coverage testing
-rw-r--r--base/pom.xml57
-rw-r--r--base/src/main/java/bjc/utils/cli/objects/Command.java23
-rw-r--r--base/src/test/java/bjc/utils/cli/objects/CommandTest.java9
3 files changed, 71 insertions, 18 deletions
diff --git a/base/pom.xml b/base/pom.xml
index 1415276..f5eea88 100644
--- a/base/pom.xml
+++ b/base/pom.xml
@@ -1,4 +1,5 @@
-<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+<project xmlns="http://maven.apache.org/POM/4.0.0"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
@@ -11,6 +12,58 @@
<build>
<plugins>
<plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-surefire-plugin</artifactId>
+ <configuration>
+ <!-- Sets the VM argument line used
+ when unit tests are run. -->
+ <argLine>${surefireArgLine}</argLine>
+ </configuration>
+ </plugin>
+ <plugin>
+ <groupId>org.jacoco</groupId>
+ <artifactId>jacoco-maven-plugin</artifactId>
+ <version>0.8.2</version>
+ <executions>
+ <!--
+ Prepares the property pointing to the JaCoCo runtime agent which
+ is passed as VM argument when Maven the Surefire plugin is executed.
+ -->
+ <execution>
+ <id>pre-unit-test</id>
+ <goals>
+ <goal>prepare-agent</goal>
+ </goals>
+ <configuration>
+ <!-- Sets the path to the file which contains the execution data. -->
+ <destFile>${project.build.directory}/coverage-reports/jacoco-ut.exec</destFile>
+ <!--
+ Sets the name of the property containing the settings
+ for JaCoCo runtime agent.
+ -->
+ <propertyName>surefireArgLine</propertyName>
+ </configuration>
+ </execution>
+ <!--
+ Ensures that the code coverage report for unit tests is created after
+ unit tests have been run.
+ -->
+ <execution>
+ <id>post-unit-test</id>
+ <phase>test</phase>
+ <goals>
+ <goal>report</goal>
+ </goals>
+ <configuration>
+ <!-- Sets the path to the file which contains the execution data. -->
+ <dataFile>${project.build.directory}/coverage-reports/jacoco-ut.exec</dataFile>
+ <!-- Sets the output directory for the code coverage report. -->
+ <outputDirectory>${project.reporting.outputDirectory}/jacoco-ut</outputDirectory>
+ </configuration>
+ </execution>
+ </executions>
+ </plugin>
+ <plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.7.0</version>
@@ -91,5 +144,7 @@
<artifactId>icu4j</artifactId>
<version>58.2</version>
</dependency>
+
+
</dependencies>
</project>
diff --git a/base/src/main/java/bjc/utils/cli/objects/Command.java b/base/src/main/java/bjc/utils/cli/objects/Command.java
index e31839c..2be7fcd 100644
--- a/base/src/main/java/bjc/utils/cli/objects/Command.java
+++ b/base/src/main/java/bjc/utils/cli/objects/Command.java
@@ -138,8 +138,7 @@ public class Command {
* @param rDelm
* The regex to stop substringing at.
*
- * @return The first capturing group (the entire match otherwise), or
- * null if there is no occurrence of the delimiter.
+ * @return The string, up to the matched pattern.
*/
public String trimToRX(String rDelm) {
return trimToRX(Pattern.compile(rDelm), true);
@@ -155,8 +154,7 @@ public class Command {
* @param delm
* The regex to stop substringing at.
*
- * @return The first capturing group (the entire match otherwise), or
- * null if there is no occurrence of the delimiter.
+ * @return The string, up to the matched pattern.
*/
public String trimToRX(Pattern delm) {
return trimToRX(delm, true);
@@ -172,8 +170,7 @@ public class Command {
* Whether or not to trim the substring and remaining
* command (Remove leading/trailing spaces).
*
- * @return The first capturing group (the entire match otherwise), or
- * null if there is no occurrence of the delimiter.
+ * @return The string, up to the matched pattern.
*/
public String trimToRX(String rDelm, boolean doTrim) {
return trimToRX(Pattern.compile(rDelm), doTrim);
@@ -189,22 +186,14 @@ public class Command {
* Whether or not to trim the substring and remaining
* command (Remove leading/trailing spaces).
*
- * @return The first capturing group (the entire match otherwise), or
- * null if there is no occurrence of the delimiter.
+ * @return The string, up to the matched pattern.
*/
public String trimToRX(Pattern delm, boolean doTrim) {
Matcher mat = delm.matcher(remn);
if (!mat.find()) return null;
- String tmp;
-
- if (mat.groupCount() > 0) {
- tmp = mat.group(1);
- remn = remn.substring(mat.end());
- } else {
- tmp = mat.group();
- remn = remn.substring(mat.end());
- }
+ String tmp = remn.substring(0, mat.start());
+ remn = remn.substring(mat.end());
if (doTrim) {
tmp = tmp.trim();
diff --git a/base/src/test/java/bjc/utils/cli/objects/CommandTest.java b/base/src/test/java/bjc/utils/cli/objects/CommandTest.java
index 129af21..a38940a 100644
--- a/base/src/test/java/bjc/utils/cli/objects/CommandTest.java
+++ b/base/src/test/java/bjc/utils/cli/objects/CommandTest.java
@@ -25,6 +25,15 @@ public class CommandTest {
assertEquals("b", com.trimTo(' '));
assertEquals("c", com.remn);
+
+ com = Command.fromString("a b c", 1, "console");
+
+ assertEquals("a b c", com.full);
+ assertEquals("a", com.name);
+ assertEquals("b c", com.remn);
+
+ assertEquals("b", com.trimTo(" "));
+ assertEquals("c", com.remn);
}
/**