-
Notifications
You must be signed in to change notification settings - Fork 40
Commit
Add a JUnit parser
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,182 @@ | ||
package edu.hm.hafner.coverage; | ||
|
||
import java.io.Serializable; | ||
|
||
import org.apache.commons.lang3.StringUtils; | ||
|
||
import com.google.errorprone.annotations.CanIgnoreReturnValue; | ||
|
||
import edu.hm.hafner.util.Generated; | ||
|
||
/** | ||
* Represents a test case that has been executed. | ||
* | ||
* @author Ullrich Hafner | ||
*/ | ||
public final class TestCase implements Serializable { | ||
private static final long serialVersionUID = -2181204291759959155L; | ||
|
||
private final String testName; | ||
private final String className; | ||
private final TestResult status; | ||
private final String type; | ||
private final String message; | ||
private final String description; | ||
|
||
private TestCase(final String testName, final String className, final TestResult status, | ||
final String type, final String message, final String description) { | ||
this.testName = testName; | ||
this.className = className.intern(); | ||
this.status = status; | ||
this.type = type; | ||
this.message = message; | ||
this.description = description; | ||
} | ||
|
||
public String getTestName() { | ||
return testName; | ||
} | ||
|
||
public String getClassName() { | ||
return className; | ||
} | ||
|
||
public TestResult getStatus() { | ||
return status; | ||
} | ||
|
||
public String getType() { | ||
return type; | ||
} | ||
|
||
public String getMessage() { | ||
return message; | ||
} | ||
|
||
public String getDescription() { | ||
return description; | ||
} | ||
|
||
@Override | ||
public boolean equals(final Object o) { | ||
if (this == o) { | ||
return true; | ||
} | ||
if (o == null || getClass() != o.getClass()) { | ||
return false; | ||
} | ||
|
||
TestCase testCase = (TestCase) o; | ||
|
||
if (!testName.equals(testCase.testName)) { | ||
return false; | ||
} | ||
if (!className.equals(testCase.className)) { | ||
return false; | ||
} | ||
if (status != testCase.status) { | ||
return false; | ||
} | ||
if (!type.equals(testCase.type)) { | ||
return false; | ||
} | ||
if (!message.equals(testCase.message)) { | ||
return false; | ||
} | ||
return description.equals(testCase.description); | ||
} | ||
|
||
@Override @Generated | ||
public String toString() { | ||
return "TestCase{testName='" + testName + '\'' + ", className='" + className + '\'' + ", status=" + status | ||
+ ", type='" + type + '\'' + ", message='" + message + '\'' + ", description='" + description + '\'' | ||
+ '}'; | ||
} | ||
|
||
@Override | ||
public int hashCode() { | ||
int result = testName.hashCode(); | ||
result = 31 * result + className.hashCode(); | ||
result = 31 * result + status.hashCode(); | ||
result = 31 * result + type.hashCode(); | ||
result = 31 * result + message.hashCode(); | ||
result = 31 * result + description.hashCode(); | ||
return result; | ||
} | ||
|
||
/** | ||
* Builder to create new {@link TestCase} instances. | ||
*/ | ||
@SuppressWarnings({"checkstyle:MissingJavadocMethod", "checkstyle:HiddenField", "ParameterHidesMemberVariable"}) | ||
public static class TestCaseBuilder { | ||
private TestResult status = TestResult.PASSED; | ||
private String testName = StringUtils.EMPTY; | ||
private String className = StringUtils.EMPTY; | ||
private String type = StringUtils.EMPTY; | ||
private String message = StringUtils.EMPTY; | ||
private String description = StringUtils.EMPTY; | ||
|
||
@CanIgnoreReturnValue | ||
public TestCaseBuilder withStatus(final TestResult status) { | ||
this.status = status; | ||
|
||
return this; | ||
Check warning on line 123 in src/main/java/edu/hm/hafner/coverage/TestCase.java ci.jenkins.io / Mutation CoverageMutation survived
Raw output
|
||
} | ||
|
||
@CanIgnoreReturnValue | ||
public TestCaseBuilder withTestName(final String testName) { | ||
this.testName = testName; | ||
|
||
return this; | ||
Check warning on line 130 in src/main/java/edu/hm/hafner/coverage/TestCase.java ci.jenkins.io / Mutation CoverageMutation survived
Raw output
|
||
} | ||
|
||
@CanIgnoreReturnValue | ||
public TestCaseBuilder withClassName(final String className) { | ||
this.className = className; | ||
|
||
return this; | ||
Check warning on line 137 in src/main/java/edu/hm/hafner/coverage/TestCase.java ci.jenkins.io / Mutation CoverageMutation survived
Raw output
|
||
} | ||
|
||
@CanIgnoreReturnValue | ||
public TestCaseBuilder withType(final String type) { | ||
this.type = type; | ||
|
||
return this; | ||
Check warning on line 144 in src/main/java/edu/hm/hafner/coverage/TestCase.java ci.jenkins.io / Mutation CoverageMutation survived
Raw output
|
||
} | ||
|
||
@CanIgnoreReturnValue | ||
public TestCaseBuilder withMessage(final String message) { | ||
this.message = message; | ||
|
||
return this; | ||
Check warning on line 151 in src/main/java/edu/hm/hafner/coverage/TestCase.java ci.jenkins.io / Mutation CoverageMutation survived
Raw output
|
||
} | ||
|
||
@CanIgnoreReturnValue | ||
public TestCaseBuilder withDescription(final String description) { | ||
this.description = description; | ||
|
||
return this; | ||
Check warning on line 158 in src/main/java/edu/hm/hafner/coverage/TestCase.java ci.jenkins.io / Mutation CoverageMutation survived
Raw output
|
||
} | ||
|
||
@CanIgnoreReturnValue | ||
public TestCaseBuilder withFailure() { | ||
status = TestResult.FAILED; | ||
|
||
return this; | ||
Check warning on line 165 in src/main/java/edu/hm/hafner/coverage/TestCase.java ci.jenkins.io / Mutation CoverageMutation survived
Raw output
|
||
} | ||
|
||
public TestCase build() { | ||
return new TestCase(testName, className, status, type, message, description); | ||
} | ||
} | ||
|
||
/** | ||
* The result of a test case. | ||
*/ | ||
public enum TestResult { | ||
PASSED, | ||
FAILED, | ||
SKIPPED, | ||
ABORTED | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
package edu.hm.hafner.coverage; | ||
|
||
/** | ||
* Represents the total number of tests. | ||
* | ||
* @author Ullrich Hafner | ||
*/ | ||
public final class TestCount extends IntegerValue { | ||
private static final long serialVersionUID = -3098842770938054269L; | ||
|
||
/** | ||
* Creates a new {@link TestCount} instance with the number of tests. | ||
* | ||
* @param tests | ||
* the number of tests | ||
*/ | ||
public TestCount(final int tests) { | ||
super(Metric.TESTS, tests); | ||
} | ||
|
||
@Override | ||
protected IntegerValue create(final int value) { | ||
return new TestCount(value); | ||
} | ||
} |