Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed metainfo generator for unit test for coverage. #26

Merged
merged 1 commit into from
May 31, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,10 @@ private void probeTestClass(Class<?> c) {
final UnitTestForCoverage unitTestForCoverage = testMethod.getAnnotation(UnitTestForCoverage.class);

int caseIndex = 0;
if (test != null && unitTestForCoverage == null) {
if (test != null ) {
caseIndex += 16;
}
if (unitTestForCoverage == null) {
caseIndex += 8;
}
if (unitTestConstructor != null) {
Expand All @@ -242,8 +245,34 @@ private void probeTestClass(Class<?> c) {
}

switch (caseIndex) {
case 0:
// ignore the method
case 16:
warningContainerBuilder.addMethodWarning(
new MethodWarning(testMethod, WarningType.TEST_ANNOTATION_WITHOUT_UNIT_ANNOTATION));
break;
case 3://fall through
case 5://fall through
case 6://fall through
case 7://fall through
case 9://fall through
case 10://fall through
case 11://fall through
case 12://fall through
case 13://fall through
case 14://fall through
case 15://fall through
case 19://fall through
case 21://fall through
case 22://fall through
case 23://fall through
case 25://fall through
case 26://fall through
case 27://fall through
case 28://fall through
case 29://fall through
case 30://fall through
case 31:
warningContainerBuilder.addMethodWarning(
new MethodWarning(testMethod, WarningType.MULTIPLE_UNIT_ANNOTATIONS_PRESENT));
break;
case 1:
warningContainerBuilder.addMethodWarning(
Expand All @@ -253,55 +282,30 @@ private void probeTestClass(Class<?> c) {
warningContainerBuilder.addMethodWarning(
new MethodWarning(testMethod, WarningType.UNIT_METHOD_ANNOTATION_WITHOUT_TEST_ANNOTATION));
break;
case 3:
warningContainerBuilder
.addMethodWarning(new MethodWarning(testMethod, WarningType.MULTIPLE_UNIT_ANNOTATIONS_PRESENT));
break;

case 4:
warningContainerBuilder.addMethodWarning(
new MethodWarning(testMethod, WarningType.UNIT_CONSTRUCTOR_ANNOTATION_WITHOUT_TEST_ANNOTATION));
break;
case 5:
warningContainerBuilder
.addMethodWarning(new MethodWarning(testMethod, WarningType.MULTIPLE_UNIT_ANNOTATIONS_PRESENT));
break;
case 6:
warningContainerBuilder
.addMethodWarning(new MethodWarning(testMethod, WarningType.MULTIPLE_UNIT_ANNOTATIONS_PRESENT));
break;
case 7:
warningContainerBuilder
.addMethodWarning(new MethodWarning(testMethod, WarningType.MULTIPLE_UNIT_ANNOTATIONS_PRESENT));
break;

case 8:
warningContainerBuilder.addMethodWarning(
new MethodWarning(testMethod, WarningType.TEST_ANNOTATION_WITHOUT_UNIT_ANNOTATION));
new MethodWarning(testMethod, WarningType.UNIT_COVERAGE_ANNOTATION_WITHOUT_TEST_ANNOTATION));
break;

case 0://fall through
case 24:
//ignore
break;
case 9:
case 17:
probeFieldTest(testMethod, unitTestField);
break;
case 10:
case 18:
probeMethodTest(testMethod, unitTestMethod);
break;
case 11:
warningContainerBuilder
.addMethodWarning(new MethodWarning(testMethod, WarningType.MULTIPLE_UNIT_ANNOTATIONS_PRESENT));
break;
case 12:
case 20:
probeConstructorTest(testMethod, unitTestConstructor);
break;
case 13:
warningContainerBuilder
.addMethodWarning(new MethodWarning(testMethod, WarningType.MULTIPLE_UNIT_ANNOTATIONS_PRESENT));
break;
case 14:
warningContainerBuilder
.addMethodWarning(new MethodWarning(testMethod, WarningType.MULTIPLE_UNIT_ANNOTATIONS_PRESENT));
break;
case 15:
warningContainerBuilder
.addMethodWarning(new MethodWarning(testMethod, WarningType.MULTIPLE_UNIT_ANNOTATIONS_PRESENT));
break;

default:
throw new RuntimeException("unhandled case index " + caseIndex);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,10 @@ public enum WarningType {

SOURCE_CONSTRUCTOR_REQUIRES_TEST("Source constructor requires a test method but does not have one"),

UNIT_COVERAGE_ANNOTATION_WITHOUT_TEST_ANNOTATION(
"Test method is marked with @UnitTestForCoverage but does not have a corresponding @Test annotation"),


UNIT_CONSTRUCTOR_ANNOTATION_WITHOUT_TEST_ANNOTATION(
"Test method is marked with @UnitTestConstructor but does not have a corresponding @Test annotation"),

Expand Down