Skip to content
This repository has been archived by the owner on Jun 12, 2021. It is now read-only.

Commit

Permalink
Test case for [JENKINS-28799]
Browse files Browse the repository at this point in the history
  • Loading branch information
jtnord committed Jun 9, 2015
1 parent 4942730 commit 15c2985
Showing 1 changed file with 29 additions and 0 deletions.
29 changes: 29 additions & 0 deletions src/test/java/CompatibilityTest.java
@@ -1,9 +1,11 @@
import junit.framework.TestResult;
import junit.framework.TestSuite;
import junit.textui.TestRunner;

import org.apache.commons.io.FileUtils;
import org.apache.tools.ant.AntClassLoader;
import org.jenkinsci.bytecode.Transformer;
import org.junit.Ignore;
import org.junit.Test;

import java.io.File;
Expand Down Expand Up @@ -31,6 +33,32 @@ public void v2() throws Exception {
assertFieldType(i, String[].class, "y");
assertFieldType(i, Object.class, "z");
}

@Test
public void testClassesAreOnlyReWrittenWhenNeeded() throws Exception {
System.out.println("rewrtting tests");
final Transformer t = new Transformer();
AntClassLoader cl = new AntClassLoader() {
@Override
protected Class<?> defineClassFromData(File container, byte[] classData, String classname) throws IOException {
byte[] rewritten = t.transform(classname, classData);
if (rewritten!=classData ) {
fail(classname + " was rewritten without need");
}
return super.defineClassFromData(container, rewritten, classname);
}
};

cl.addPathComponent(new File("target/test-classes/v2"));
cl.addPathComponent(new File("target/test-classes/client"));
cl.addPathComponent(new File("target/lib/ivy.jar"));

t.loadRules(cl);

cl.loadClass("org.apache.ivy.core.settings.IvySettings");
System.out.println("rewrtting tests - done");
}


private void assertFieldType(Class<?> i, Class<?> type, String name) throws NoSuchFieldException {
assertSame(type, i.getDeclaredField(name).getType());
Expand Down Expand Up @@ -69,4 +97,5 @@ private void verify(ClassLoader cl) throws Exception {
if (tr.errorCount() + tr.failureCount()>0)
throw new Error("test failures");
}

}

0 comments on commit 15c2985

Please sign in to comment.