This is an automated email from the ASF dual-hosted git repository.
ggregory pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/commons-bcel.git
The following commit(s) were added to refs/heads/master by this push:
new 215508b BCEL-343 JUnit Assertion improvement (#69)
215508b is described below
commit 215508b60f372891d2da0c7190451d8e82bb404b
Author: Allon Murienik <[email protected]>
AuthorDate: Wed Oct 7 17:16:12 2020 +0300
BCEL-343 JUnit Assertion improvement (#69)
* BCEL-343 Fix assertion typo
Fix a typo in FieldAnnotationsTestCase#checkValue: "Didnt" to
"Didn't".
* BCEL-343 Remove unused test methods
* BCEL-343 Remove redundant casts in tests
* BCEL-343 Simplify assertTrue to assertFalse
Simplify assertTrue calls with negative conditions to assertFalse
calls which are easier to understand.
* BCEL-343 Simplify assertTrue with equality to assertEquals
Clean up assertions code by using the built-in assertions in
org.junit.jupiter.api.Assertions instead of reinventing the wheel.
assertTrue(x.equals(y)) and assertTrue(primitiveX == primitiveY)
are simplified to assertEquals(x, y).
The main gain by this patch is cleaning up the code and making it
easier to maintain.
A side bonus is that many assertions simplified to assertEquals calls
had messages that were manually constructed to show the difference
between the two values being compared, and these messages were
constructed regardless of the assertion success or failure. By using
assertEquals, these string concatenations are avoided as long as the
assert succeeds.
* BCEL-343 Simplify explicit ifs to assertEquals
Clean up assertions code by using the built-in assertions in
org.junit.jupiter.api.Assertions instead of reinventing the wheel.
This patch simplifies the idiom of using an if to explicitly check for
equality:
```
if (!a.equals(b)) {
fail("a should equal b");
}
```
with the build it assertEquals(a, b, "a should equal b").
* BCEL-343 Simplify catching exceptions in tests
Replace the idiom of catching an exception and then explicitly calling
org.junit.jupiter.api.Assertions with just allowing the error to be
thrown from the test method and leaving the it up to the runner to
handle the failure.
* BCEL-343 Replace non-constant assertion message with Supplier
In the cases that assertions have non-constant failure messages, these
messages are replaced with Suppliers that produce them in order to
avoid producing the calculated string unconditionally.
---
.../java/org/apache/bcel/AbstractTestCase.java | 21 +----
.../apache/bcel/AnnotationAccessFlagTestCase.java | 3 +-
.../bcel/AnnotationDefaultAttributeTestCase.java | 8 +-
.../org/apache/bcel/ElementValueGenTestCase.java | 47 +++--------
.../bcel/EnclosingMethodAttributeTestCase.java | 36 +++------
.../org/apache/bcel/EnumAccessFlagTestCase.java | 3 +-
src/test/java/org/apache/bcel/PerformanceTest.java | 3 +-
.../bcel/classfile/JDKClassDumpTestCase.java | 6 +-
.../apache/bcel/generic/AnnotationGenTestCase.java | 65 +++++----------
.../bcel/generic/FieldAnnotationsTestCase.java | 42 ++--------
.../GeneratingAnnotatedClassesTestCase.java | 93 ++++++++--------------
.../bcel/generic/JdkGenericDumpTestCase.java | 7 +-
.../org/apache/bcel/generic/MethodGenTestCase.java | 2 +-
.../bcel/verifier/AbstractVerifierTestCase.java | 18 ++---
.../bcel/verifier/VerifierArrayAccessTestCase.java | 4 +-
.../bcel/verifier/VerifierInvokeTestCase.java | 8 +-
.../bcel/verifier/VerifierReturnTestCase.java | 4 +-
17 files changed, 115 insertions(+), 255 deletions(-)
diff --git a/src/test/java/org/apache/bcel/AbstractTestCase.java
b/src/test/java/org/apache/bcel/AbstractTestCase.java
index 6f95354..842f889 100644
--- a/src/test/java/org/apache/bcel/AbstractTestCase.java
+++ b/src/test/java/org/apache/bcel/AbstractTestCase.java
@@ -35,7 +35,7 @@ import org.apache.bcel.generic.SimpleElementValueGen;
import org.apache.bcel.util.ClassPath;
import org.apache.bcel.util.SyntheticRepository;
-import static org.junit.jupiter.api.Assertions.assertTrue;
+import static org.junit.jupiter.api.Assertions.assertEquals;
public abstract class AbstractTestCase
{
@@ -141,27 +141,10 @@ public abstract class AbstractTestCase
chosenAttrsList.add(element);
}
}
- assertTrue(chosenAttrsList.size() == 1,
- "Should be one match: " + chosenAttrsList.size());
+ assertEquals(1, chosenAttrsList.size(), "Wrong number of matches");
return chosenAttrsList.get(0);
}
- protected String dumpAttributes(final Attribute[] as)
- {
- final StringBuilder result = new StringBuilder();
- result.append("AttributeArray:[");
- for (int i = 0; i < as.length; i++)
- {
- final Attribute attr = as[i];
- result.append(attr.toString());
- if (i + 1 < as.length) {
- result.append(",");
- }
- }
- result.append("]");
- return result.toString();
- }
-
protected String dumpAnnotationEntries(final AnnotationEntry[] as)
{
final StringBuilder result = new StringBuilder();
diff --git a/src/test/java/org/apache/bcel/AnnotationAccessFlagTestCase.java
b/src/test/java/org/apache/bcel/AnnotationAccessFlagTestCase.java
index 84134ac..232695f 100644
--- a/src/test/java/org/apache/bcel/AnnotationAccessFlagTestCase.java
+++ b/src/test/java/org/apache/bcel/AnnotationAccessFlagTestCase.java
@@ -21,6 +21,7 @@ package org.apache.bcel;
import org.apache.bcel.classfile.JavaClass;
import org.junit.jupiter.api.Test;
+import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertTrue;
public class AnnotationAccessFlagTestCase extends AbstractTestCase
@@ -37,7 +38,7 @@ public class AnnotationAccessFlagTestCase extends
AbstractTestCase
assertTrue(clazz.isAnnotation(),
"Expected SimpleAnnotation class to say it was an annotation -
but it didn't !");
clazz = getTestClass(PACKAGE_BASE_NAME+".data.SimpleClass");
- assertTrue(!clazz.isAnnotation(),
+ assertFalse(clazz.isAnnotation(),
"Expected SimpleClass class to say it was not an annotation -
but it didn't !");
}
}
diff --git
a/src/test/java/org/apache/bcel/AnnotationDefaultAttributeTestCase.java
b/src/test/java/org/apache/bcel/AnnotationDefaultAttributeTestCase.java
index 23e1394..0593a8b 100644
--- a/src/test/java/org/apache/bcel/AnnotationDefaultAttributeTestCase.java
+++ b/src/test/java/org/apache/bcel/AnnotationDefaultAttributeTestCase.java
@@ -25,7 +25,7 @@ import org.apache.bcel.classfile.Method;
import org.apache.bcel.classfile.SimpleElementValue;
import org.junit.jupiter.api.Test;
-import static org.junit.jupiter.api.Assertions.assertTrue;
+import static org.junit.jupiter.api.Assertions.assertEquals;
public class AnnotationDefaultAttributeTestCase extends AbstractTestCase
{
@@ -42,9 +42,7 @@ public class AnnotationDefaultAttributeTestCase extends
AbstractTestCase
final AnnotationDefault a = (AnnotationDefault) findAttribute(
"AnnotationDefault", m.getAttributes());
final SimpleElementValue val = (SimpleElementValue)
a.getDefaultValue();
- assertTrue(val.getElementValueType() == ElementValue.STRING,
- "Should be STRING but is " + val.getElementValueType());
- assertTrue(val.getValueString().equals("bananas"),
- "Should have default of bananas but default is " +
val.getValueString());
+ assertEquals(ElementValue.STRING, val.getElementValueType(), "Wrong
element value type");
+ assertEquals("bananas", val.getValueString(), "Wrong default");
}
}
diff --git a/src/test/java/org/apache/bcel/ElementValueGenTestCase.java
b/src/test/java/org/apache/bcel/ElementValueGenTestCase.java
index 098f2ca..f359c1d 100644
--- a/src/test/java/org/apache/bcel/ElementValueGenTestCase.java
+++ b/src/test/java/org/apache/bcel/ElementValueGenTestCase.java
@@ -33,8 +33,8 @@ import org.apache.bcel.generic.ObjectType;
import org.apache.bcel.generic.SimpleElementValueGen;
import org.junit.jupiter.api.Test;
+import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertTrue;
-import static org.junit.jupiter.api.Assertions.fail;
public class ElementValueGenTestCase extends AbstractTestCase
{
@@ -56,9 +56,7 @@ public class ElementValueGenTestCase extends AbstractTestCase
ElementValueGen.PRIMITIVE_INT, cp, 555);
// Creation of an element like that should leave a new entry in the
// cpool
- assertTrue(evg.getIndex() == cp.lookupInteger(555),
- "Should have the same index in the constantpool but "
- + evg.getIndex() + "!=" + cp.lookupInteger(555));
+ assertEquals(cp.lookupInteger(555), evg.getIndex(), "Should have the
same index in the constantpool");
checkSerialize(evg, cp);
}
@@ -71,9 +69,7 @@ public class ElementValueGenTestCase extends AbstractTestCase
ElementValueGen.PRIMITIVE_FLOAT, cp, 111.222f);
// Creation of an element like that should leave a new entry in the
// cpool
- assertTrue(evg.getIndex() == cp.lookupFloat(111.222f),
- "Should have the same index in the constantpool but "
- + evg.getIndex() + "!=" + cp.lookupFloat(111.222f));
+ assertEquals(cp.lookupFloat(111.222f), evg.getIndex(), "Should have
the same index in the constantpool");
checkSerialize(evg, cp);
}
@@ -87,9 +83,7 @@ public class ElementValueGenTestCase extends AbstractTestCase
// Creation of an element like that should leave a new entry in the
// cpool
final int idx = cp.lookupDouble(333.44);
- assertTrue(evg.getIndex() == idx,
- "Should have the same index in the constantpool but "
- + evg.getIndex() + "!=" + idx);
+ assertEquals(idx, evg.getIndex(), "Should have the same index in the
constantpool");
checkSerialize(evg, cp);
}
@@ -103,9 +97,7 @@ public class ElementValueGenTestCase extends AbstractTestCase
// Creation of an element like that should leave a new entry in the
// cpool
final int idx = cp.lookupLong(3334455L);
- assertTrue(evg.getIndex() == idx,
- "Should have the same index in the constantpool but "
- + evg.getIndex() + "!=" + idx);
+ assertEquals(idx, evg.getIndex(), "Should have the same index in the
constantpool");
checkSerialize(evg, cp);
}
@@ -119,9 +111,7 @@ public class ElementValueGenTestCase extends
AbstractTestCase
// Creation of an element like that should leave a new entry in the
// cpool
final int idx = cp.lookupInteger('t');
- assertTrue(evg.getIndex() == idx,
- "Should have the same index in the constantpool but "
- + evg.getIndex() + "!=" + idx);
+ assertEquals(idx, evg.getIndex(), "Should have the same index in the
constantpool");
checkSerialize(evg, cp);
}
@@ -135,9 +125,7 @@ public class ElementValueGenTestCase extends
AbstractTestCase
// Creation of an element like that should leave a new entry in the
// cpool
final int idx = cp.lookupInteger((byte) 'z');
- assertTrue(evg.getIndex() == idx,
- "Should have the same index in the constantpool but "
- + evg.getIndex() + "!=" + idx);
+ assertEquals(idx, evg.getIndex(), "Should have the same index in the
constantpool");
checkSerialize(evg, cp);
}
@@ -151,9 +139,7 @@ public class ElementValueGenTestCase extends
AbstractTestCase
// Creation of an element like that should leave a new entry in the
// cpool
final int idx = cp.lookupInteger(1); // 1 == true
- assertTrue(evg.getIndex() == idx,
- "Should have the same index in the constantpool but "
- + evg.getIndex() + "!=" + idx);
+ assertEquals(idx, evg.getIndex(), "Should have the same index in the
constantpool");
checkSerialize(evg, cp);
}
@@ -167,9 +153,7 @@ public class ElementValueGenTestCase extends
AbstractTestCase
// Creation of an element like that should leave a new entry in the
// cpool
final int idx = cp.lookupInteger(42);
- assertTrue(evg.getIndex() == idx,
- "Should have the same index in the constantpool but "
- + evg.getIndex() + "!=" + idx);
+ assertEquals(idx, evg.getIndex(), "Should have the same index in the
constantpool");
checkSerialize(evg, cp);
}
@@ -185,9 +169,7 @@ public class ElementValueGenTestCase extends
AbstractTestCase
ElementValueGen.STRING, cp, "hello");
// Creation of an element like that should leave a new entry in the
// cpool
- assertTrue(evg.getIndex() == cp.lookupUtf8("hello"),
- "Should have the same index in the constantpool but "
- + evg.getIndex() + "!=" + cp.lookupUtf8("hello"));
+ assertEquals(cp.lookupUtf8("hello"), evg.getIndex(), "Should have the
same index in the constantpool");
checkSerialize(evg, cp);
}
@@ -203,9 +185,8 @@ public class ElementValueGenTestCase extends
AbstractTestCase
final EnumElementValueGen evg = new EnumElementValueGen(enumType,
"Red", cp);
// Creation of an element like that should leave a new entry in the
// cpool
- assertTrue(evg.getValueIndex() == cp.lookupUtf8("Red"),
- "The new ElementValue value index should match the contents of
the constantpool but "
- + evg.getValueIndex() + "!=" + cp.lookupUtf8("Red"));
+ assertEquals(cp.lookupUtf8("Red"), evg.getValueIndex(),
+ "The new ElementValue value index should match the contents of
the constantpool");
// BCELBUG: Should the class signature or class name be in the constant
// pool? (see note in ConstantPool)
// assertTrue("The new ElementValue type index should match the
contents
@@ -241,8 +222,6 @@ public class ElementValueGenTestCase extends
AbstractTestCase
evgAfter = ElementValueGen.readElementValue(dis, cpg);
}
final String afterValue = evgAfter.stringifyValue();
- if (!beforeValue.equals(afterValue)) {
- fail("Deserialization failed: before='" + beforeValue + "'
after='" + afterValue + "'");
- }
+ assertEquals(beforeValue, afterValue, "Deserialization failed");
}
}
diff --git
a/src/test/java/org/apache/bcel/EnclosingMethodAttributeTestCase.java
b/src/test/java/org/apache/bcel/EnclosingMethodAttributeTestCase.java
index 005298a..edc2ecf 100644
--- a/src/test/java/org/apache/bcel/EnclosingMethodAttributeTestCase.java
+++ b/src/test/java/org/apache/bcel/EnclosingMethodAttributeTestCase.java
@@ -28,8 +28,8 @@ import org.apache.bcel.classfile.JavaClass;
import org.apache.bcel.util.SyntheticRepository;
import org.junit.jupiter.api.Test;
+import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNotNull;
-import static org.junit.jupiter.api.Assertions.assertTrue;
public class EnclosingMethodAttributeTestCase extends AbstractTestCase
{
@@ -44,16 +44,12 @@ public class EnclosingMethodAttributeTestCase extends
AbstractTestCase
final JavaClass clazz =
getTestClass(PACKAGE_BASE_NAME+".data.AttributeTestClassEM01$1S");
final ConstantPool pool = clazz.getConstantPool();
final Attribute[] encMethodAttrs = findAttribute("EnclosingMethod",
clazz);
- assertTrue(encMethodAttrs.length == 1,
- "Expected 1 EnclosingMethod attribute but found " +
encMethodAttrs.length);
+ assertEquals(1, encMethodAttrs.length, "Wrong number of
EnclosingMethod attributes");
final EnclosingMethod em = (EnclosingMethod) encMethodAttrs[0];
final String enclosingClassName =
em.getEnclosingClass().getBytes(pool);
final String enclosingMethodName =
em.getEnclosingMethod().getName(pool);
-
assertTrue(enclosingClassName.equals(PACKAGE_BASE_SIG+"/data/AttributeTestClassEM01"),
- "Expected class name to be
'"+PACKAGE_BASE_SIG+"/data/AttributeTestClassEM01' but was "
- + enclosingClassName);
- assertTrue(enclosingMethodName.equals("main"),
- "Expected method name to be 'main' but was " +
enclosingMethodName);
+ assertEquals(PACKAGE_BASE_SIG + "/data/AttributeTestClassEM01",
enclosingClassName, "Wrong class name");
+ assertEquals(enclosingMethodName, "main", "Wrong method name");
}
/**
@@ -67,16 +63,12 @@ public class EnclosingMethodAttributeTestCase extends
AbstractTestCase
final JavaClass clazz =
getTestClass(PACKAGE_BASE_NAME+".data.AttributeTestClassEM02$1");
final ConstantPool pool = clazz.getConstantPool();
final Attribute[] encMethodAttrs = findAttribute("EnclosingMethod",
clazz);
- assertTrue(encMethodAttrs.length == 1,
- "Expected 1 EnclosingMethod attribute but found " +
encMethodAttrs.length);
+ assertEquals(1, encMethodAttrs.length, "Expected 1 EnclosingMethod
attribute but found " + encMethodAttrs.length);
final EnclosingMethod em = (EnclosingMethod) encMethodAttrs[0];
final String enclosingClassName =
em.getEnclosingClass().getBytes(pool);
- assertTrue(em.getEnclosingMethodIndex() == 0,
- "The class is not within a method, so method_index should be
null, but it is "
- + em.getEnclosingMethodIndex());
-
assertTrue(enclosingClassName.equals(PACKAGE_BASE_SIG+"/data/AttributeTestClassEM02"),
- "Expected class name to be
'"+PACKAGE_BASE_SIG+"/data/AttributeTestClassEM02' but was "
- + enclosingClassName);
+ assertEquals(em.getEnclosingMethodIndex(), 0,
+ "The class is not within a method, so method_index should be
null");
+ assertEquals(PACKAGE_BASE_SIG + "/data/AttributeTestClassEM02",
enclosingClassName, "Wrong class name");
}
/**
@@ -89,8 +81,7 @@ public class EnclosingMethodAttributeTestCase extends
AbstractTestCase
final JavaClass clazz =
getTestClass(PACKAGE_BASE_NAME+".data.AttributeTestClassEM02$1");
final ConstantPool pool = clazz.getConstantPool();
final Attribute[] encMethodAttrs = findAttribute("EnclosingMethod",
clazz);
- assertTrue(encMethodAttrs.length == 1,
- "Expected 1 EnclosingMethod attribute but found " +
encMethodAttrs.length);
+ assertEquals(1, encMethodAttrs.length, "Wrong number of
EnclosingMethod attributes");
// Write it out
final File tfile =
createTestdataFile("AttributeTestClassEM02$1.class");
clazz.dump(tfile);
@@ -100,12 +91,9 @@ public class EnclosingMethodAttributeTestCase extends
AbstractTestCase
assertNotNull(clazz2); // Use the variable to avoid a warning
final EnclosingMethod em = (EnclosingMethod) encMethodAttrs[0];
final String enclosingClassName =
em.getEnclosingClass().getBytes(pool);
- assertTrue(em.getEnclosingMethodIndex() == 0,
- "The class is not within a method, so method_index should be
null, but it is "
- + em.getEnclosingMethodIndex());
-
assertTrue(enclosingClassName.equals(PACKAGE_BASE_SIG+"/data/AttributeTestClassEM02"),
- "Expected class name to be
'"+PACKAGE_BASE_SIG+"/data/AttributeTestClassEM02' but was "
- + enclosingClassName);
+ assertEquals(em.getEnclosingMethodIndex(), 0,
+ "The class is not within a method, so method_index should be
null");
+ assertEquals(PACKAGE_BASE_SIG + "/data/AttributeTestClassEM02",
enclosingClassName, "Wrong class name");
tfile.deleteOnExit();
}
}
diff --git a/src/test/java/org/apache/bcel/EnumAccessFlagTestCase.java
b/src/test/java/org/apache/bcel/EnumAccessFlagTestCase.java
index e140c0d..f4f34d1 100644
--- a/src/test/java/org/apache/bcel/EnumAccessFlagTestCase.java
+++ b/src/test/java/org/apache/bcel/EnumAccessFlagTestCase.java
@@ -21,6 +21,7 @@ package org.apache.bcel;
import org.apache.bcel.classfile.JavaClass;
import org.junit.jupiter.api.Test;
+import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertTrue;
public class EnumAccessFlagTestCase extends AbstractTestCase
@@ -37,7 +38,7 @@ public class EnumAccessFlagTestCase extends AbstractTestCase
assertTrue(clazz.isEnum(),
"Expected SimpleEnum class to say it was an enum - but it
didn't !");
clazz = getTestClass(PACKAGE_BASE_NAME+".data.SimpleClass");
- assertTrue(!clazz.isEnum(),
+ assertFalse(clazz.isEnum(),
"Expected SimpleClass class to say it was not an enum - but it
didn't !");
}
}
diff --git a/src/test/java/org/apache/bcel/PerformanceTest.java
b/src/test/java/org/apache/bcel/PerformanceTest.java
index 64d7650..91e5087 100644
--- a/src/test/java/org/apache/bcel/PerformanceTest.java
+++ b/src/test/java/org/apache/bcel/PerformanceTest.java
@@ -20,7 +20,6 @@ package org.apache.bcel;
import java.io.ByteArrayInputStream;
import java.io.File;
-import java.io.FileFilter;
import java.io.IOException;
import java.io.InputStream;
import java.util.Enumeration;
@@ -134,7 +133,7 @@ public final class PerformanceTest {
@Test
public void testPerformance() {
final File javaLib = new File(System.getProperty("java.home"), "lib");
- javaLib.listFiles((FileFilter) file -> {
+ javaLib.listFiles(file -> {
if(file.getName().endsWith(".jar")) {
try {
test(file);
diff --git a/src/test/java/org/apache/bcel/classfile/JDKClassDumpTestCase.java
b/src/test/java/org/apache/bcel/classfile/JDKClassDumpTestCase.java
index 64e1b93..a2eb7ec 100644
--- a/src/test/java/org/apache/bcel/classfile/JDKClassDumpTestCase.java
+++ b/src/test/java/org/apache/bcel/classfile/JDKClassDumpTestCase.java
@@ -24,7 +24,6 @@ import java.io.ByteArrayOutputStream;
import java.io.DataInputStream;
import java.io.DataOutputStream;
import java.io.File;
-import java.io.FileFilter;
import java.io.InputStream;
import java.util.Enumeration;
import java.util.jar.JarEntry;
@@ -40,7 +39,7 @@ public class JDKClassDumpTestCase {
@Test
public void testPerformance() throws Exception {
final File javaLib = new File(System.getProperty("java.home") +
"/lib");
- javaLib.listFiles((FileFilter) file -> {
+ javaLib.listFiles(file -> {
if (file.getName().endsWith(".jar")) {
try {
testJar(file);
@@ -81,7 +80,8 @@ public class JDKClassDumpTestCase {
int i = 0;
for (final int out : baos.toByteArray()) {
final int in = src.read();
- assertEquals(in, out & 0xFF, name + ": Mismatch at " + i);
+ int j = i;
+ assertEquals(in, out & 0xFF, () -> (name + ": Mismatch at " +
j));
i++;
}
}
diff --git a/src/test/java/org/apache/bcel/generic/AnnotationGenTestCase.java
b/src/test/java/org/apache/bcel/generic/AnnotationGenTestCase.java
index 074fd3d..c66b171 100644
--- a/src/test/java/org/apache/bcel/generic/AnnotationGenTestCase.java
+++ b/src/test/java/org/apache/bcel/generic/AnnotationGenTestCase.java
@@ -33,9 +33,9 @@ import org.apache.bcel.classfile.RuntimeInvisibleAnnotations;
import org.apache.bcel.classfile.RuntimeVisibleAnnotations;
import org.junit.jupiter.api.Test;
+import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertTrue;
-import static org.junit.jupiter.api.Assertions.fail;
public class AnnotationGenTestCase extends AbstractTestCase
{
@@ -49,7 +49,7 @@ public class AnnotationGenTestCase extends AbstractTestCase
* Programmatically construct an mutable annotation (AnnotationGen) object.
*/
@Test
- public void testConstructMutableAnnotation()
+ public void testConstructMutableAnnotation() throws IOException
{
// Create the containing class
final ClassGen cg = createClassGen("HelloWorld");
@@ -123,49 +123,28 @@ public class AnnotationGenTestCase extends
AbstractTestCase
assertTrue(foundRIV, "Should have seen a RuntimeInvisibleAnnotation");
}
- private void checkSerialize(final AnnotationEntryGen a, final
ConstantPoolGen cpg)
+ private void checkSerialize(final AnnotationEntryGen a, final
ConstantPoolGen cpg) throws IOException
{
- try
- {
- final String beforeName = a.getTypeName();
- final ByteArrayOutputStream baos = new ByteArrayOutputStream();
- try (DataOutputStream dos = new DataOutputStream(baos)) {
- a.dump(dos);
- dos.flush();
- }
- final byte[] bs = baos.toByteArray();
- final ByteArrayInputStream bais = new ByteArrayInputStream(bs);
- AnnotationEntryGen annAfter;
- try (DataInputStream dis = new DataInputStream(bais)) {
- annAfter = AnnotationEntryGen.read(dis, cpg,
a.isRuntimeVisible());
- }
- final String afterName = annAfter.getTypeName();
- if (!beforeName.equals(afterName))
- {
- fail("Deserialization failed: before type='" + beforeName
- + "' after type='" + afterName + "'");
- }
- if (a.getValues().size() != annAfter.getValues().size())
- {
- fail("Different numbers of element name value pairs?? "
- + a.getValues().size() + "!="
- + annAfter.getValues().size());
- }
- for (int i = 0; i < a.getValues().size(); i++)
- {
- final ElementValuePairGen beforeElement = a.getValues().get(i);
- final ElementValuePairGen afterElement =
annAfter.getValues().get(i);
- if (!beforeElement.getNameString().equals(
- afterElement.getNameString()))
- {
- fail("Different names?? " + beforeElement.getNameString()
- + "!=" + afterElement.getNameString());
- }
- }
+ final String beforeName = a.getTypeName();
+ final ByteArrayOutputStream baos = new ByteArrayOutputStream();
+ try (DataOutputStream dos = new DataOutputStream(baos)) {
+ a.dump(dos);
+ dos.flush();
+ }
+ final byte[] bs = baos.toByteArray();
+ final ByteArrayInputStream bais = new ByteArrayInputStream(bs);
+ AnnotationEntryGen annAfter;
+ try (DataInputStream dis = new DataInputStream(bais)) {
+ annAfter = AnnotationEntryGen.read(dis, cpg, a.isRuntimeVisible());
}
- catch (final IOException ioe)
- {
- fail("Unexpected exception whilst checking serialization: " + ioe);
+ final String afterName = annAfter.getTypeName();
+ assertEquals(beforeName, afterName, "Deserialization failed");
+ assertEquals(a.getValues().size(), annAfter.getValues().size(),
+ "Different numbers of element name value pairs??");
+ for (int i = 0; i < a.getValues().size(); i++) {
+ final ElementValuePairGen beforeElement = a.getValues().get(i);
+ final ElementValuePairGen afterElement =
annAfter.getValues().get(i);
+ assertEquals(beforeElement.getNameString(),
afterElement.getNameString(), "Different names??");
}
}
}
diff --git
a/src/test/java/org/apache/bcel/generic/FieldAnnotationsTestCase.java
b/src/test/java/org/apache/bcel/generic/FieldAnnotationsTestCase.java
index 8cd71df..9fd468b 100644
--- a/src/test/java/org/apache/bcel/generic/FieldAnnotationsTestCase.java
+++ b/src/test/java/org/apache/bcel/generic/FieldAnnotationsTestCase.java
@@ -29,8 +29,8 @@ import org.apache.bcel.classfile.JavaClass;
import org.apache.bcel.util.SyntheticRepository;
import org.junit.jupiter.api.Test;
+import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertTrue;
-import static org.junit.jupiter.api.Assertions.fail;
public class FieldAnnotationsTestCase extends AbstractTestCase
{
@@ -115,9 +115,7 @@ public class FieldAnnotationsTestCase extends
AbstractTestCase
System.err.println("With AnnotationEntrys: "
+ dumpAnnotationEntries(f.getAnnotationEntries()));
}
- assertTrue(f.getAnnotationEntries().length == 2,
- "Should be 2 AnnotationEntrys on this field, but there are "
- + f.getAnnotationEntries().length);
+ assertEquals(2, f.getAnnotationEntries().length, "Wrong number of
AnnotationEntries");
}
// helper methods
@@ -139,38 +137,10 @@ public class FieldAnnotationsTestCase extends
AbstractTestCase
private void checkAnnotationEntry(final AnnotationEntry a, final String
name, final String elementname,
final String elementvalue)
{
- assertTrue(a.getAnnotationType().equals(name),
- "Expected AnnotationEntry to have name " + name
- + " but it had name " + a.getAnnotationType());
- assertTrue(a.getElementValuePairs().length == 1,
- "Expected AnnotationEntry to have one element but it had "
- + a.getElementValuePairs().length);
+ assertEquals(name, a.getAnnotationType(), "Wrong AnnotationEntry
name");
+ assertEquals(1, a.getElementValuePairs().length, "Wrong number of
AnnotationEntry elements");
final ElementValuePair envp = a.getElementValuePairs()[0];
- assertTrue(elementname.equals(envp.getNameString()),
- "Expected element name " + elementname + " but was "
- + envp.getNameString());
- assertTrue(elementvalue.equals(envp.getValue().stringifyValue()),
- "Expected element value " + elementvalue + " but was "
- + envp.getValue().stringifyValue());
- }
-
- // helper methods
- public void checkValue(final AnnotationEntry a, final String name, final
String tostring)
- {
- for (int i = 0; i < a.getElementValuePairs().length; i++)
- {
- final ElementValuePair element = a.getElementValuePairs()[i];
- if (element.getNameString().equals(name))
- {
- if (!element.getValue().stringifyValue().equals(tostring))
- {
- fail("Expected element " + name + " to have value "
- + tostring + " but it had value "
- + element.getValue().stringifyValue());
- }
- return;
- }
- }
- fail("Didnt find named element " + name);
+ assertEquals(envp.getNameString(), elementname, "Wrong element name");
+ assertEquals(envp.getValue().stringifyValue(), elementvalue, "Wrong
element value");
}
}
diff --git
a/src/test/java/org/apache/bcel/generic/GeneratingAnnotatedClassesTestCase.java
b/src/test/java/org/apache/bcel/generic/GeneratingAnnotatedClassesTestCase.java
index 57f61f6..ac455e8 100644
---
a/src/test/java/org/apache/bcel/generic/GeneratingAnnotatedClassesTestCase.java
+++
b/src/test/java/org/apache/bcel/generic/GeneratingAnnotatedClassesTestCase.java
@@ -91,24 +91,16 @@ public class GeneratingAnnotatedClassesTestCase extends
AbstractTestCase
dumpClass(cg, "HelloWorld.class");
final JavaClass jc = getClassFrom(".", "HelloWorld");
final AnnotationEntry[] as = jc.getAnnotationEntries();
- assertTrue(as.length == 2,
- "Should be two AnnotationEntries but found " + as.length);
+ assertEquals(2, as.length, "Wrong number of AnnotationEntries");
// TODO L??;
- assertTrue(as[0].getAnnotationType().equals("LSimpleAnnotation;"),
- "Name of annotation 1 should be LSimpleAnnotation; but it is "
- + as[0].getAnnotationType());
- assertTrue(as[1].getAnnotationType().equals("LSimpleAnnotation;"),
- "Name of annotation 2 should be LSimpleAnnotation; but it is "
- + as[1].getAnnotationType());
+ assertEquals("LSimpleAnnotation;", as[0].getAnnotationType(), "Wrong
name of annotation 1");
+ assertEquals("LSimpleAnnotation;", as[1].getAnnotationType(), "Wrong
name of annotation 2");
final ElementValuePair[] vals = as[0].getElementValuePairs();
final ElementValuePair nvp = vals[0];
- assertTrue(nvp.getNameString().equals("id"),
- "Name of element in SimpleAnnotation should be 'id' but it is
" + nvp.getNameString());
+ assertEquals("id", nvp.getNameString(), "Wrong name of element in
SimpleAnnotation");
final ElementValue ev = nvp.getValue();
- assertTrue(ev.getElementValueType() == ElementValue.PRIMITIVE_INT,
- "Type of element value should be int but it is " +
ev.getElementValueType());
- assertTrue(ev.stringifyValue().equals("4"),
- "Value of element should be 4 but it is " +
ev.stringifyValue());
+ assertEquals(ElementValue.PRIMITIVE_INT, ev.getElementValueType(),
"Wrong type of element value");
+ assertEquals("4", ev.stringifyValue(), "Wrong value of element");
assertTrue(createTestdataFile("HelloWorld.class").delete());
}
@@ -127,26 +119,22 @@ public class GeneratingAnnotatedClassesTestCase extends
AbstractTestCase
buildClassContentsWithAnnotatedMethods(cg, cp, il);
// Check annotation is OK
int i = cg.getMethods()[0].getAnnotationEntries().length;
- assertTrue(i == 1,
- "Prior to dumping, main method should have 1 annotation but
has " + i);
+ assertEquals(1, i, "Wrong number of annotations of main method prior
to dumping");
dumpClass(cg, "temp1" + File.separator + "HelloWorld.class");
final JavaClass jc2 = getClassFrom("temp1", "HelloWorld");
// Check annotation is OK
i = jc2.getMethods()[0].getAnnotationEntries().length;
- assertTrue(i == 1,
- "JavaClass should say 1 annotation on main method but says " +
i);
+ assertEquals(1, i, "Wrong number of annotation on JavaClass");
final ClassGen cg2 = new ClassGen(jc2);
// Check it now it is a ClassGen
final Method[] m = cg2.getMethods();
i = m[0].getAnnotationEntries().length;
- assertTrue(i == 1,
- "The main 'Method' should have one annotation but has " + i);
+ assertEquals(1, i, "Wrong number of annotations on the main 'Method'");
final MethodGen mg = new MethodGen(m[0], cg2.getClassName(), cg2
.getConstantPool());
// Check it finally when the Method is changed to a MethodGen
i = mg.getAnnotationEntries().length;
- assertTrue(i == 1,
- "The main 'MethodGen' should have one annotation but has " +
i);
+ assertEquals(1, i, "Wrong number of annotations on the main
'MethodGen'");
assertTrue(wipe("temp1", "HelloWorld.class"));
}
@@ -171,14 +159,10 @@ public class GeneratingAnnotatedClassesTestCase extends
AbstractTestCase
final ClassGen cg2 = new ClassGen(jc2);
// Main method after reading the class back in
final Method mainMethod1 = jc2.getMethods()[0];
- assertTrue(mainMethod1.getAnnotationEntries().length == 1,
- "The 'Method' should have one annotations but has "
- + mainMethod1.getAnnotationEntries().length);
+ assertEquals(1, mainMethod1.getAnnotationEntries().length, "Wrong
number of annotations of the 'Method'");
final MethodGen mainMethod2 = new MethodGen(mainMethod1,
cg2.getClassName(),
cg2.getConstantPool());
- assertTrue(mainMethod2.getAnnotationEntries().length == 1,
- "The 'MethodGen' should have one annotation but has "
- + mainMethod2.getAnnotationEntries().length);
+ assertEquals(1, mainMethod2.getAnnotationEntries().length, "Wrong
number of annotations of the 'MethodGen'");
AnnotationEntryGen fruit =
createFruitAnnotation(cg2.getConstantPool(), "Pear");
mainMethod2.addAnnotationEntry(fruit);
cg2.removeMethod(mainMethod1);
@@ -188,16 +172,12 @@ public class GeneratingAnnotatedClassesTestCase extends
AbstractTestCase
final ClassGen cg3 = new ClassGen(jc3);
final Method mainMethod3 = cg3.getMethods()[1];
final int i = mainMethod3.getAnnotationEntries().length;
- assertTrue(i == 2,
- "The 'Method' should now have two annotations but has " + i);
+ assertEquals(2, i, "Wrong number of annotations on the 'Method'");
mainMethod2.removeAnnotationEntry(fruit);
- assertTrue(mainMethod2.getAnnotationEntries().length == 1,
- "The 'MethodGen' should have one annotation but has "
- + mainMethod2.getAnnotationEntries().length);
+ assertEquals(1, mainMethod2.getAnnotationEntries().length, "Wrong
number of annotations on the 'MethodGen'");
mainMethod2.removeAnnotationEntries();
- assertTrue(mainMethod2.getAnnotationEntries().length == 0,
- "The 'MethodGen' should have no annotations but has "
- + mainMethod2.getAnnotationEntries().length);
+ assertEquals(0, mainMethod2.getAnnotationEntries().length, 0,
+ "Wrong number of annotations on the 'MethodGen'");
assertTrue(wipe("temp2", "HelloWorld.class"));
assertTrue(wipe("temp3", "HelloWorld.class"));
}
@@ -214,8 +194,7 @@ public class GeneratingAnnotatedClassesTestCase extends
AbstractTestCase
final ClassGen cgen = new ClassGen(jc);
// Check annotations are correctly preserved
final AnnotationEntryGen[] annotations = cgen.getAnnotationEntries();
- assertTrue(annotations.length == 1,
- "Expected one annotation but found " + annotations.length);
+ assertEquals(1, annotations.length, "Wrong number of annotations");
}
/**
@@ -230,8 +209,7 @@ public class GeneratingAnnotatedClassesTestCase extends
AbstractTestCase
final ClassGen cgen = new ClassGen(jc);
// Check annotations are correctly preserved
final AnnotationEntryGen[] annotations = cgen.getAnnotationEntries();
- assertTrue(annotations.length == 1,
- "Expected one annotation but found " + annotations.length);
+ assertEquals(1, annotations.length, "Wrong number of annotations");
}
/**
@@ -246,27 +224,23 @@ public class GeneratingAnnotatedClassesTestCase extends
AbstractTestCase
final ClassGen cgen = new ClassGen(jc);
// Check annotations are correctly preserved
final AnnotationEntryGen[] annotations = cgen.getAnnotationEntries();
- assertTrue(annotations.length == 1,
- "Expected one annotation but found " + annotations.length);
+ assertEquals(1, annotations.length, "Wrong number of annotations");
final AnnotationEntryGen a = annotations[0];
- assertTrue(a.getValues().size() == 1,
- "That annotation should only have one value but has " +
a.getValues().size());
+ assertEquals(1, a.getValues().size(), "Wrong number of values for the
annotation");
final ElementValuePairGen nvp = a.getValues().get(0);
final ElementValueGen value = nvp.getValue();
assertTrue(value instanceof ArrayElementValueGen,
"Value should be ArrayElementValueGen but is " + value);
final ArrayElementValueGen arrayValue = (ArrayElementValueGen) value;
- assertTrue(arrayValue.getElementValuesSize() == 1,
- "Array value should be size one but is " +
arrayValue.getElementValuesSize());
+ assertEquals(1, arrayValue.getElementValuesSize(), "Wrong size of the
array");
final ElementValueGen innerValue =
arrayValue.getElementValues().get(0);
assertTrue(
innerValue instanceof AnnotationElementValueGen,
"Value in the array should be AnnotationElementValueGen but is
" + innerValue);
final AnnotationElementValueGen innerAnnotationValue =
(AnnotationElementValueGen) innerValue;
-
assertTrue(innerAnnotationValue.getAnnotation().getTypeSignature().equals(
-
"L"+PACKAGE_BASE_SIG+"/data/SimpleAnnotation;"),
- "Should be called L"+PACKAGE_BASE_SIG+"/data/SimpleAnnotation;
but is called: "
- + innerAnnotationValue.getAnnotation().getTypeName());
+ assertEquals("L" + PACKAGE_BASE_SIG + "/data/SimpleAnnotation;",
+ innerAnnotationValue.getAnnotation().getTypeSignature(),
+ "Wrong type signature");
// check the three methods
final Method[] methods = cgen.getMethods();
@@ -289,7 +263,7 @@ public class GeneratingAnnotatedClassesTestCase extends
AbstractTestCase
}
else
{
- fail("unexpected method "+method.getName());
+ fail(() -> "unexpected method " + method.getName());
}
}
}
@@ -298,7 +272,7 @@ public class GeneratingAnnotatedClassesTestCase extends
AbstractTestCase
{
final String methodName= method.getName();
final AnnotationEntry[] annos= method.getAnnotationEntries();
- assertEquals(expectedNumberAnnotations, annos.length, "For " +
methodName);
+ assertEquals(expectedNumberAnnotations, annos.length, () -> "For " +
methodName);
if(expectedNumberAnnotations!=0)
{
assertArrayElementValue(nExpectedArrayValues, annos[0]);
@@ -325,7 +299,8 @@ public class GeneratingAnnotatedClassesTestCase extends
AbstractTestCase
{
final AnnotationEntry[] annos=
parameterAnnotation.getAnnotationEntries();
final int expectedLength =
expectedNumberOfParmeterAnnotations[i++];
- assertEquals(expectedLength, annos.length, methodName + "
parameter " + i);
+ int j = i;
+ assertEquals(expectedLength, annos.length, () -> methodName + "
parameter " + j);
if(expectedLength!=0)
{
assertSimpleElementValue(annos[0]);
@@ -352,16 +327,14 @@ public class GeneratingAnnotatedClassesTestCase extends
AbstractTestCase
final ClassGen cgen = new ClassGen(jc);
// Check annotations are correctly preserved
final AnnotationEntryGen[] annotations = cgen.getAnnotationEntries();
- assertTrue(annotations.length == 1,
- "Expected one annotation but found " + annotations.length);
+ assertEquals(1, annotations.length, "Wrong number of annotations");
final List<?> l = annotations[0].getValues();
boolean found = false;
for (final Object name : l) {
final ElementValuePairGen element = (ElementValuePairGen) name;
if (element.getNameString().equals("dval"))
{
- if (((SimpleElementValueGen) element.getValue())
- .stringifyValue().equals("33.4")) {
+ if (element.getValue().stringifyValue().equals("33.4")) {
found = true;
}
}
@@ -380,8 +353,7 @@ public class GeneratingAnnotatedClassesTestCase extends
AbstractTestCase
final ClassGen cgen = new ClassGen(jc);
final ConstantPoolGen cp = cgen.getConstantPool();
cgen.addAnnotationEntry(createFruitAnnotation(cp, "Pineapple"));
- assertTrue(cgen.getAnnotationEntries().length == 2,
- "Should now have two annotations but has " +
cgen.getAnnotationEntries().length);
+ assertEquals(2, cgen.getAnnotationEntries().length, "Wrong number of
annotations");
dumpClass(cgen, "SimpleAnnotatedClass.class");
assertTrue(wipe("SimpleAnnotatedClass.class"));
}
@@ -397,8 +369,7 @@ public class GeneratingAnnotatedClassesTestCase extends
AbstractTestCase
final ClassGen cgen = new ClassGen(jc);
final ConstantPoolGen cp = cgen.getConstantPool();
cgen.addAnnotationEntry(createCombinedAnnotation(cp));
- assertTrue(cgen.getAnnotationEntries().length == 2,
- "Should now have two annotations but has " +
cgen.getAnnotationEntries().length);
+ assertEquals(2, cgen.getAnnotationEntries().length, "Wrong number of
annotations");
dumpClass(cgen, "SimpleAnnotatedClass.class");
final JavaClass jc2 = getClassFrom(".", "SimpleAnnotatedClass");
jc2.getAnnotationEntries();
diff --git a/src/test/java/org/apache/bcel/generic/JdkGenericDumpTestCase.java
b/src/test/java/org/apache/bcel/generic/JdkGenericDumpTestCase.java
index 3fe7305..f7a1654 100644
--- a/src/test/java/org/apache/bcel/generic/JdkGenericDumpTestCase.java
+++ b/src/test/java/org/apache/bcel/generic/JdkGenericDumpTestCase.java
@@ -25,7 +25,6 @@ import static org.junit.jupiter.api.Assertions.fail;
import static org.junit.jupiter.api.Assumptions.assumeTrue;
import java.io.File;
-import java.io.FileFilter;
import java.io.IOException;
import java.io.InputStream;
import java.nio.file.FileSystems;
@@ -198,7 +197,7 @@ public class JdkGenericDumpTestCase {
final InstructionList instructionList = new InstructionList(src);
final byte[] out = instructionList.getByteCode();
if (src.length == out.length) {
- assertArrayEquals(src, out, name + ": " + method.toString());
+ assertArrayEquals(src, out, () -> name + ": " + method.toString());
} else {
System.out.println(name + ": " + method.toString() + " " +
src.length + " " + out.length);
System.out.println(bytesToHex(src));
@@ -212,12 +211,12 @@ public class JdkGenericDumpTestCase {
private File[] listJdkJars(String javaHome) throws Exception {
final File javaLib = new File(javaHome, "lib");
- return javaLib.listFiles((FileFilter) file ->
file.getName().endsWith(".jar"));
+ return javaLib.listFiles(file -> file.getName().endsWith(".jar"));
}
private File[] listJdkModules(String javaHome) throws Exception {
final File javaLib = new File(javaHome, "jmods");
- return javaLib.listFiles((FileFilter) file ->
file.getName().endsWith(".jmod"));
+ return javaLib.listFiles(file -> file.getName().endsWith(".jmod"));
}
private void testJar(final File file) throws Exception {
diff --git a/src/test/java/org/apache/bcel/generic/MethodGenTestCase.java
b/src/test/java/org/apache/bcel/generic/MethodGenTestCase.java
index 7f7ad9d..2a99224 100644
--- a/src/test/java/org/apache/bcel/generic/MethodGenTestCase.java
+++ b/src/test/java/org/apache/bcel/generic/MethodGenTestCase.java
@@ -68,7 +68,7 @@ public class MethodGenTestCase {
}
}
- fail("Method " + name + " not found in class " + cls);
+ fail(() -> "Method " + name + " not found in class " + cls);
return null;
}
diff --git
a/src/test/java/org/apache/bcel/verifier/AbstractVerifierTestCase.java
b/src/test/java/org/apache/bcel/verifier/AbstractVerifierTestCase.java
index d82fc5f..30400d5 100644
--- a/src/test/java/org/apache/bcel/verifier/AbstractVerifierTestCase.java
+++ b/src/test/java/org/apache/bcel/verifier/AbstractVerifierTestCase.java
@@ -23,7 +23,6 @@ import org.apache.bcel.classfile.JavaClass;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertTrue;
-import static org.junit.jupiter.api.Assertions.fail;
public abstract class AbstractVerifierTestCase {
@@ -35,7 +34,7 @@ public abstract class AbstractVerifierTestCase {
* @param classname simple classname of the class to verify
* @param message message displayed if assertion fails
*/
- public void assertVerifyOK(final String classname, final String message) {
+ public void assertVerifyOK(final String classname, final String message)
throws ClassNotFoundException {
final String testClassname = TEST_PACKAGE + classname;
assertTrue(doAllPasses(testClassname), message);
}
@@ -47,7 +46,7 @@ public abstract class AbstractVerifierTestCase {
* @param classname simple classname of the class to verify
* @param message message displayed if assertion fails
*/
- public void assertVerifyRejected(final String classname, final String
message) {
+ public void assertVerifyRejected(final String classname, final String
message) throws ClassNotFoundException {
final String testClassname = TEST_PACKAGE + classname;
assertFalse(doAllPasses(testClassname), message);
}
@@ -58,16 +57,9 @@ public abstract class AbstractVerifierTestCase {
* @param classname name of the class to verify
* @return false if the verification fails, true otherwise
*/
- public boolean doAllPasses(final String classname) {
- int nbMethods = 0;
-
- try {
- final JavaClass jc = Repository.lookupClass(classname);
- nbMethods = jc.getMethods().length;
- } catch (final ClassNotFoundException e) {
- fail(e.getMessage());
- return false;
- }
+ public boolean doAllPasses(final String classname) throws
ClassNotFoundException {
+ final JavaClass jc = Repository.lookupClass(classname);
+ int nbMethods = jc.getMethods().length;
final Verifier verifier = VerifierFactory.getVerifier(classname);
VerificationResult result = verifier.doPass1();
diff --git
a/src/test/java/org/apache/bcel/verifier/VerifierArrayAccessTestCase.java
b/src/test/java/org/apache/bcel/verifier/VerifierArrayAccessTestCase.java
index 6a9bc4a..01170c8 100644
--- a/src/test/java/org/apache/bcel/verifier/VerifierArrayAccessTestCase.java
+++ b/src/test/java/org/apache/bcel/verifier/VerifierArrayAccessTestCase.java
@@ -28,7 +28,7 @@ import org.junit.jupiter.api.Test;
public class VerifierArrayAccessTestCase extends AbstractVerifierTestCase {
@Test
- public void testInvalidArrayAccess() throws IOException {
+ public void testInvalidArrayAccess() throws IOException,
ClassNotFoundException {
new TestArrayAccess03Creator().create();
assertVerifyRejected("TestArrayAccess03", "Verification of an
arraystore instruction on an object must fail.");
new TestArrayAccess04Creator().create();
@@ -37,7 +37,7 @@ public class VerifierArrayAccessTestCase extends
AbstractVerifierTestCase {
}
@Test
- public void testValidArrayAccess() throws IOException {
+ public void testValidArrayAccess() throws IOException,
ClassNotFoundException {
assertVerifyOK("TestArrayAccess01",
"Verification of an arraystore instruction on an array that is
not compatible with the stored element must pass.");
new TestArrayAccess02Creator().create();
diff --git a/src/test/java/org/apache/bcel/verifier/VerifierInvokeTestCase.java
b/src/test/java/org/apache/bcel/verifier/VerifierInvokeTestCase.java
index 43d7739..9c8eebb 100644
--- a/src/test/java/org/apache/bcel/verifier/VerifierInvokeTestCase.java
+++ b/src/test/java/org/apache/bcel/verifier/VerifierInvokeTestCase.java
@@ -23,23 +23,23 @@ import org.junit.jupiter.api.Test;
public class VerifierInvokeTestCase extends AbstractVerifierTestCase {
@Test
- public void testLegalInvokeVirtual() {
+ public void testLegalInvokeVirtual() throws ClassNotFoundException {
assertVerifyOK("TestLegalInvokeVirtual01", "Verification of
invokevirtual on method defined in superclass must pass.");
assertVerifyOK("TestLegalInvokeVirtual02", "Verification of
invokevirtual on method defined in superinterface must pass.");
}
@Test
- public void testLegalInvokeStatic() {
+ public void testLegalInvokeStatic() throws ClassNotFoundException {
assertVerifyOK("TestLegalInvokeStatic01", "Verification of
invokestatic on method defined in superclass must pass.");
}
@Test
- public void testLegalInvokeInterface() {
+ public void testLegalInvokeInterface() throws ClassNotFoundException {
assertVerifyOK("TestLegalInvokeInterface01", "Verification of
invokeinterface on method defined in superinterface must pass.");
}
@Test
- public void testLegalInvokeSpecial() {
+ public void testLegalInvokeSpecial() throws ClassNotFoundException {
assertVerifyOK("TestLegalInvokeSpecial01", "Verification of
invokespecial on method defined in superclass must pass.");
assertVerifyOK("TestLegalInvokeSpecial02", "Verification of
invokespecial on method defined in superclass must pass.");
}
diff --git a/src/test/java/org/apache/bcel/verifier/VerifierReturnTestCase.java
b/src/test/java/org/apache/bcel/verifier/VerifierReturnTestCase.java
index 6238c68..d21a55c 100644
--- a/src/test/java/org/apache/bcel/verifier/VerifierReturnTestCase.java
+++ b/src/test/java/org/apache/bcel/verifier/VerifierReturnTestCase.java
@@ -26,7 +26,7 @@ import org.junit.jupiter.api.Test;
public class VerifierReturnTestCase extends AbstractVerifierTestCase {
@Test
- public void testInvalidReturn() throws IOException {
+ public void testInvalidReturn() throws IOException, ClassNotFoundException
{
new TestReturn01Creator().create();
assertVerifyRejected("TestReturn01", "Verification of a void method
that returns an object must fail.");
new TestReturn03Creator().create();
@@ -34,7 +34,7 @@ public class VerifierReturnTestCase extends
AbstractVerifierTestCase {
}
@Test
- public void testValidReturn() {
+ public void testValidReturn() throws ClassNotFoundException {
assertVerifyOK("TestReturn02", "Verification of a method that returns
a newly created object must pass.");
assertVerifyOK("TestArray01", "Verification of a method that returns
an array must pass.");
}