-
Notifications
You must be signed in to change notification settings - Fork 47
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
145 additions
and
110 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
109 changes: 67 additions & 42 deletions
109
...bpm/extension/process_test_coverage/junit/rules/TestCoverageProcessEngineRuleBuilder.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,70 +1,95 @@ | ||
package org.camunda.bpm.extension.process_test_coverage.junit.rules; | ||
|
||
/** | ||
* Fluent Builder for TestCoverageProcessEngineRule. | ||
* | ||
*/ | ||
public class TestCoverageProcessEngineRuleBuilder { | ||
|
||
/** | ||
* If you set this property to a ratio (e.g. "1.0" for full coverage), | ||
/** | ||
* If you set this property to a ratio (e.g. "1.0" for full coverage), | ||
* the @ClassRule will fail the test run if the coverage is less.<br> | ||
* Example parameter for running java:<br> | ||
* <code>-Dorg.camunda.bpm.extension.process_test_coverage.ASSERT_AT_LEAST=1.0</code> | ||
*/ | ||
public static final String DEFAULT_ASSERT_AT_LEAST_PROPERTY = "org.camunda.bpm.extension.process_test_coverage.ASSERT_AT_LEAST"; | ||
|
||
TestCoverageProcessEngineRule rule = new TestCoverageProcessEngineRule(); | ||
|
||
/** @return a builder with typical method @Rule configuration */ | ||
public static TestCoverageProcessEngineRuleBuilder create() { | ||
return createBase() | ||
.optionalAssertCoverageAtLeastProperty(DEFAULT_ASSERT_AT_LEAST_PROPERTY); | ||
|
||
private TestCoverageProcessEngineRule rule = new TestCoverageProcessEngineRule(); | ||
|
||
/** | ||
* Creates a TestCoverageProcessEngineRuleBuilder with the default class | ||
* coverage assertion property activated. | ||
* | ||
* @return | ||
*/ | ||
public static TestCoverageProcessEngineRuleBuilder create() { | ||
return createBase().optionalAssertCoverageAtLeastProperty(DEFAULT_ASSERT_AT_LEAST_PROPERTY); | ||
} | ||
|
||
/** | ||
* Set the system property name for minimal class coverage assertion. | ||
* | ||
* @param key | ||
* System property name. | ||
* @return | ||
*/ | ||
public TestCoverageProcessEngineRuleBuilder optionalAssertCoverageAtLeastProperty(String key) { | ||
|
||
String assertAtLeast = System.getProperty(key); | ||
if (assertAtLeast != null) { | ||
try{ | ||
|
||
final MinimalCoverageMatcher minimalCoverageMatcher = new MinimalCoverageMatcher(Double.parseDouble(assertAtLeast)); | ||
try { | ||
|
||
final MinimalCoverageMatcher minimalCoverageMatcher = new MinimalCoverageMatcher( | ||
Double.parseDouble(assertAtLeast)); | ||
rule.addClassCoverageAssertionMatcher(minimalCoverageMatcher); | ||
|
||
}catch(NumberFormatException e) { | ||
throw new RuntimeException("BAD TEST CONFIGURATION: optionalAssertCoverageAtLeastProperty( \"" + key + "\" ) must be double"); | ||
|
||
} catch (NumberFormatException e) { | ||
throw new RuntimeException("BAD TEST CONFIGURATION: optionalAssertCoverageAtLeastProperty( \"" + key | ||
+ "\" ) must be double"); | ||
} | ||
} | ||
return this; | ||
} | ||
|
||
/** @return a builder with typical method @ClassRule configuration */ | ||
public static TestCoverageProcessEngineRuleBuilder createClassRule() { | ||
return createBase().reportCoverageAfter() | ||
.optionalAssertCoverageAtLeastProperty(DEFAULT_ASSERT_AT_LEAST_PROPERTY); | ||
} | ||
/** @return a basic builder with nothing preconfigured */ | ||
public static TestCoverageProcessEngineRuleBuilder createBase() { | ||
return new TestCoverageProcessEngineRuleBuilder(); | ||
} | ||
|
||
/** | ||
* Enables detailed logging of individual class and method coverage objects. | ||
* | ||
* @return | ||
*/ | ||
public TestCoverageProcessEngineRuleBuilder withDetailedCoverageLogging() { | ||
rule.setDetailedCoverageLogging(true); | ||
return this; | ||
} | ||
|
||
/** | ||
* Asserts if the class coverage is greater than the passed percentage. | ||
* | ||
* @param percentage | ||
* @return | ||
*/ | ||
public TestCoverageProcessEngineRuleBuilder assertClassCoverageAtLeast(double percentage) { | ||
|
||
/** @return a basic builder with nothing preconfigured */ | ||
public static TestCoverageProcessEngineRuleBuilder createBase() { | ||
return new TestCoverageProcessEngineRuleBuilder(); | ||
} | ||
if (0 > percentage || percentage > 1) { | ||
throw new RuntimeException( | ||
"BAD TEST CONFIGURATION: coverageAtLeast " + percentage + " (" + 100 * percentage + "%) "); | ||
} | ||
|
||
public TestCoverageProcessEngineRuleBuilder reportCoverageAfter() { | ||
rule.setReportCoverageWhenFinished(true); | ||
return this; | ||
} | ||
rule.addClassCoverageAssertionMatcher(new MinimalCoverageMatcher(percentage)); | ||
return this; | ||
|
||
public TestCoverageProcessEngineRuleBuilder assertGlobalCoverageAtLeast(double percentage) { | ||
|
||
if (0 > percentage || percentage > 1) { | ||
throw new RuntimeException("BAD TEST CONFIGURATION: coverageAtLeast " + percentage + " (" + 100*percentage + "%) "); | ||
} | ||
|
||
rule.addClassCoverageAssertionMatcher(new MinimalCoverageMatcher(percentage)); | ||
return this; | ||
|
||
} | ||
} | ||
|
||
public TestCoverageProcessEngineRule build() { | ||
return rule; | ||
} | ||
/** | ||
* Builds the coverage rule. | ||
* | ||
* @return | ||
*/ | ||
public TestCoverageProcessEngineRule build() { | ||
return rule; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.