Skip to content

Commit

Permalink
Add test coverage
Browse files Browse the repository at this point in the history
spotless
  • Loading branch information
snf2ye committed Aug 2, 2023
1 parent a50708f commit 0d7456e
Show file tree
Hide file tree
Showing 5 changed files with 59 additions and 2 deletions.
2 changes: 1 addition & 1 deletion cli/src/main/java/bio/terra/pfb/GitConfiguration.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public String getCliVersion() {
return readGitPropertiesValue(CLI_VERSION_BUILD_PROPERTY);
}

private String readGitPropertiesValue(String propertyName) {
String readGitPropertiesValue(String propertyName) {
String result = "";
InputStream inputStream = null;
try {
Expand Down
6 changes: 5 additions & 1 deletion cli/src/main/java/bio/terra/pfb/JavaPfbCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,14 @@
versionProvider = PfbVersion.class)
public class JavaPfbCommand implements Runnable {
public static void main(String[] args) {
int exitCode = new CommandLine(new JavaPfbCommand()).execute(args);
int exitCode = executeCommand(args);
System.exit(exitCode);
}

static int executeCommand(String[] args) {
return new CommandLine(new JavaPfbCommand()).execute(args);
}

@Override
public void run() {
System.out.println("PFB RUN");
Expand Down
9 changes: 9 additions & 0 deletions cli/src/test/java/bio/terra/pfb/GitConfigurationTest.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
package bio.terra.pfb;

import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.is;
import static org.hamcrest.Matchers.matchesPattern;
import static org.hamcrest.Matchers.nullValue;

import org.junit.jupiter.api.Test;

Expand All @@ -13,4 +15,11 @@ void getBuildVersion() {
String version = gitConfiguration.getCliVersion();
assertThat(version, matchesPattern("\\d+\\.\\d+\\.\\d"));
}

@Test
void testFileNotFound() {
GitConfiguration gitConfiguration = new GitConfiguration();
String emptyString = gitConfiguration.readGitPropertiesValue("invalid.property.name");
assertThat(emptyString, is(nullValue()));
}
}
28 changes: 28 additions & 0 deletions cli/src/test/java/bio/terra/pfb/JavaPfbCommandTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.containsString;
import static org.hamcrest.Matchers.equalTo;
import static org.hamcrest.Matchers.matchesPattern;

import java.io.ByteArrayOutputStream;
import java.io.PrintStream;
Expand Down Expand Up @@ -35,6 +37,32 @@ void run() {
assertThat(outContent.toString(), containsString("PFB RUN"));
}

@Test
void testVersionCommand() {
String[] args = new String[1];
args[0] = "--version";
javaPfbCommand.executeCommand(args);
assertThat(outContent.toString(), matchesPattern("pfb \\d+\\.\\d+\\.\\d\n"));
}

@Test
void testCorrectVersion() {
GitConfiguration gitConfiguration = new GitConfiguration();
String exepectedVersion = gitConfiguration.getCliVersion();
String[] args = new String[1];
args[0] = "--version";
javaPfbCommand.executeCommand(args);
assertThat(outContent.toString(), equalTo("pfb " + exepectedVersion + "\n"));
}

@Test
void testHelpCommand() {
String[] args = new String[1];
args[0] = "--help";
javaPfbCommand.executeCommand(args);
assertThat(outContent.toString(), containsString("Usage: pfb"));
}

@Test
void helloCommand() {
javaPfbCommand.helloCommand();
Expand Down
16 changes: 16 additions & 0 deletions cli/src/test/java/bio/terra/pfb/PfbVersionTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package bio.terra.pfb;

import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.matchesPattern;

import org.junit.jupiter.api.Test;

class PfbVersionTest {

@Test
void getVersion() {
PfbVersion pfbVersion = new PfbVersion();
String[] version = pfbVersion.getVersion();
assertThat(version[0], matchesPattern("\\$\\{COMMAND-FULL-NAME\\} \\d+\\.\\d+\\.\\d"));
}
}

0 comments on commit 0d7456e

Please sign in to comment.