1/* 2 * Copyright (C) 2008 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 android.content.res.cts; 18 19import android.content.res.Resources; 20import android.content.res.Resources.NotFoundException; 21import junit.framework.TestCase; 22 23public class Resources_NotFoundExceptionTest extends TestCase { 24 25 public void testNotFoundException() { 26 NotFoundException ne; 27 boolean wasThrown; 28 29 wasThrown = false; 30 ne = new NotFoundException(); 31 32 try { 33 throw ne; 34 } catch (NotFoundException e) { 35 // expected 36 assertSame(ne, e); 37 wasThrown = true; 38 } finally { 39 if (!wasThrown) { 40 fail("should throw out NotFoundException"); 41 } 42 } 43 44 final String MESSAGE = "test"; 45 wasThrown = false; 46 ne = new NotFoundException(MESSAGE); 47 48 try { 49 throw ne; 50 } catch (NotFoundException e) { 51 // expected 52 assertSame(ne, e); 53 assertEquals(MESSAGE, e.getMessage()); 54 wasThrown = true; 55 } finally { 56 if (!wasThrown) { 57 fail("should throw out NotFoundException"); 58 } 59 } 60 61 final Exception CAUSE = new NullPointerException(); 62 wasThrown = false; 63 ne = new NotFoundException(MESSAGE, CAUSE); 64 65 try { 66 throw ne; 67 } catch (NotFoundException e) { 68 // expected 69 assertSame(ne, e); 70 assertEquals(MESSAGE, e.getMessage()); 71 assertEquals(CAUSE, e.getCause()); 72 wasThrown = true; 73 } finally { 74 if (!wasThrown) { 75 fail("should throw out NotFoundException"); 76 } 77 } 78 } 79} 80