1/* 2 * Copyright (C) 2010 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17package libcore.java.lang.reflect; 18 19import junit.framework.TestCase; 20import tests.util.ClassLoaderBuilder; 21 22public final class MissingClassesTest extends TestCase { 23 24 private Class<?> loadableClass; 25 26 @Override protected void setUp() throws Exception { 27 String prefix = MissingClassesTest.class.getName(); 28 ClassLoader cl = new ClassLoaderBuilder() 29 .withPrivateCopy(prefix + "$Loadable") 30 .without(prefix + "$Unloadable") 31 .build(); 32 loadableClass = cl.loadClass(prefix + "$Loadable"); 33 } 34 35 /** 36 * http://b/issue?id=2634005 37 */ 38 public void testGetDeclaredFieldsFails() { 39 try { 40 loadableClass.getDeclaredFields(); 41 fail(); 42 } catch (NoClassDefFoundError expected) { 43 } 44 } 45 46 public void testGetDeclaredMethodsFails() { 47 try { 48 loadableClass.getDeclaredMethods(); 49 fail(); 50 } catch (NoClassDefFoundError expected) { 51 } 52 } 53 54 public void testGetMethodFails() throws NoSuchMethodException { 55 try { 56 loadableClass.getDeclaredMethod("method", Unloadable.class); 57 fail(); 58 } catch (NoClassDefFoundError expected) { 59 } 60 } 61 62 public void testGetFieldFails() throws NoSuchFieldException { 63 try { 64 loadableClass.getDeclaredField("field"); 65 fail(); 66 } catch (NoClassDefFoundError expected) { 67 } 68 } 69 70 class Loadable { 71 Unloadable field; 72 void method(Unloadable unloadable) {} 73 } 74 75 class Unloadable {} 76} 77