summaryrefslogtreecommitdiffstats
path: root/annotation/src/test/java
diff options
context:
space:
mode:
authorThe Android Open Source Project <initial-contribution@android.com>2008-10-21 07:00:00 -0700
committerThe Android Open Source Project <initial-contribution@android.com>2008-10-21 07:00:00 -0700
commitfdb2704414a9ed92394ada0d1395e4db86889465 (patch)
tree9b591a4a50054274a197f02b3ccb51313681879f /annotation/src/test/java
downloadlibcore-fdb2704414a9ed92394ada0d1395e4db86889465.zip
libcore-fdb2704414a9ed92394ada0d1395e4db86889465.tar.gz
libcore-fdb2704414a9ed92394ada0d1395e4db86889465.tar.bz2
Initial Contribution
Diffstat (limited to 'annotation/src/test/java')
-rw-r--r--annotation/src/test/java/org/apache/harmony/annotation/tests/java/lang/annotation/AllTests.java42
-rw-r--r--annotation/src/test/java/org/apache/harmony/annotation/tests/java/lang/annotation/AnnotationFormatErrorTest.java56
-rw-r--r--annotation/src/test/java/org/apache/harmony/annotation/tests/java/lang/annotation/AnnotationTypeMismatchExceptionTest.java46
-rw-r--r--annotation/src/test/java/org/apache/harmony/annotation/tests/java/lang/annotation/ElementTypeTest.java65
-rw-r--r--annotation/src/test/java/org/apache/harmony/annotation/tests/java/lang/annotation/IncompleteAnnotationExceptionTest.java58
-rw-r--r--annotation/src/test/java/org/apache/harmony/annotation/tests/java/lang/annotation/RetentionPolicyTest.java60
-rw-r--r--annotation/src/test/java/tests/annotation/AllTests.java38
7 files changed, 365 insertions, 0 deletions
diff --git a/annotation/src/test/java/org/apache/harmony/annotation/tests/java/lang/annotation/AllTests.java b/annotation/src/test/java/org/apache/harmony/annotation/tests/java/lang/annotation/AllTests.java
new file mode 100644
index 0000000..6662037
--- /dev/null
+++ b/annotation/src/test/java/org/apache/harmony/annotation/tests/java/lang/annotation/AllTests.java
@@ -0,0 +1,42 @@
+/* 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 org.apache.harmony.nio_char.tests.java.nio.charset.ASCIICharsetEncoderTest;
+
+import junit.framework.Test;
+import junit.framework.TestSuite;
+
+/**
+ * Test suite for java.nio.charset package.
+ */
+public class AllTests {
+
+ public static Test suite() {
+ TestSuite suite = new TestSuite("Test for java.lang.annotation");
+ // $JUnit-BEGIN$
+
+ suite.addTestSuite(AnnotationFormatErrorTest.class);
+ suite.addTestSuite(AnnotationTypeMismatchExceptionTest.class);
+ suite.addTestSuite(ElementTypeTest.class);
+ suite.addTestSuite(IncompleteAnnotationExceptionTest.class);
+ suite.addTestSuite(RetentionPolicyTest.class);
+
+ // $JUnit-END$
+ return suite;
+ }
+}
diff --git a/annotation/src/test/java/org/apache/harmony/annotation/tests/java/lang/annotation/AnnotationFormatErrorTest.java b/annotation/src/test/java/org/apache/harmony/annotation/tests/java/lang/annotation/AnnotationFormatErrorTest.java
new file mode 100644
index 0000000..b80f3a9
--- /dev/null
+++ b/annotation/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/annotation/src/test/java/org/apache/harmony/annotation/tests/java/lang/annotation/AnnotationTypeMismatchExceptionTest.java b/annotation/src/test/java/org/apache/harmony/annotation/tests/java/lang/annotation/AnnotationTypeMismatchExceptionTest.java
new file mode 100644
index 0000000..9948e29
--- /dev/null
+++ b/annotation/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 instanciate AnnotationTypeMismatchException", e);
+ assertSame("wrong method name", m, e.element());
+ assertEquals("wrong found type", "some type", e.foundType());
+ }
+}
diff --git a/annotation/src/test/java/org/apache/harmony/annotation/tests/java/lang/annotation/ElementTypeTest.java b/annotation/src/test/java/org/apache/harmony/annotation/tests/java/lang/annotation/ElementTypeTest.java
new file mode 100644
index 0000000..d81cabd
--- /dev/null
+++ b/annotation/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/annotation/src/test/java/org/apache/harmony/annotation/tests/java/lang/annotation/IncompleteAnnotationExceptionTest.java b/annotation/src/test/java/org/apache/harmony/annotation/tests/java/lang/annotation/IncompleteAnnotationExceptionTest.java
new file mode 100644
index 0000000..0acd4fa
--- /dev/null
+++ b/annotation/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 instanciate IncompleteAnnotationException", e);
+ assertSame("wrong annotation type", clazz, e.annotationType());
+ assertSame("wrong element name", elementName, e.elementName());
+ }
+}
diff --git a/annotation/src/test/java/org/apache/harmony/annotation/tests/java/lang/annotation/RetentionPolicyTest.java b/annotation/src/test/java/org/apache/harmony/annotation/tests/java/lang/annotation/RetentionPolicyTest.java
new file mode 100644
index 0000000..c4f7c03
--- /dev/null
+++ b/annotation/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);
+ }
+}
diff --git a/annotation/src/test/java/tests/annotation/AllTests.java b/annotation/src/test/java/tests/annotation/AllTests.java
new file mode 100644
index 0000000..84b1b40
--- /dev/null
+++ b/annotation/src/test/java/tests/annotation/AllTests.java
@@ -0,0 +1,38 @@
+/* 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 tests.annotation;
+
+import junit.framework.Test;
+import junit.framework.TestSuite;
+
+/**
+ * Test suite that includes all tests for the NIO_Char project.
+ */
+public class AllTests {
+
+ public static void main(String[] args) {
+ junit.textui.TestRunner.run(AllTests.suite());
+ }
+
+ public static Test suite() {
+ TestSuite suite = new TestSuite("All Annotation test suites");
+ // $JUnit-BEGIN$
+ suite.addTest(org.apache.harmony.annotation.tests.java.lang.annotation.AllTests.suite());
+ // $JUnit-END$
+ return suite;
+ }
+}