AssertionErrorTest.java revision 89c1feb0a69a7707b271086e749975b3f7acacf7
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, WITHOUT 13 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 14 * License for the specific language governing permissions and limitations under 15 * the License. 16 */ 17 18package org.apache.harmony.luni.tests.java.lang; 19 20import dalvik.annotation.TestInfo; 21import dalvik.annotation.TestLevel; 22import dalvik.annotation.TestTarget; 23import dalvik.annotation.TestTargetClass; 24 25import junit.framework.TestCase; 26 27@TestTargetClass(AssertionError.class) 28public class AssertionErrorTest extends TestCase { 29 30 @TestInfo( 31 level = TestLevel.COMPLETE, 32 purpose = "", 33 targets = { 34 @TestTarget( 35 methodName = "AssertionError", 36 methodArgs = {} 37 ) 38 }) 39 public void test_Constructor() { 40 AssertionError e = new AssertionError(); 41 assertNull(e.getMessage()); 42 assertNull(e.getCause()); 43 } 44 @TestInfo( 45 level = TestLevel.COMPLETE, 46 purpose = "", 47 targets = { 48 @TestTarget( 49 methodName = "AssertionError", 50 methodArgs = {java.lang.Object.class} 51 ) 52 }) 53 public void test_ConstructorObject() { 54 Object obj = "toString"; 55 AssertionError e = new AssertionError(obj); 56 assertEquals("toString", e.getMessage()); 57 assertNull(e.getCause()); 58 59 NullPointerException npe = new NullPointerException("null value"); 60 e = new AssertionError(npe); 61 assertEquals(npe.toString(), e.getMessage()); 62 assertSame(npe, e.getCause()); 63 } 64 @TestInfo( 65 level = TestLevel.COMPLETE, 66 purpose = "", 67 targets = { 68 @TestTarget( 69 methodName = "AssertionError", 70 methodArgs = {boolean.class} 71 ) 72 }) 73 public void test_ConstructorBoolean() { 74 AssertionError e = new AssertionError(true); 75 assertEquals("true", e.getMessage()); 76 assertNull(e.getCause()); 77 } 78 @TestInfo( 79 level = TestLevel.COMPLETE, 80 purpose = "", 81 targets = { 82 @TestTarget( 83 methodName = "AssertionError", 84 methodArgs = {char.class} 85 ) 86 }) 87 public void test_ConstructorChar() { 88 AssertionError e = new AssertionError('a'); 89 assertEquals("a", e.getMessage()); 90 assertNull(e.getCause()); 91 } 92 @TestInfo( 93 level = TestLevel.COMPLETE, 94 purpose = "", 95 targets = { 96 @TestTarget( 97 methodName = "AssertionError", 98 methodArgs = {int.class} 99 ) 100 }) 101 public void test_ConstructorInt() { 102 AssertionError e = new AssertionError(1); 103 assertEquals("1", e.getMessage()); 104 assertNull(e.getCause()); 105 } 106 @TestInfo( 107 level = TestLevel.COMPLETE, 108 purpose = "", 109 targets = { 110 @TestTarget( 111 methodName = "AssertionError", 112 methodArgs = {long.class} 113 ) 114 }) 115 public void test_ConstructorLong() { 116 AssertionError e = new AssertionError(1L); 117 assertEquals("1", e.getMessage()); 118 assertNull(e.getCause()); 119 } 120 @TestInfo( 121 level = TestLevel.COMPLETE, 122 purpose = "", 123 targets = { 124 @TestTarget( 125 methodName = "AssertionError", 126 methodArgs = {float.class} 127 ) 128 }) 129 public void test_ConstructorFloat() { 130 AssertionError e = new AssertionError(1.0F); 131 assertEquals("1.0", e.getMessage()); 132 assertNull(e.getCause()); 133 } 134 @TestInfo( 135 level = TestLevel.COMPLETE, 136 purpose = "", 137 targets = { 138 @TestTarget( 139 methodName = "AssertionError", 140 methodArgs = {double.class} 141 ) 142 }) 143 public void test_ConstructorDouble() { 144 AssertionError e = new AssertionError(1.0D); 145 assertEquals("1.0", e.getMessage()); 146 assertNull(e.getCause()); 147 } 148 149} 150