Commit f0c46506 authored by Eric Bruneton's avatar Eric Bruneton
Browse files

Address code review comments.

parent 40c07e33
Pipeline #4444 passed with stage
in 11 minutes and 7 seconds
......@@ -122,6 +122,11 @@ public class AnalyzerAdapterTest extends AsmTest {
}
}
/**
* A ClassVisitor that inserts intermediate frames before each instruction of each method, using
* the types computed with an AnalyzerAdapter (in order to check that these intermediate frames
* are correct).
*/
static class ClassAnalyzerAdapter extends ClassVisitor {
private String owner;
......
......@@ -29,11 +29,11 @@ package org.objectweb.asm.commons;
import static org.junit.jupiter.api.Assertions.assertDoesNotThrow;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.junit.jupiter.api.Assertions.assertTrue;
import java.io.IOException;
import java.util.concurrent.atomic.AtomicLong;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.MethodSource;
......@@ -58,52 +58,57 @@ public class SerialVersionUidAdderTest extends AsmTest {
@Test
public void testAllMethods_class() throws IOException {
AtomicLong svuid = new AtomicLong();
ClassReader classReader = new ClassReader("SerialVersionClass");
SerialVersionUIDAdder svuidAdder = new SerialVersionUIDAdder(null);
classReader.accept(new SerialVersionUidCalculator(svuid), 0);
classReader.accept(svuidAdder, 0);
long svuid = svuidAdder.computeSVUID();
assertEquals(4654798559887898126L, svuid.get());
assertEquals(4654798559887898126L, svuid);
}
@Test
public void testAllMethods_anonymousInnerClass() throws IOException {
AtomicLong svuid = new AtomicLong();
ClassReader classReader = new ClassReader("SerialVersionAnonymousInnerClass$1");
SerialVersionUIDAdder svuidAdder = new SerialVersionUIDAdder(null);
classReader.accept(new SerialVersionUidCalculator(svuid), 0);
classReader.accept(svuidAdder, 0);
long svuid = svuidAdder.computeSVUID();
assertEquals(2591057588230880800L, svuid.get());
assertEquals(2591057588230880800L, svuid);
}
@Test
public void testAllMethods_interface() throws IOException {
AtomicLong svuid = new AtomicLong();
ClassReader classReader = new ClassReader("SerialVersionInterface");
SerialVersionUIDAdder svuidAdder = new SerialVersionUIDAdder(null);
classReader.accept(new SerialVersionUidCalculator(svuid), 0);
classReader.accept(svuidAdder, 0);
long svuid = svuidAdder.computeSVUID();
assertEquals(682190902657822970L, svuid.get());
assertEquals(682190902657822970L, svuid);
}
@Test
public void testAllMethods_emptyInterface() throws IOException {
AtomicLong svuid = new AtomicLong();
ClassReader classReader = new ClassReader("SerialVersionEmptyInterface");
SerialVersionUIDAdder svuidAdder = new SerialVersionUIDAdder(null);
classReader.accept(new SerialVersionUidCalculator(svuid), 0);
classReader.accept(svuidAdder, 0);
long svuid = svuidAdder.computeSVUID();
assertEquals(-2126445979242430981L, svuid.get());
assertEquals(-2126445979242430981L, svuid);
}
@Test
public void testAllMethods_enum() throws IOException {
AtomicLong svuid = new AtomicLong();
ClassReader classReader = new ClassReader("SerialVersionEnum");
ClassWriter classWriter = new ClassWriter(0);
SerialVersionUIDAdder svuidAdder = new SerialVersionUIDAdder(classWriter);
classReader.accept(new SerialVersionUidCalculator(svuid), 0);
classReader.accept(svuidAdder, 0);
assertEquals(0L, svuid.get());
assertFalse(new ClassFile(classWriter.toByteArray()).toString().contains("serialVersionUID"));
}
/**
......@@ -123,20 +128,4 @@ public class SerialVersionUidAdderTest extends AsmTest {
assertTrue(new ClassFile(classWriter.toByteArray()).toString().contains("serialVersionUID"));
}
}
static class SerialVersionUidCalculator extends SerialVersionUIDAdder {
private final AtomicLong svuid;
SerialVersionUidCalculator(final AtomicLong svuid) {
super(Opcodes.ASM7, null);
this.svuid = svuid;
}
@Override
protected long computeSVUID() throws IOException {
svuid.set(super.computeSVUID());
return svuid.get();
}
}
}
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment