commons-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Benedikt Ritter <brit...@apache.org>
Subject Re: svn commit: r1749612 - /commons/proper/bcel/trunk/src/test/java/org/apache/bcel/generic/JDKGenericDumpTestCase.java
Date Wed, 22 Jun 2016 06:29:00 GMT
Hi,

Benedikt Ritter <britter@apache.org> schrieb am Mi., 22. Juni 2016 um
08:26 Uhr:

> Hello Gary,
>
> I don't understand this change. Wouldn't it be easier to assign the value
> of java.home to a field in a setup method?
>

I've reviewed the later changes which introduce the code for checking Java
Homes on Windows. Now it makes sense.

Thank you!


>
> Benedikt
>
>
> <ggregory@apache.org> schrieb am Mi., 22. Juni 2016 um 00:00 Uhr:
>
>> Author: ggregory
>> Date: Tue Jun 21 22:00:25 2016
>> New Revision: 1749612
>>
>> URL: http://svn.apache.org/viewvc?rev=1749612&view=rev
>> Log:
>> Parameterize test.
>>
>> Modified:
>>
>> commons/proper/bcel/trunk/src/test/java/org/apache/bcel/generic/JDKGenericDumpTestCase.java
>>
>> Modified:
>> commons/proper/bcel/trunk/src/test/java/org/apache/bcel/generic/JDKGenericDumpTestCase.java
>> URL:
>> http://svn.apache.org/viewvc/commons/proper/bcel/trunk/src/test/java/org/apache/bcel/generic/JDKGenericDumpTestCase.java?rev=1749612&r1=1749611&r2=1749612&view=diff
>>
>> ==============================================================================
>> ---
>> commons/proper/bcel/trunk/src/test/java/org/apache/bcel/generic/JDKGenericDumpTestCase.java
>> (original)
>> +++
>> commons/proper/bcel/trunk/src/test/java/org/apache/bcel/generic/JDKGenericDumpTestCase.java
>> Tue Jun 21 22:00:25 2016
>> @@ -23,6 +23,8 @@ import static org.junit.Assert.fail;
>>  import java.io.File;
>>  import java.io.FileFilter;
>>  import java.io.InputStream;
>> +import java.util.Arrays;
>> +import java.util.Collection;
>>  import java.util.Enumeration;
>>  import java.util.jar.JarEntry;
>>  import java.util.jar.JarFile;
>> @@ -32,14 +34,29 @@ import org.apache.bcel.classfile.Code;
>>  import org.apache.bcel.classfile.JavaClass;
>>  import org.apache.bcel.classfile.Method;
>>  import org.junit.Test;
>> +import org.junit.runner.RunWith;
>> +import org.junit.runners.Parameterized;
>> +import org.junit.runners.Parameterized.Parameters;
>>
>>  /**
>>   * Test that the generic dump() methods work on the JDK classes
>>   * Reads each class into an instruction list and then dumps
>>   * the instructions. The output bytes should be the same as the input.
>>   */
>> +@RunWith(Parameterized.class)
>>  public class JDKGenericDumpTestCase {
>>
>> +    @Parameters(name = "{0}")
>> +    public static Collection<Object[]> data() {
>> +        return Arrays.asList(new Object[][] { {
>> System.getProperty("java.home") } });
>> +    }
>> +
>> +    public JDKGenericDumpTestCase(final String javaHome) {
>> +        this.javaHome = javaHome;
>> +    }
>> +
>> +    private String javaHome;
>> +
>>      @Test
>>      public void testJDKjars() throws Exception {
>>          final File[] jars = listJDKjars();
>> @@ -70,18 +87,18 @@ public class JDKGenericDumpTestCase {
>>      }
>>
>>      private void compare(final String name, final Method m) {
>> -//        System.out.println("Method: " + m);
>> +        // System.out.println("Method: " + m);
>>          final Code c = m.getCode();
>> -        if (c==null) {
>> +        if (c == null) {
>>              return; // e.g. abstract method
>>          }
>>          final byte[] src = c.getCode();
>>          final InstructionList il = new InstructionList(src);
>>          final byte[] out = il.getByteCode();
>>          if (src.length == out.length) {
>> -            assertArrayEquals(name + ": "+m.toString(), src, out);
>> +            assertArrayEquals(name + ": " + m.toString(), src, out);
>>          } else {
>> -            System.out.println(name + ": "+m.toString() +" "+
>> src.length+" "+out.length);
>> +            System.out.println(name + ": " + m.toString() + " " +
>> src.length + " " + out.length);
>>              System.out.println(bytesToHex(src));
>>              System.out.println(bytesToHex(out));
>>              for (final InstructionHandle ih : il) {
>> @@ -92,7 +109,7 @@ public class JDKGenericDumpTestCase {
>>      }
>>
>>      private File[] listJDKjars() throws Exception {
>> -        final File javaLib = new File(System.getProperty("java.home") +
>> "/lib");
>> +        final File javaLib = new File(javaHome + "/lib");
>>          return javaLib.listFiles(new FileFilter() {
>>              @Override
>>              public boolean accept(final File file) {
>> @@ -102,9 +119,10 @@ public class JDKGenericDumpTestCase {
>>      }
>>
>>      private static final char[] hexArray =
>> "0123456789ABCDEF".toCharArray();
>> +
>>      private static String bytesToHex(final byte[] bytes) {
>>          final char[] hexChars = new char[bytes.length * 3];
>> -        int i=0;
>> +        int i = 0;
>>          for (final byte b : bytes) {
>>              final int v = b & 0xFF;
>>              hexChars[i++] = hexArray[v >>> 4];
>>
>>
>>

Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message