Skip to content

Commit

Permalink
Refactoring and documentation.
Browse files Browse the repository at this point in the history
  • Loading branch information
z0rb committed Apr 4, 2016
1 parent 49dce11 commit 630f694
Show file tree
Hide file tree
Showing 6 changed files with 224 additions and 267 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
import org.camunda.bpm.extension.process_test_coverage.model.CoveredElement;
import org.camunda.bpm.extension.process_test_coverage.model.MethodCoverage;
import org.camunda.bpm.extension.process_test_coverage.model.ProcessCoverage;
import org.camunda.bpm.extension.process_test_coverage.model.ProcessCoverageBuilder;

/**
* State tracking the current class and method coverage run.
Expand All @@ -19,117 +18,120 @@
* @author okicir
*/
public class CoverageTestRunState {
private Logger log = Logger.getLogger(CoverageTestRunState.class.getCanonicalName());
/**
* The actual class coverage object.
*/

private Logger log = Logger.getLogger(CoverageTestRunState.class.getCanonicalName());

/**
* The actual class coverage object.
*/
private ClassCoverage classCoverage = new ClassCoverage();

/**
* The test class name.
*/
private String className;
private String testClassName;

/**
* The name of the currently executing test method.
*/
private String currentTestName;
private String currentTestMethodName;

/**
* Adds the covered element to the current test run coverage.
*
* @param coveredElement
*/
public void addCoveredElement(/*@NotNull*/ CoveredElement coveredElement) {

if (log.isLoggable(Level.FINE)) {
log.info("notifyCoveredElement(" + coveredElement + ")");
}

classCoverage.addCoveredElement(currentTestName, coveredElement);

}

/**
* Adds a test method to the class coverage.
*
* @param processEngine
* @param deploymentId The deployment ID of the test method run. (Hint: Every test method run has its own deployment.)
* @param processDefinitions The process definitions of the test method deployment.
* @param testName The name of the test method.
*/
public void addTestMethodRun(ProcessEngine processEngine, String deploymentId,
List<ProcessDefinition> processDefinitions, String testName) {

final MethodCoverage testCoverage = new MethodCoverage(deploymentId);
for (ProcessDefinition processDefinition : processDefinitions) {

// Construct the pristine coverage object

// TODO decide on the builders fate
final ProcessCoverage processCoverage = ProcessCoverageBuilder.createFlowNodeAndSequenceFlowCoverage(processEngine)
.forProcess(processDefinition).build();

testCoverage.addProcessCoverage(processCoverage);
}

classCoverage.addTestMethodCoverage(testName, testCoverage);
}

/**
* Retrieves the coverage for a test method.
*
* @param testName
* @return
*/
public MethodCoverage getTestMethodCoverage(String testName) {
return classCoverage.getTestMethodCoverage(testName);
}

/**
* Retrieves the currently executing test method coverage.
*
* @return
*/
public MethodCoverage getCurrentTestMethodCoverage() {
return classCoverage.getTestMethodCoverage(currentTestName);
public void addCoveredElement(/* @NotNull */ CoveredElement coveredElement) {

if (log.isLoggable(Level.FINE)) {
log.info("notifyCoveredElement(" + coveredElement + ")");
}

classCoverage.addCoveredElement(currentTestMethodName, coveredElement);

}

/**
* Adds a test method to the class coverage.
*
* @param processEngine
* @param deploymentId
* The deployment ID of the test method run. (Hint: Every test
* method run has its own deployment.)
* @param processDefinitions
* The process definitions of the test method deployment.
* @param testName
* The name of the test method.
*/
public void addTestMethodRun(ProcessEngine processEngine, String deploymentId,
List<ProcessDefinition> processDefinitions, String testName) {

final MethodCoverage testCoverage = new MethodCoverage(deploymentId);
for (ProcessDefinition processDefinition : processDefinitions) {

// Construct the pristine coverage object

// TODO decide on the builders fate
final ProcessCoverage processCoverage = new ProcessCoverage(processEngine, processDefinition);

testCoverage.addProcessCoverage(processCoverage);
}

classCoverage.addTestMethodCoverage(testName, testCoverage);
}

/**
* Retrieves the coverage for a test method.
*
* @param testName
* @return
*/
public MethodCoverage getTestMethodCoverage(String testName) {
return classCoverage.getTestMethodCoverage(testName);
}

/**
* Retrieves the currently executing test method coverage.
*
* @return
*/
public MethodCoverage getCurrentTestMethodCoverage() {
return classCoverage.getTestMethodCoverage(currentTestMethodName);
}
/**
* Retrieves the class coverage.
*
* @return
*/
public ClassCoverage getClassCoverage() {
return classCoverage;
}
/**
* Retrieves the name of the currently executing test method.
*
* @return
*/
public String getCurrentTestName() {
return currentTestName;

/**
* Retrieves the class coverage.
*
* @return
*/
public ClassCoverage getClassCoverage() {
return classCoverage;
}

/**
* Retrieves the name of the currently executing test method.
*
* @return
*/
public String getCurrentTestMethodName() {
return currentTestMethodName;
}

/**
* Sets the name of the currently executing test mehod.
*
* @param currentTestName
*/
public void setCurrentTestName(String currentTestName) {
this.currentTestName = currentTestName;
public void setCurrentTestMethodName(String currentTestName) {
this.currentTestMethodName = currentTestName;
}

public String getClassName() {
return className;
public String getTestClassName() {
return testClassName;
}

public void setClassName(String className) {
this.className = className;
public void setTestClassName(String className) {
this.testClassName = className;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -202,12 +202,12 @@ private void initializeRunState(final Description description) {
if (firstRun) {

coverageTestRunState = new CoverageTestRunState();
coverageTestRunState.setClassName(description.getClassName());
coverageTestRunState.setTestClassName(description.getClassName());

firstRun = false;
}

coverageTestRunState.setCurrentTestName(description.getMethodName());
coverageTestRunState.setCurrentTestMethodName(description.getMethodName());

}

Expand Down
Loading

0 comments on commit 630f694

Please sign in to comment.