diff --git a/src/main/java/gov/hhs/aspr/ms/util/meta/unittestcoverage/MetaInfoGenerator.java b/src/main/java/gov/hhs/aspr/ms/util/meta/unittestcoverage/MetaInfoGenerator.java index 0ee2292..05a8ce6 100644 --- a/src/main/java/gov/hhs/aspr/ms/util/meta/unittestcoverage/MetaInfoGenerator.java +++ b/src/main/java/gov/hhs/aspr/ms/util/meta/unittestcoverage/MetaInfoGenerator.java @@ -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) { @@ -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( @@ -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); diff --git a/src/main/java/gov/hhs/aspr/ms/util/meta/unittestcoverage/warnings/WarningType.java b/src/main/java/gov/hhs/aspr/ms/util/meta/unittestcoverage/warnings/WarningType.java index 162d020..7fa9ba4 100644 --- a/src/main/java/gov/hhs/aspr/ms/util/meta/unittestcoverage/warnings/WarningType.java +++ b/src/main/java/gov/hhs/aspr/ms/util/meta/unittestcoverage/warnings/WarningType.java @@ -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"),