summaryrefslogtreecommitdiff
path: root/test/068-classloader/src/Main.java
diff options
context:
space:
mode:
Diffstat (limited to 'test/068-classloader/src/Main.java')
-rw-r--r--test/068-classloader/src/Main.java57
1 files changed, 57 insertions, 0 deletions
diff --git a/test/068-classloader/src/Main.java b/test/068-classloader/src/Main.java
index 7dfb6f507d..1b2a4a4ceb 100644
--- a/test/068-classloader/src/Main.java
+++ b/test/068-classloader/src/Main.java
@@ -58,6 +58,63 @@ public class Main {
testAbstract(loader);
testImplement(loader);
testIfaceImplement(loader);
+
+ testSeparation();
+ }
+
+ static void testSeparation() {
+ FancyLoader loader1 = new FancyLoader(ClassLoader.getSystemClassLoader());
+ FancyLoader loader2 = new FancyLoader(ClassLoader.getSystemClassLoader());
+
+ try {
+ Class target1 = loader1.loadClass("MutationTarget");
+ Class target2 = loader2.loadClass("MutationTarget");
+
+ if (target1 == target2) {
+ throw new RuntimeException("target1 should not be equal to target2");
+ }
+
+ Class mutator1 = loader1.loadClass("Mutator");
+ Class mutator2 = loader2.loadClass("Mutator");
+
+ if (mutator1 == mutator2) {
+ throw new RuntimeException("mutator1 should not be equal to mutator2");
+ }
+
+ runMutator(mutator1, 1);
+
+ int value = getMutationTargetValue(target1);
+ if (value != 1) {
+ throw new RuntimeException("target 1 has unexpected value " + value);
+ }
+ value = getMutationTargetValue(target2);
+ if (value != 0) {
+ throw new RuntimeException("target 2 has unexpected value " + value);
+ }
+
+ runMutator(mutator2, 2);
+
+ value = getMutationTargetValue(target1);
+ if (value != 1) {
+ throw new RuntimeException("target 1 has unexpected value " + value);
+ }
+ value = getMutationTargetValue(target2);
+ if (value != 2) {
+ throw new RuntimeException("target 2 has unexpected value " + value);
+ }
+ } catch (Exception ex) {
+ ex.printStackTrace();
+ }
+ }
+
+ private static void runMutator(Class c, int v) throws Exception {
+ java.lang.reflect.Method m = c.getDeclaredMethod("mutate", int.class);
+ m.invoke(null, v);
+ }
+
+ private static int getMutationTargetValue(Class c) throws Exception {
+ java.lang.reflect.Field f = c.getDeclaredField("value");
+ return f.getInt(null);
}
/**