Skip to content

Commit

Permalink
docs: Javadoc blocks added for lint compliancy.
Browse files Browse the repository at this point in the history
  • Loading branch information
pboychev-bcom committed Nov 19, 2024
1 parent fcef83f commit 6f67b3f
Showing 1 changed file with 147 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -46,32 +46,51 @@ public abstract class AbstractVroTestMojo extends AbstractMojo {
@Parameter(required = false, property = "test", defaultValue = "${test.*}")
private Map<String, String> test;

/**
* Triggers the unit tests execution.
*
* @throws MojoExecutionException
* @throws MojoFailureException
*/
public void execute() throws MojoExecutionException, MojoFailureException {
if (skipTests) {
getLog().info("Tests are skipped.");
}
else if (!hasTests()) {
} else if (!hasTests()) {
getLog().info("No test files found.");
}
else {
} else {
Configuration config = new Configuration(test);
printStarted(config);
buildTestbed(config);
runTests(config);
}
}

/**
* @return A flag indicating whether or not tests exist for the project.
*/
protected Boolean hasTests() {
return new File(getCliPath()).exists();
}

/**
* Prints a message indicating the testing step is starting.
*
* @param config
*/
protected void printStarted(Configuration config) {
getLog().info("");
getLog().info("-------------------------------------------------------");
getLog().info(" T E S T S");
getLog().info("-------------------------------------------------------");
}

/**
* Bootstrapping the unit tests.
*
* @param config
* @throws org.apache.maven.plugin.MojoExecutionException
* @throws org.apache.maven.plugin.MojoFailureException
*/
protected void buildTestbed(Configuration config)
throws org.apache.maven.plugin.MojoExecutionException,
org.apache.maven.plugin.MojoFailureException {
Expand All @@ -84,6 +103,12 @@ protected void buildTestbed(Configuration config)
.execute(getLog());
}

/**
* Build the command for running the tests.
*
* @param config
* @return The command to be executed for running the tests.
*/
protected List<String> buildTestbedCommand(Configuration config) {
String projectRoot = project.getBasedir().toPath().toString();
List<String> cmd = new ArrayList<>();
Expand Down Expand Up @@ -121,7 +146,7 @@ protected List<String> buildTestbedCommand(Configuration config) {
cmd.add(coverageThresholds);
}

if(config.isPerFileEnabled()){
if (config.isPerFileEnabled()) {
cmd.add("--per-file");
cmd.add("true");
}
Expand All @@ -131,6 +156,12 @@ protected List<String> buildTestbedCommand(Configuration config) {

protected abstract void addTestbedPaths(List<String> cmd, Configuration config);

/**
* Uses the project configuration it its pom file to build the tests coverage threshold values.
*
* @param config
* @return The threshold values list.
*/
protected String buildCoverageThresholdToken(Configuration config) {
List<String> thresholds = new ArrayList<String>(5);

Expand Down Expand Up @@ -167,6 +198,13 @@ protected String buildCoverageThresholdToken(Configuration config) {
return String.join(",", thresholds);
}

/**
* Builds and executes the tests run.
*
* @param config
* @throws org.apache.maven.plugin.MojoExecutionException
* @throws org.apache.maven.plugin.MojoFailureException
*/
protected void runTests(Configuration config)
throws org.apache.maven.plugin.MojoExecutionException, org.apache.maven.plugin.MojoFailureException {
new ProcessExecutor()
Expand All @@ -178,6 +216,12 @@ protected void runTests(Configuration config)
.execute(getLog());
}

/**
* Builds the command for running the tests.
*
* @param config
* @return
*/
protected List<String> buildRunCommand(Configuration config) {
List<String> cmd = new ArrayList<>();
cmd.add(getCliPath());
Expand All @@ -190,7 +234,11 @@ protected List<String> buildRunCommand(Configuration config) {
return cmd;
}


/**
* Returns the path tot the vrotest dependency.
*
* @return The path to the vrotest dependency.
*/
protected String getCliPath() {
String projectRoot = project.getBasedir().toPath().toString();
String vrotestCmd = SystemUtils.IS_OS_WINDOWS ? "vrotest.cmd" : "vrotest";
Expand Down Expand Up @@ -225,93 +273,186 @@ public Configuration(Map<String, String> props) {
this.props = props;
}

/**
* Returns a flag whether or not code report is enabled.
*
* @return The flag value.
*/
public Boolean isCoverageEnabled() {
String value = props.get(COVERAGE_ENABLED);
return value != null && Boolean.parseBoolean(value);
}

/**
* Returns a a list of code coverage reports.
*
* @return The coverate list.
*/
public List<String> getCoverageReports() {
String value = props.get(COVERAGE_REPORTS);
return Arrays.asList((value != null ? value.trim() : "").split(",")).stream()
.map(reportName -> reportName.trim())
.collect(Collectors.toList());
}

/**
* Loads the configuration value for maximum allowed errors value.
*
* @return The configuration value.
*/
public Integer getCoverageThresholdError() {
String value = props.get(COVERAGE_THRESHOLD_ERROR);
return value != null ? Integer.parseInt(value) : 0;
}

/**
* Loads the configuration value for maximum allowed warnings value.
*
* @return The configuration value.
*/
public Integer getCoverageThresholdWarn() {
String value = props.get(COVERAGE_THRESHOLD_WARN);
return value != null ? Integer.parseInt(value) : 0;
}

/**
* Loads the configuration value for maximum allowed errors per branch value.
*
* @return The configuration value.
*/
public Integer getCoverageBranchesThresholdError() {
String value = props.get(COVERAGE_THRESHOLD_BRANCHES_ERROR);
return value != null ? Integer.parseInt(value) : 0;
}

/**
* Loads the configuration value for maximum allowed warnings per branch value.
*
* @return The configuration value.
*/
public Integer getCoverageBranchesThresholdWarn() {
String value = props.get(COVERAGE_THRESHOLD_BRANCHES_WARN);
return value != null ? Integer.parseInt(value) : 0;
}

/**
* Loads the configuration value for maximum allowed errors for lines.
*
* @return The configuration value.
*/
public Integer getCoverageLinesThresholdError() {
String value = props.get(COVERAGE_THRESHOLD_LINES_ERROR);
return value != null ? Integer.parseInt(value) : 0;
}

/**
* Loads the configuration value for maximum allowed warnings for lines.
*
* @return The configuration value.
*/
public Integer getCoverageLinesThresholdWarn() {
String value = props.get(COVERAGE_THRESHOLD_LINES_WARN);
return value != null ? Integer.parseInt(value) : 0;
}

/**
* Loads the configuration value for maximum allowed errors for functions.
*
* @return The configuration value.
*/
public Integer getCoverageFunctionsThresholdError() {
String value = props.get(COVERAGE_THRESHOLD_FUNCS_ERROR);
return value != null ? Integer.parseInt(value) : 0;
}

/**
* Loads the configuration value for maximum allowed warnings for functions.
*
* @return The configuration value.
*/
public Integer getCoverageFunctionsThresholdWarn() {
String value = props.get(COVERAGE_THRESHOLD_FUNCS_WARN);
return value != null ? Integer.parseInt(value) : 0;
}

/**
* Loads the configuration value for maximum allowed errors for statements.
*
* @return The configuration value.
*/
public Integer getCoverageStatementsThresholdError() {
String value = props.get(COVERAGE_THRESHOLD_STMTS_ERROR);
return value != null ? Integer.parseInt(value) : 0;
}

/**
* Loads the configuration value for maximum allowed warnings for statements.
*
* @return The configuration value.
*/
public Integer getCoverageStatementsThresholdWarn() {
String value = props.get(COVERAGE_THRESHOLD_STMTS_WARN);
return value != null ? Integer.parseInt(value) : 0;
}

/**
* Loads the configuration flag value for per-file coverate.
*
* @return The configuration value.
*/
public Boolean isPerFileEnabled() {
String value = props.get(COVERAGE_TEST_PERFILE);
return value != null && Boolean.parseBoolean(value);
}

/**
* Returns the framework package name - "jasmine" or "jest".
*
* @return The configuration value.
*/
public String getFrameworkPackageName() {
String value = props.get(FRAMEWORK_PACKAGE_NAME);
return value != null ? value : "";
}

/**
* Returns the framework package version.
*
* @return The configuration value.
*/
public String getFrameworkVersion() {
String value = props.get(FRAMEWORK_VERSION);
return value != null ? value : "";
}

/**
* Returns the version of the Jasmine reporters package.
* Supported when Jasmine is used as tests framework.
*
* @return The configuration value.
*/
public String getJasmineReportersVersion() {
String value = props.get(JASMINE_REPORTERS_VERSION);
return value != null ? value : "";
}

/**
* Returns the version of the Ansi Colors package.
* Supported when Jasmine is used as tests framework.
*
* @return The configuration value.
*/
public String getAnsiColorsVersion() {
String value = props.get(ANSI_COLORS_VERSION);
return value != null ? value : "";
}

/**
* Returns the type of tests runner to be used - supports either none or "swc".
* Supported when Jest is used as tests framework.
*
* @return The configuration value.
*/
public String getTestsRunner() {
String value = props.get(TESTS_RUNNER);
return value != null ? value : "";
Expand Down

0 comments on commit 6f67b3f

Please sign in to comment.