ModifierTest.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.lang.reflect; 19 20import dalvik.annotation.TestTargets; 21import dalvik.annotation.TestLevel; 22import dalvik.annotation.TestTargetNew; 23import dalvik.annotation.TestTargetClass; 24 25import java.lang.reflect.Modifier; 26 27@TestTargetClass(Modifier.class) 28public class ModifierTest extends junit.framework.TestCase { 29 30 private static final int ALL_FLAGS = 0x7FF; 31 32 /** 33 * @tests java.lang.reflect.Modifier#Modifier() 34 */ 35 @TestTargetNew( 36 level = TestLevel.COMPLETE, 37 notes = "The only thing I can do", 38 method = "Modifier", 39 args = {} 40 ) 41 public void test_Constructor() { 42 assertNotNull(new Modifier()); 43 } 44 45 /** 46 * @tests java.lang.reflect.Modifier#isAbstract(int) 47 */ 48 @TestTargetNew( 49 level = TestLevel.COMPLETE, 50 notes = "", 51 method = "isAbstract", 52 args = {int.class} 53 ) 54 public void test_isAbstractI() { 55 // Test for method boolean java.lang.reflect.Modifier.isAbstract(int) 56 assertTrue("ABSTRACT returned false", Modifier.isAbstract(ALL_FLAGS)); 57 assertTrue("ABSTRACT returned false", Modifier 58 .isAbstract(Modifier.ABSTRACT)); 59 assertTrue("Non-ABSTRACT returned true", !Modifier 60 .isAbstract(Modifier.TRANSIENT)); 61 } 62 63 /** 64 * @tests java.lang.reflect.Modifier#isFinal(int) 65 */ 66 @TestTargetNew( 67 level = TestLevel.COMPLETE, 68 notes = "", 69 method = "isFinal", 70 args = {int.class} 71 ) 72 public void test_isFinalI() { 73 // Test for method boolean java.lang.reflect.Modifier.isFinal(int) 74 assertTrue("FINAL returned false", Modifier.isFinal(ALL_FLAGS)); 75 assertTrue("FINAL returned false", Modifier.isFinal(Modifier.FINAL)); 76 assertTrue("Non-FINAL returned true", !Modifier 77 .isFinal(Modifier.TRANSIENT)); 78 } 79 80 /** 81 * @tests java.lang.reflect.Modifier#isInterface(int) 82 */ 83 @TestTargetNew( 84 level = TestLevel.COMPLETE, 85 notes = "", 86 method = "isInterface", 87 args = {int.class} 88 ) 89 public void test_isInterfaceI() { 90 // Test for method boolean java.lang.reflect.Modifier.isInterface(int) 91 assertTrue("INTERFACE returned false", Modifier.isInterface(ALL_FLAGS)); 92 assertTrue("INTERFACE returned false", Modifier 93 .isInterface(Modifier.INTERFACE)); 94 assertTrue("Non-INTERFACE returned true", !Modifier 95 .isInterface(Modifier.TRANSIENT)); 96 } 97 98 /** 99 * @tests java.lang.reflect.Modifier#isNative(int) 100 */ 101 @TestTargetNew( 102 level = TestLevel.COMPLETE, 103 notes = "", 104 method = "isNative", 105 args = {int.class} 106 ) 107 public void test_isNativeI() { 108 // Test for method boolean java.lang.reflect.Modifier.isNative(int) 109 assertTrue("NATIVE returned false", Modifier.isNative(ALL_FLAGS)); 110 assertTrue("NATIVE returned false", Modifier.isNative(Modifier.NATIVE)); 111 assertTrue("Non-NATIVE returned true", !Modifier 112 .isNative(Modifier.TRANSIENT)); 113 } 114 115 /** 116 * @tests java.lang.reflect.Modifier#isPrivate(int) 117 */ 118 @TestTargetNew( 119 level = TestLevel.COMPLETE, 120 notes = "", 121 method = "isPrivate", 122 args = {int.class} 123 ) 124 public void test_isPrivateI() { 125 // Test for method boolean java.lang.reflect.Modifier.isPrivate(int) 126 assertTrue("PRIVATE returned false", Modifier.isPrivate(ALL_FLAGS)); 127 assertTrue("PRIVATE returned false", Modifier 128 .isPrivate(Modifier.PRIVATE)); 129 assertTrue("Non-PRIVATE returned true", !Modifier 130 .isPrivate(Modifier.TRANSIENT)); 131 } 132 133 /** 134 * @tests java.lang.reflect.Modifier#isProtected(int) 135 */ 136 @TestTargetNew( 137 level = TestLevel.COMPLETE, 138 notes = "", 139 method = "isProtected", 140 args = {int.class} 141 ) 142 public void test_isProtectedI() { 143 // Test for method boolean java.lang.reflect.Modifier.isProtected(int) 144 assertTrue("PROTECTED returned false", Modifier.isProtected(ALL_FLAGS)); 145 assertTrue("PROTECTED returned false", Modifier 146 .isProtected(Modifier.PROTECTED)); 147 assertTrue("Non-PROTECTED returned true", !Modifier 148 .isProtected(Modifier.TRANSIENT)); 149 } 150 151 /** 152 * @tests java.lang.reflect.Modifier#isPublic(int) 153 */ 154 @TestTargetNew( 155 level = TestLevel.COMPLETE, 156 notes = "", 157 method = "isPublic", 158 args = {int.class} 159 ) 160 public void test_isPublicI() { 161 // Test for method boolean java.lang.reflect.Modifier.isPublic(int) 162 assertTrue("PUBLIC returned false", Modifier.isPublic(ALL_FLAGS)); 163 assertTrue("PUBLIC returned false", Modifier.isPublic(Modifier.PUBLIC)); 164 assertTrue("Non-PUBLIC returned true", !Modifier 165 .isPublic(Modifier.TRANSIENT)); 166 } 167 168 /** 169 * @tests java.lang.reflect.Modifier#isStatic(int) 170 */ 171 @TestTargetNew( 172 level = TestLevel.COMPLETE, 173 notes = "", 174 method = "isStatic", 175 args = {int.class} 176 ) 177 public void test_isStaticI() { 178 // Test for method boolean java.lang.reflect.Modifier.isStatic(int) 179 assertTrue("STATIC returned false", Modifier.isStatic(ALL_FLAGS)); 180 assertTrue("STATIC returned false", Modifier.isStatic(Modifier.STATIC)); 181 assertTrue("Non-STATIC returned true", !Modifier 182 .isStatic(Modifier.TRANSIENT)); 183 } 184 185 /** 186 * @tests java.lang.reflect.Modifier#isStrict(int) 187 */ 188 @TestTargetNew( 189 level = TestLevel.COMPLETE, 190 notes = "", 191 method = "isStrict", 192 args = {int.class} 193 ) 194 public void test_isStrictI() { 195 // Test for method boolean java.lang.reflect.Modifier.isStrict(int) 196 assertTrue("STRICT returned false", Modifier.isStrict(Modifier.STRICT)); 197 assertTrue("Non-STRICT returned true", !Modifier 198 .isStrict(Modifier.TRANSIENT)); 199 } 200 201 /** 202 * @tests java.lang.reflect.Modifier#isSynchronized(int) 203 */ 204 @TestTargetNew( 205 level = TestLevel.COMPLETE, 206 notes = "", 207 method = "isSynchronized", 208 args = {int.class} 209 ) 210 public void test_isSynchronizedI() { 211 // Test for method boolean 212 // java.lang.reflect.Modifier.isSynchronized(int) 213 assertTrue("Synchronized returned false", Modifier 214 .isSynchronized(ALL_FLAGS)); 215 assertTrue("Non-Synchronized returned true", !Modifier 216 .isSynchronized(Modifier.VOLATILE)); 217 } 218 219 /** 220 * @tests java.lang.reflect.Modifier#isTransient(int) 221 */ 222 @TestTargetNew( 223 level = TestLevel.COMPLETE, 224 notes = "", 225 method = "isTransient", 226 args = {int.class} 227 ) 228 public void test_isTransientI() { 229 // Test for method boolean java.lang.reflect.Modifier.isTransient(int) 230 assertTrue("Transient returned false", Modifier.isTransient(ALL_FLAGS)); 231 assertTrue("Transient returned false", Modifier 232 .isTransient(Modifier.TRANSIENT)); 233 assertTrue("Non-Transient returned true", !Modifier 234 .isTransient(Modifier.VOLATILE)); 235 } 236 237 /** 238 * @tests java.lang.reflect.Modifier#isVolatile(int) 239 */ 240 @TestTargetNew( 241 level = TestLevel.COMPLETE, 242 notes = "", 243 method = "isVolatile", 244 args = {int.class} 245 ) 246 public void test_isVolatileI() { 247 // Test for method boolean java.lang.reflect.Modifier.isVolatile(int) 248 assertTrue("Volatile returned false", Modifier.isVolatile(ALL_FLAGS)); 249 assertTrue("Volatile returned false", Modifier 250 .isVolatile(Modifier.VOLATILE)); 251 assertTrue("Non-Volatile returned true", !Modifier 252 .isVolatile(Modifier.TRANSIENT)); 253 } 254 255 /** 256 * @tests java.lang.reflect.Modifier#toString(int) 257 */ 258 @TestTargetNew( 259 level = TestLevel.COMPLETE, 260 notes = "", 261 method = "toString", 262 args = {int.class} 263 ) 264 public void test_toStringI() { 265 // Test for method java.lang.String 266 // java.lang.reflect.Modifier.toString(int) 267 assertTrue("Returned incorrect string value: " 268 + Modifier.toString(java.lang.reflect.Modifier.PUBLIC 269 + java.lang.reflect.Modifier.ABSTRACT), Modifier 270 .toString( 271 java.lang.reflect.Modifier.PUBLIC 272 + java.lang.reflect.Modifier.ABSTRACT).equals( 273 "public abstract")); 274 } 275 276 /** 277 * Sets up the fixture, for example, open a network connection. This method 278 * is called before a test is executed. 279 */ 280 protected void setUp() { 281 } 282 283 /** 284 * Tears down the fixture, for example, close a network connection. This 285 * method is called after a test is executed. 286 */ 287 protected void tearDown() { 288 } 289} 290