Path: blob/master/test/jdk/java/lang/instrument/GetInitiatedClassesTest.java
41149 views
/*1* Copyright (c) 2003, 2015, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation.7*8* This code is distributed in the hope that it will be useful, but WITHOUT9* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or10* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License11* version 2 for more details (a copy is included in the LICENSE file that12* accompanied this code).13*14* You should have received a copy of the GNU General Public License version15* 2 along with this work; if not, write to the Free Software Foundation,16* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.17*18* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA19* or visit www.oracle.com if you need additional information or have any20* questions.21*/2223/**24* @test25* @bug 488279826* @summary simple tests for getInitiatedClasses (does a newly loaded class show up?)27* @author Gabriel Adauto, Wily Technology28*29* @run build GetInitiatedClassesTest DummyClass30* @run shell MakeJAR.sh basicAgent31* @run main/othervm -javaagent:basicAgent.jar GetInitiatedClassesTest GetInitiatedClassesTest32*/3334public class35GetInitiatedClassesTest36extends ASimpleInstrumentationTestCase37{3839/**40* Constructor for GetInitiatedClassesTest.41* @param name42*/43public GetInitiatedClassesTest(String name)44{45super(name);46}4748public static void49main (String[] args)50throws Throwable {51ATestCaseScaffold test = new GetInitiatedClassesTest(args[0]);52test.runTest();53}5455protected final void56doRunTest()57throws Throwable {58testGetInitiatedClasses();59}6061public void62testGetInitiatedClasses()63throws Throwable64{65ClassLoader loader = getClass().getClassLoader();6667Class[] classes = fInst.getInitiatedClasses(loader);68assertNotNull(classes);6970Class dummy = loader.loadClass("DummyClass");71assertEquals("DummyClass", dummy.getName());7273// double check that we can make an instance (just to prove the loader is kosher)74Object testInstance = dummy.newInstance();7576Class[] classes2 = fInst.getInitiatedClasses(loader);77assertNotNull(classes2);78assertClassArrayContainsClass(classes2, dummy);79}8081}828384