EventObjectTest.java revision cc05ad238516f1303687aba4a978e24e57c0c07a
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 18package tests.api.java.util; 19 20import dalvik.annotation.TestTargetNew; 21import dalvik.annotation.TestTargets; 22import dalvik.annotation.TestLevel; 23import dalvik.annotation.TestTargetClass; 24 25import java.util.EventObject; 26 27@TestTargetClass(EventObject.class) 28public class EventObjectTest extends junit.framework.TestCase { 29 30 Object myObject; 31 32 EventObject myEventObject; 33 34 /** 35 * @tests java.util.EventObject#EventObject(java.lang.Object) 36 */ 37 @TestTargetNew( 38 level = TestLevel.COMPLETE, 39 notes = "See setUp method.", 40 method = "EventObject", 41 args = {java.lang.Object.class} 42 ) 43 public void test_ConstructorLjava_lang_Object() { 44 try { 45 new EventObject(null); 46 fail ("IllegalArgumentException expected"); 47 } catch (IllegalArgumentException e) { 48 //expected 49 } 50 } 51 52 /** 53 * @tests java.util.EventObject#getSource() 54 */ 55 @TestTargetNew( 56 level = TestLevel.COMPLETE, 57 notes = "", 58 method = "getSource", 59 args = {} 60 ) 61 public void test_getSource() { 62 // Test for method java.lang.Object java.util.EventObject.getSource() 63 assertTrue("Wrong source returned", 64 myEventObject.getSource() == myObject); 65 } 66 67 /** 68 * @tests java.util.EventObject#toString() 69 */ 70 @TestTargetNew( 71 level = TestLevel.COMPLETE, 72 notes = "", 73 method = "toString", 74 args = {} 75 ) 76 public void test_toString() { 77 // Test for method java.lang.String java.util.EventObject.toString() 78 assertTrue("Incorrect toString returned: " + myEventObject.toString(), 79 myEventObject.toString().indexOf( 80 "java.util.EventObject[source=java.lang.Object@") == 0); 81 } 82 83 /** 84 * Sets up the fixture, for example, open a network connection. This method 85 * is called before a test is executed. 86 */ 87 protected void setUp() { 88 myObject = new Object(); 89 myEventObject = new EventObject(myObject); 90 } 91 92 /** 93 * Tears down the fixture, for example, close a network connection. This 94 * method is called after a test is executed. 95 */ 96 protected void tearDown() { 97 } 98} 99