diff options
author | Elliott Hughes <enh@google.com> | 2013-04-26 12:11:19 -0700 |
---|---|---|
committer | Elliott Hughes <enh@google.com> | 2013-04-26 12:18:35 -0700 |
commit | d0d215d5a6cf237f829908b3921a630bbe46f0e4 (patch) | |
tree | e8f7037b2720573be5dbf8d4cb4f71e599ff9543 /harmony-tests | |
parent | 783feda93e8645aaf4d5a3b9cbbcd5eeb88b29d8 (diff) | |
download | libcore-d0d215d5a6cf237f829908b3921a630bbe46f0e4.zip libcore-d0d215d5a6cf237f829908b3921a630bbe46f0e4.tar.gz libcore-d0d215d5a6cf237f829908b3921a630bbe46f0e4.tar.bz2 |
Add the harmony annotation tests.
Change-Id: Ibbca52bae20e24e2d76d038d85e1ff5411ffc523
Diffstat (limited to 'harmony-tests')
5 files changed, 285 insertions, 0 deletions
diff --git a/harmony-tests/src/test/java/org/apache/harmony/annotation/tests/java/lang/annotation/AnnotationFormatErrorTest.java b/harmony-tests/src/test/java/org/apache/harmony/annotation/tests/java/lang/annotation/AnnotationFormatErrorTest.java new file mode 100644 index 0000000..b80f3a9 --- /dev/null +++ b/harmony-tests/src/test/java/org/apache/harmony/annotation/tests/java/lang/annotation/AnnotationFormatErrorTest.java @@ -0,0 +1,56 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.harmony.annotation.tests.java.lang.annotation; + +import java.lang.annotation.AnnotationFormatError; + +import junit.framework.TestCase; + +/** + * Test case of java.lang.annotation.AnnotationFormatError + */ +public class AnnotationFormatErrorTest extends TestCase { + /** + * @tests java.lang.annotation.AnnotationFormatError#AnnotationFormatError(String) + */ + @SuppressWarnings("nls") + public void test_constructorLjava_lang_String() { + AnnotationFormatError e = new AnnotationFormatError("some message"); + assertEquals("some message", e.getMessage()); + } + + /** + * @tests java.lang.annotation.AnnotationFormatError#AnnotationFormatError(Throwable) + */ + public void test_constructorLjava_lang_Throwable() { + IllegalArgumentException iae = new IllegalArgumentException(); + AnnotationFormatError e = new AnnotationFormatError(iae); + assertSame(iae, e.getCause()); + } + + /** + * @tests java.lang.annotation.AnnotationFormatError#AnnotationFormatError(String,Throwable) + */ + @SuppressWarnings("nls") + public void test_constructorLjava_lang_StringLjava_lang_Throwable() { + IllegalArgumentException iae = new IllegalArgumentException(); + AnnotationFormatError e = new AnnotationFormatError("some message", iae); + assertEquals("some message", e.getMessage()); + assertSame(iae, e.getCause()); + } +} diff --git a/harmony-tests/src/test/java/org/apache/harmony/annotation/tests/java/lang/annotation/AnnotationTypeMismatchExceptionTest.java b/harmony-tests/src/test/java/org/apache/harmony/annotation/tests/java/lang/annotation/AnnotationTypeMismatchExceptionTest.java new file mode 100644 index 0000000..37ee8c1 --- /dev/null +++ b/harmony-tests/src/test/java/org/apache/harmony/annotation/tests/java/lang/annotation/AnnotationTypeMismatchExceptionTest.java @@ -0,0 +1,46 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.harmony.annotation.tests.java.lang.annotation; + +import java.lang.annotation.AnnotationTypeMismatchException; +import java.lang.reflect.Method; + +import junit.framework.TestCase; + +/** + * Test case of java.lang.annotation.AnnotationTypeMismatchException + */ +public class AnnotationTypeMismatchExceptionTest extends TestCase { + + /** + * @throws ClassNotFoundException + * @throws SecurityException + * @tests java.lang.annotation.AnnotationTypeMismatchException#AnnotationTypeMismatchException(Method, + * String) + */ + @SuppressWarnings("nls") + public void test_constructorLjava_lang_reflect_MethodLjava_lang_String() throws SecurityException, ClassNotFoundException { + Method[] methods = Class.forName("java.lang.String").getMethods(); + Method m = methods[0]; + AnnotationTypeMismatchException e = new AnnotationTypeMismatchException( + m, "some type"); + assertNotNull("can not instantiate AnnotationTypeMismatchException", e); + assertSame("wrong method name", m, e.element()); + assertEquals("wrong found type", "some type", e.foundType()); + } +} diff --git a/harmony-tests/src/test/java/org/apache/harmony/annotation/tests/java/lang/annotation/ElementTypeTest.java b/harmony-tests/src/test/java/org/apache/harmony/annotation/tests/java/lang/annotation/ElementTypeTest.java new file mode 100644 index 0000000..d81cabd --- /dev/null +++ b/harmony-tests/src/test/java/org/apache/harmony/annotation/tests/java/lang/annotation/ElementTypeTest.java @@ -0,0 +1,65 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.harmony.annotation.tests.java.lang.annotation; + +import java.lang.annotation.ElementType; +import java.util.Arrays; + +import junit.framework.TestCase; + +/** + * Test case of java.lang.annotation.ElementType + */ +public class ElementTypeTest extends TestCase { + + /** + * @throws Exception + * @tests java.lang.annotation.ElementType#valueOf(String) + */ + @SuppressWarnings("nls") + public void test_valueOfLjava_lang_String() throws Exception { + assertSame(ElementType.ANNOTATION_TYPE, ElementType + .valueOf("ANNOTATION_TYPE")); + assertSame(ElementType.CONSTRUCTOR, ElementType.valueOf("CONSTRUCTOR")); + assertSame(ElementType.FIELD, ElementType.valueOf("FIELD")); + assertSame(ElementType.LOCAL_VARIABLE, ElementType + .valueOf("LOCAL_VARIABLE")); + assertSame(ElementType.METHOD, ElementType.valueOf("METHOD")); + assertSame(ElementType.PACKAGE, ElementType.valueOf("PACKAGE")); + assertSame(ElementType.PARAMETER, ElementType.valueOf("PARAMETER")); + assertSame(ElementType.TYPE, ElementType.valueOf("TYPE")); + try { + ElementType.valueOf("OTHER"); + fail("Should throw an IllegalArgumentException"); + } catch (IllegalArgumentException e) { + // expected + } + } + + /** + * @throws Exception + * @tests java.lang.annotation.ElementType#values() + */ + @SuppressWarnings("nls") + public void test_values() throws Exception { + ElementType[] values = ElementType.values(); + assertTrue(values.length > 1); + Arrays.sort(values); + assertTrue(Arrays.binarySearch(values, ElementType.METHOD) >= 0); + } +} diff --git a/harmony-tests/src/test/java/org/apache/harmony/annotation/tests/java/lang/annotation/IncompleteAnnotationExceptionTest.java b/harmony-tests/src/test/java/org/apache/harmony/annotation/tests/java/lang/annotation/IncompleteAnnotationExceptionTest.java new file mode 100644 index 0000000..d44b90a --- /dev/null +++ b/harmony-tests/src/test/java/org/apache/harmony/annotation/tests/java/lang/annotation/IncompleteAnnotationExceptionTest.java @@ -0,0 +1,58 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.harmony.annotation.tests.java.lang.annotation; + +import java.lang.annotation.IncompleteAnnotationException; + +import junit.framework.TestCase; + +/** + * + */ +public class IncompleteAnnotationExceptionTest extends TestCase { + + /* + * Class under test for void IncompleteAnnotationException(String) + * Regression for HARMONY-2477 + */ + public void testNullType() { + try { + new IncompleteAnnotationException(null, "str"); + fail("NullPointerException must be thrown"); + } catch (NullPointerException e) { + // Expected + } + } + + /** + * @throws Exception + * @tests java.lang.annotation.IncompleteAnnotationException#IncompleteAnnotationException(Class, + * String) + */ + @SuppressWarnings("nls") + public void test_constructorLjava_lang_Class_Ljava_lang_String() + throws Exception { + Class clazz = String.class; + String elementName = "some element"; + IncompleteAnnotationException e = new IncompleteAnnotationException( + clazz, elementName); + assertNotNull("can not instantiate IncompleteAnnotationException", e); + assertSame("wrong annotation type", clazz, e.annotationType()); + assertSame("wrong element name", elementName, e.elementName()); + } +} diff --git a/harmony-tests/src/test/java/org/apache/harmony/annotation/tests/java/lang/annotation/RetentionPolicyTest.java b/harmony-tests/src/test/java/org/apache/harmony/annotation/tests/java/lang/annotation/RetentionPolicyTest.java new file mode 100644 index 0000000..c4f7c03 --- /dev/null +++ b/harmony-tests/src/test/java/org/apache/harmony/annotation/tests/java/lang/annotation/RetentionPolicyTest.java @@ -0,0 +1,60 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.harmony.annotation.tests.java.lang.annotation; + +import java.lang.annotation.RetentionPolicy; +import java.util.Arrays; + +import junit.framework.TestCase; + +/** + * Test case of java.lang.annotation.RetentionPolicy + */ +public class RetentionPolicyTest extends TestCase { + /** + * @throws Exception + * @tests java.lang.annotation.RetentionPolicy#valueOf(String) + */ + @SuppressWarnings("nls") + public void test_valueOfLjava_lang_String() throws Exception { + assertSame(RetentionPolicy.CLASS, RetentionPolicy + .valueOf("CLASS")); + assertSame(RetentionPolicy.RUNTIME, RetentionPolicy + .valueOf("RUNTIME")); + assertSame(RetentionPolicy.SOURCE, RetentionPolicy + .valueOf("SOURCE")); + try { + RetentionPolicy.valueOf("OTHER"); + fail("Should throw an IllegalArgumentException"); + } catch (IllegalArgumentException e) { + // expected + } + } + + /** + * @throws Exception + * @tests java.lang.annotation.RetentionPolicy#values() + */ + @SuppressWarnings("nls") + public void test_values() throws Exception { + RetentionPolicy[] values = RetentionPolicy.values(); + assertTrue(values.length > 1); + Arrays.sort(values); + assertTrue(Arrays.binarySearch(values, RetentionPolicy.RUNTIME) >= 0); + } +} |