/*
 * Copyright (c) 2006-2011 Rogério Liesenfeld
 * This file is subject to the terms of the MIT license (see LICENSE.txt).
 */
package mockit.multicore;

import org.junit.*;

import mockit.*;

public final class CopyingClassLoaderTest
{
   final CopyingClassLoader copyingCL = new CopyingClassLoader();

   @Test
   public void createCopyOfClassWithoutCausingDependenciesToBeLoaded() throws Exception
   {
      Class<?> original = A.class;

      Class<?> copy = copyingCL.getCopy(original.getName());

      assert original != copy;
      assert original.getClassLoader() == ClassLoader.getSystemClassLoader();
      assert copy.getClassLoader() == copyingCL;
      assert !copyingCL.hasLoadedClass(B.class);
      assert copy.getPackage() != null;
   }

   @SuppressWarnings({"UnusedDeclaration"})
   public static class A
   {
      final B b = new B();

      public static boolean doSomething(int i) { return i > 0; }
      Class<?> getClassOfDependency() { return b.getClass(); }
   }

   public static class B
   {
      @SuppressWarnings({"UnusedDeclaration"})
      public boolean doSomething(int i) { return i > 0; }
   }

   @Test
   public void createCopyOfClassAndCauseDependencyToBeLoaded() throws Exception
   {
      Class<?> original = A.class;

      Class<?> copy = copyingCL.getCopy(original.getName());

      Object a = Deencapsulation.newInstance(copy);
      assert a.getClass() == copy;
      assert copyingCL.hasLoadedClass(B.class);

      Class<?> bClass = Deencapsulation.invoke(a, "getClassOfDependency");
      assert bClass == B.class; // would be different if B was defined outside a "mockit" package
      assert "B".equals(bClass.getSimpleName());
   }
}

@@ -150,24 +150,59 @@
 lticore;%0D%0A%0D%0A
+import static org.junit.Assert.*;%0D%0A
 import org.j
@@ -566,25 +566,32 @@
   assert
- 
+NotSame(
 original
  != copy
@@ -586,16 +586,15 @@
 inal
- !=
+,
  copy
+)
 ;%0D%0A 
@@ -608,21 +608,13 @@
 sert
- original.get
+Same(
 Clas
@@ -620,22 +620,26 @@
 ssLoader
-() == 
+.getSystem
 ClassLoa
@@ -637,34 +637,40 @@
 mClassLoader
-.getSystem
+(), original.get
 ClassLoader(
@@ -670,16 +670,17 @@
 Loader()
+)
 ;%0D%0A     
@@ -678,32 +678,47 @@
 );%0D%0A      assert
+Same(copyingCL,
  copy.getClassLo
@@ -727,21 +727,9 @@
 er()
- == copyingCL
+)
 ;%0D%0A 
@@ -739,18 +739,22 @@
   assert
- !
+False(
 copyingC
@@ -778,16 +778,17 @@
 B.class)
+)
 ;%0D%0A     
@@ -790,25 +790,32 @@
       assert
- 
+NotNull(
 copy.getPack
@@ -823,16 +823,9 @@
 ge()
- != null
+)
 ;%0D%0A 
@@ -1487,16 +1487,26 @@
   assert
+Same(copy,
  a.getCl
@@ -1514,16 +1514,9 @@
 ss()
- == copy
+)
 ;%0D%0A 
@@ -1526,17 +1526,21 @@
   assert
- 
+True(
 copyingC
@@ -1564,16 +1564,17 @@
 B.class)
+)
 ;%0D%0A%0D%0A   
@@ -1662,26 +1662,29 @@
 sert
- bClass == B.c
+Same(B.class, bC
 lass
+)
 ; //
@@ -1764,20 +1764,20 @@
 sert
- %22B%22.e
+E
 quals(
+%22B%22, 
 bCla

Replace Java asserts with JUnit asserts.