package org.apache.commons.bcel6.util;

import static org.junit.Assert.*;

import java.io.ByteArrayOutputStream;
import java.io.OutputStream;

import org.apache.commons.bcel6.classfile.JavaClass;
import org.junit.Test;

public class BCELifierTestCase {

    @Test
    public void test() throws Exception {
        OutputStream os = new ByteArrayOutputStream();
        JavaClass java_class = BCELifier.getJavaClass("Java8Example");
        assertNotNull(java_class);
        BCELifier bcelifier = new BCELifier(java_class, os);
        bcelifier.start();
    }

}

@@ -84,27 +84,145 @@
 ava.io.B
-yteArrayOut
+ufferedInputStream;%0Aimport java.io.ByteArrayOutputStream;%0Aimport java.io.File;%0Aimport java.io.FileOutputStream;%0Aimport java.io.In
 putStrea
@@ -253,17 +253,16 @@
 Stream;%0A
-%0A
 import o
@@ -330,16 +330,17 @@
 .Test;%0A%0A
+%0A
 public c
@@ -635,24 +635,24 @@
 class, os);%0A
-
         bcel
@@ -673,10 +673,2097 @@
 %0A    %7D%0A%0A
+    /*%0A     * Dump a class using %22javap%22 and compare with the same class recreated%0A     * using BCELifier, %22javac%22, %22java%22 and dumped with %22javap%22%0A     * TODO: detect if JDK present and skip test if not %0A     */%0A    @Test%0A    public void testJavapCompare() throws Exception %7B%0A        testClassOnPath(%22target/test-classes/Java8Example.class%22);%0A    %7D%0A%0A    private void testClassOnPath(String javaClass) throws Exception %7B%0A        // Get javap of the input class%0A        final String initial = exec(null, %22javap%22, %22-p%22, javaClass);%0A%0A        final File workDir = new File(%22target%22);%0A        File infile = new File(javaClass);%0A        JavaClass java_class = BCELifier.getJavaClass(infile.getName().replace(%22.class%22, %22%22));%0A        assertNotNull(java_class);%0A        File outfile = new File(workDir,infile.getName().replace(%22.class%22, %22Creator.java%22));%0A        FileOutputStream fos = new FileOutputStream(outfile);%0A        BCELifier bcelifier = new BCELifier(java_class, fos);%0A        bcelifier.start();%0A        fos.close();%0A        exec(workDir, %22javac%22, %22-cp%22, %22classes%22, outfile.getName());%0A        exec(workDir, %22java%22, %22-cp%22, %22.:classes%22, outfile.getName().replace(%22.java%22, %22%22));%0A        final String output = exec(workDir, %22javap%22, %22-p%22, infile.getName());%0A        assertEquals(initial, output);%0A    %7D%0A%0A    private String exec(File workDir, String ... args) throws Exception %7B%0A//        System.err.println(java.util.Arrays.toString(args));%0A        ProcessBuilder pb = new ProcessBuilder( args );%0A        pb.directory(workDir);%0A        Process proc = pb.start();%0A        BufferedInputStream is = new BufferedInputStream(proc.getInputStream());%0A        InputStream es = proc.getErrorStream();%0A        proc.waitFor();%0A        byte %5B%5Dbuff=new byte%5B2048%5D;%0A        int len;%0A        while((len=es.read(buff)) != -1) %7B%0A            System.err.print(new String(buff,0,len));%0A        %7D%0A        %0A        StringBuilder sb = new StringBuilder();%0A        while((len=is.read(buff)) != -1) %7B%0A            sb.append(new String(buff,0,len));%0A        %7D%0A        is.close();%0A        return sb.toString();%0A    %7D%0A%0A
 %7D%0A

Add a round-trip BCELifier test case