Path: blob/master/test/jdk/java/lang/instrument/GetAllLoadedClassesTest.java
41152 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 getAllLoadedClasses (is Object there? does a newly loaded class show up?)27* @author Gabriel Adauto, Wily Technology28*29* @run build GetAllLoadedClassesTest DummyClass30* @run shell MakeJAR.sh basicAgent31* @run main/othervm -javaagent:basicAgent.jar GetAllLoadedClassesTest GetAllLoadedClassesTest32*/3334import java.net.*;3536public class37GetAllLoadedClassesTest38extends ASimpleInstrumentationTestCase39{4041/**42* Constructor for GetAllLoadedClassesTest.43* @param name44*/45public GetAllLoadedClassesTest(String name)46{47super(name);48}4950public static void51main (String[] args)52throws Throwable {53ATestCaseScaffold test = new GetAllLoadedClassesTest(args[0]);54test.runTest();55}5657protected final void58doRunTest()59throws Throwable {60testGetAllLoadedClasses();61}6263public void64testGetAllLoadedClasses()65throws Throwable66{67ClassLoader loader = getClass().getClassLoader();6869Class[] classes = fInst.getAllLoadedClasses();70assertNotNull(classes);71assertClassArrayDoesNotContainClassByName(classes, "DummyClass");72assertClassArrayContainsClass(classes, Object.class);7374Class dummy = loader.loadClass("DummyClass");75assertEquals("DummyClass", dummy.getName());7677// double check that we can make an instance (just to prove the loader is kosher)78Object testInstance = dummy.newInstance();7980Class[] classes2 = fInst.getAllLoadedClasses();81assertNotNull(classes2);82assertClassArrayContainsClass(classes2, dummy);83}8485}868788