package org.innocuous; public class Chicken { public static class Foo { public void myMethod(boolean trash) { System.out.println("Expecting class Foo"); Class c = Foo.class; System.out.println("Got the class " + c); } } public static class Bar { public void myMethod(boolean doAssert) { System.out.println("Expecting class Bar"); Class c = Bar.class; System.out.println("Got the class " + c); // Any one of the following things will make the test fail and load the wrong class // Even if the assert is skipped by a conditional. assert c.getName().endsWith("Bar"); //assert c != null; //assert Class.class != null; /* int i = 1; assert i != 2; */ /* if (doAssert) assert c.getName().endsWith("Bar"); */ } } public static void main(String[] args) { new Foo().myMethod(false); new Bar().myMethod(false); } }