aboutsummaryrefslogtreecommitdiff
path: root/org.jacoco.core.test.validation.java7/src/org/jacoco/core/test/validation/java7/TryWithResourcesTest.java
diff options
context:
space:
mode:
authorMarc R. Hoffmann <hoffmann@mountainminds.com>2018-08-09 19:46:04 +0200
committerEvgeny Mandrikov <Godin@users.noreply.github.com>2018-08-09 19:46:04 +0200
commit1001adda9a37f262c6162c1fec99487a5a79e7fa (patch)
treeba8e6436a44ba6d6525df8eda33f60dc14898954 /org.jacoco.core.test.validation.java7/src/org/jacoco/core/test/validation/java7/TryWithResourcesTest.java
parent592533c898da5c11d99c9fa09177d92ad50a0455 (diff)
downloadjacoco-1001adda9a37f262c6162c1fec99487a5a79e7fa.tar.gz
Simplify validation test setup (#718)
Diffstat (limited to 'org.jacoco.core.test.validation.java7/src/org/jacoco/core/test/validation/java7/TryWithResourcesTest.java')
-rw-r--r--org.jacoco.core.test.validation.java7/src/org/jacoco/core/test/validation/java7/TryWithResourcesTest.java181
1 files changed, 24 insertions, 157 deletions
diff --git a/org.jacoco.core.test.validation.java7/src/org/jacoco/core/test/validation/java7/TryWithResourcesTest.java b/org.jacoco.core.test.validation.java7/src/org/jacoco/core/test/validation/java7/TryWithResourcesTest.java
index 9eb02571..0078258a 100644
--- a/org.jacoco.core.test.validation.java7/src/org/jacoco/core/test/validation/java7/TryWithResourcesTest.java
+++ b/org.jacoco.core.test.validation.java7/src/org/jacoco/core/test/validation/java7/TryWithResourcesTest.java
@@ -11,10 +11,9 @@
*******************************************************************************/
package org.jacoco.core.test.validation.java7;
-import org.jacoco.core.analysis.ICounter;
+import org.jacoco.core.test.validation.Source.Line;
import org.jacoco.core.test.validation.ValidationTestBase;
import org.jacoco.core.test.validation.java7.targets.TryWithResourcesTarget;
-import org.junit.Test;
/**
* Test of filtering of a bytecode that is generated for a try-with-resources
@@ -26,192 +25,60 @@ public class TryWithResourcesTest extends ValidationTestBase {
super(TryWithResourcesTarget.class);
}
- /**
- * {@link TryWithResourcesTarget#test()}
- */
- @Test
- public void test() {
- assertLine("test.before", ICounter.FULLY_COVERED);
- // without filter next line covered partly:
+ public void assertTry(final Line line) {
+ // without filter this line is covered partly:
if (!isJDKCompiler || JAVA_VERSION.isBefore("11")) {
- assertLine("test.try", ICounter.FULLY_COVERED);
+ assertFullyCovered(line);
} else {
- assertLine("test.try", ICounter.EMPTY);
+ assertEmpty(line);
}
- assertLine("test.open1", ICounter.FULLY_COVERED);
- assertLine("test.open2", ICounter.FULLY_COVERED);
- assertLine("test.open3", ICounter.FULLY_COVERED);
- assertLine("test.body", ICounter.FULLY_COVERED);
- // without filter next line has branches:
- assertLine("test.close", ICounter.EMPTY);
- assertLine("test.catch", ICounter.NOT_COVERED);
- assertLine("test.finally", ICounter.FULLY_COVERED);
- }
-
- /**
- * {@link TryWithResourcesTarget#test2()}
- */
- @Test
- public void test2() {
- assertLine("test2.before", ICounter.FULLY_COVERED);
- // without filter next line covered partly:
- if (!isJDKCompiler || JAVA_VERSION.isBefore("11")) {
- assertLine("test2.try", ICounter.FULLY_COVERED);
- } else {
- assertLine("test2.try", ICounter.EMPTY);
- }
- assertLine("test2.open1", ICounter.FULLY_COVERED);
- assertLine("test2.open2", ICounter.FULLY_COVERED);
- assertLine("test2.open3", ICounter.FULLY_COVERED);
- assertLine("test2.body", ICounter.FULLY_COVERED);
- // without filter next line has branches:
- assertLine("test2.close", ICounter.EMPTY);
- assertLine("test2.catch", ICounter.NOT_COVERED);
- assertLine("test2.finally", ICounter.FULLY_COVERED);
- assertLine("test2.after", ICounter.FULLY_COVERED);
}
- /**
- * {@link TryWithResourcesTarget#returnInBody()}
- */
- @Test
- public void returnInBody() {
- // without filter next line covered partly:
- if (!isJDKCompiler || JAVA_VERSION.isBefore("11")) {
- assertLine("returnInBody.try", ICounter.FULLY_COVERED);
- } else {
- assertLine("returnInBody.try", ICounter.EMPTY);
- }
- assertLine("returnInBody.open", ICounter.FULLY_COVERED);
-
+ public void assertReturnInBodyClose(final Line line) {
// without filter next line has branches:
if (isJDKCompiler) {
// https://bugs.openjdk.java.net/browse/JDK-8134759
// javac 7 and 8 up to 8u92 are affected
if (JAVA_VERSION.isBefore("1.8.0_92")) {
- assertLine("returnInBody.close", ICounter.FULLY_COVERED);
+ assertFullyCovered(line);
} else {
- assertLine("returnInBody.close", ICounter.EMPTY);
+ assertEmpty(line);
}
} else {
- assertLine("returnInBody.close", ICounter.EMPTY);
+ assertEmpty(line);
}
-
- assertLine("returnInBody.return", ICounter.FULLY_COVERED);
}
- /**
- * {@link TryWithResourcesTarget#nested()}
- */
- @Test
- public void nested() {
- // without filter next line covered partly:
- if (!isJDKCompiler || JAVA_VERSION.isBefore("11")) {
- assertLine("nested.try1", ICounter.FULLY_COVERED);
- } else {
- assertLine("nested.try1", ICounter.EMPTY);
- }
- assertLine("nested.open1", ICounter.FULLY_COVERED);
- assertLine("nested.catch1", ICounter.NOT_COVERED);
-
- // without filter next line covered partly:
- if (!isJDKCompiler || JAVA_VERSION.isBefore("11")) {
- assertLine("nested.try2", ICounter.FULLY_COVERED);
- } else {
- assertLine("nested.try2", ICounter.EMPTY);
- }
- assertLine("nested.body", ICounter.FULLY_COVERED);
- assertLine("nested.catch2", ICounter.NOT_COVERED);
- assertLine("nested.finally2", ICounter.FULLY_COVERED);
-
- // next lines not covered on exceptional path:
- if (!isJDKCompiler || JAVA_VERSION.isBefore("11")) {
- assertLine("nested.try3", ICounter.FULLY_COVERED);
- } else {
- assertLine("nested.try3", ICounter.EMPTY);
- }
- assertLine("nested.open3", ICounter.FULLY_COVERED);
- assertLine("nested.body3", ICounter.FULLY_COVERED);
- assertLine("nested.catch3", ICounter.NOT_COVERED);
- assertLine("nested.finally3", ICounter.FULLY_COVERED);
-
- // without filter next lines have branches:
- assertLine("nested.close3", ICounter.EMPTY);
- assertLine("nested.close2", ICounter.EMPTY);
- assertLine("nested.close1", ICounter.EMPTY);
- }
-
- /**
- * {@link TryWithResourcesTarget#returnInCatch()}
- */
- @Test
- public void returnInCatch() {
- // without filter next line covered partly:
- if (!isJDKCompiler || JAVA_VERSION.isBefore("11")) {
- assertLine("returnInCatch.try1", ICounter.FULLY_COVERED);
- } else {
- assertLine("returnInCatch.try1", ICounter.EMPTY);
- }
- assertLine("returnInCatch.open", ICounter.FULLY_COVERED);
- assertLine("returnInCatch.finally1", ICounter.PARTLY_COVERED, 1, 1);
- // without filter next line has branches:
- assertLine("returnInCatch.close", ICounter.EMPTY);
-
- assertLine("returnInCatch.try2", ICounter.EMPTY);
- assertLine("returnInCatch.finally2", ICounter.PARTLY_COVERED, 1, 1);
- }
-
- /*
- * Corner cases
- */
-
- /**
- * {@link TryWithResourcesTarget#handwritten()}
- */
- @Test
- public void handwritten() {
+ public void assertHandwritten(final Line line) {
if (isJDKCompiler) {
- assertLine("handwritten", /* partly when ECJ: */ICounter.EMPTY);
+ assertEmpty(line);
+ } else {
+ assertFullyCovered(line, 1, 1);
}
}
- /**
- * {@link TryWithResourcesTarget#empty()}
- */
- @Test
- public void empty() {
- if (!isJDKCompiler || JAVA_VERSION.isBefore("11")) {
- assertLine("empty.try", ICounter.FULLY_COVERED);
- } else {
- assertLine("empty.try", ICounter.EMPTY);
- }
- assertLine("empty.open", ICounter.FULLY_COVERED);
+ public void assertEmptyClose(final Line line) {
if (!isJDKCompiler) {
- assertLine("empty.close", ICounter.PARTLY_COVERED, 7, 1);
+ assertPartlyCovered(line, 7, 1);
} else if (JAVA_VERSION.isBefore("8")) {
- assertLine("empty.close", ICounter.PARTLY_COVERED, 6, 2);
+ assertPartlyCovered(line, 6, 2);
} else if (JAVA_VERSION.isBefore("9")) {
- assertLine("empty.close", ICounter.PARTLY_COVERED, 2, 2);
+ assertPartlyCovered(line, 2, 2);
} else {
- assertLine("empty.close", ICounter.FULLY_COVERED);
+ assertFullyCovered(line);
}
}
- /**
- * {@link TryWithResourcesTarget#throwInBody()}
- */
- @Test
- public void throwInBody() {
+ public void assertThrowInBodyClose(final Line line) {
// not filtered
- assertLine("throwInBody.try", ICounter.NOT_COVERED);
- if (!isJDKCompiler){
- assertLine("throwInBody.close", ICounter.NOT_COVERED, 6, 0);
+ if (!isJDKCompiler) {
+ assertNotCovered(line, 6, 0);
} else if (JAVA_VERSION.isBefore("9")) {
- assertLine("throwInBody.close", ICounter.NOT_COVERED, 4, 0);
+ assertNotCovered(line, 4, 0);
} else if (JAVA_VERSION.isBefore("11")) {
- assertLine("throwInBody.close", ICounter.NOT_COVERED);
+ assertNotCovered(line);
} else {
- assertLine("throwInBody.close", ICounter.EMPTY);
+ assertEmpty(line);
}
}