1 /* 2 * Licensed to the Apache Software Foundation (ASF) under one or more 3 * contributor license agreements. See the NOTICE file distributed with 4 * this work for additional information regarding copyright ownership. 5 * The ASF licenses this file to You under the Apache License, Version 2.0 6 * (the "License"); you may not use this file except in compliance with 7 * the License. You may obtain a copy of the License at 8 * 9 * http://www.apache.org/licenses/LICENSE-2.0 10 * 11 * Unless required by applicable law or agreed to in writing, software 12 * distributed under the License is distributed on an "AS IS" BASIS, 13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 * See the License for the specific language governing permissions and 15 * limitations under the License. 16 */ 17 18 package tests.api.javax.security.auth; 19 20 import dalvik.annotation.TestLevel; 21 import dalvik.annotation.TestTargetClass; 22 import dalvik.annotation.TestTargetNew; 23 import dalvik.annotation.TestTargets; 24 25 import junit.framework.TestCase; 26 27 import javax.security.auth.Destroyable; 28 import javax.security.auth.DestroyFailedException; 29 30 31 /** 32 * Tests for <code>Destroyable</code> class constructors and methods. 33 * 34 */ 35 @TestTargetClass(Destroyable.class) 36 public class DestroyableTest extends TestCase { 37 38 /** 39 * @tests javax.security.auth.Destroyable#destroy() 40 * @tests javax.security.auth.Destroyable#isDestroyed() 41 */ 42 @TestTargets({ 43 @TestTargetNew( 44 level = TestLevel.SUFFICIENT, 45 notes = "", 46 method = "destroy", 47 args = {} 48 ), 49 @TestTargetNew( 50 level = TestLevel.COMPLETE, 51 notes = "", 52 method = "isDestroyed", 53 args = {} 54 ) 55 }) 56 public void test_destroy() { 57 myDestroyable md = new myDestroyable(); 58 try { 59 assertFalse(md.isDestroyed()); 60 md.destroy(); 61 assertTrue(md.isDestroyed()); 62 } catch (Exception e) { 63 fail("Unexpected exception " + e); 64 } 65 } 66 67 private class myDestroyable implements Destroyable { 68 69 boolean destroyDone = false; 70 71 myDestroyable() { 72 } 73 74 public void destroy() throws DestroyFailedException { 75 destroyDone = true; 76 } 77 78 public boolean isDestroyed() { 79 return destroyDone; 80 } 81 } 82 } 83 84 85