You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@poi.apache.org by on...@apache.org on 2016/08/15 07:27:03 UTC
svn commit: r1756356 - in /poi/trunk/src/testcases/org/apache/poi:
POITestCase.java TestPOITestCase.java
Author: onealj
Date: Mon Aug 15 07:27:03 2016
New Revision: 1756356
URL: http://svn.apache.org/viewvc?rev=1756356&view=rev
Log:
add (meta) unit test for POITestCase
Added:
poi/trunk/src/testcases/org/apache/poi/TestPOITestCase.java
- copied, changed from r1756350, poi/trunk/src/testcases/org/apache/poi/POITestCase.java
Modified:
poi/trunk/src/testcases/org/apache/poi/POITestCase.java
Modified: poi/trunk/src/testcases/org/apache/poi/POITestCase.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/testcases/org/apache/poi/POITestCase.java?rev=1756356&r1=1756355&r2=1756356&view=diff
==============================================================================
--- poi/trunk/src/testcases/org/apache/poi/POITestCase.java (original)
+++ poi/trunk/src/testcases/org/apache/poi/POITestCase.java Mon Aug 15 07:27:03 2016
@@ -32,13 +32,16 @@ import java.security.PrivilegedActionExc
import java.security.PrivilegedExceptionAction;
import java.util.ArrayList;
import java.util.List;
+import java.util.Locale;
import java.util.Map;
import org.apache.poi.util.SuppressForbidden;
+import org.apache.poi.util.Internal;
/**
* Util class for POI JUnit TestCases, which provide additional features
*/
+@Internal
public final class POITestCase {
public static void assertContains(String haystack, String needle) {
assertNotNull(haystack);
@@ -47,6 +50,19 @@ public final class POITestCase {
haystack.contains(needle)
);
}
+
+ public static void assertContainsIgnoreCase(String haystack, String needle, Locale locale) {
+ assertNotNull(haystack);
+ assertNotNull(needle);
+ String hay = haystack.toLowerCase(locale);
+ String n = needle.toLowerCase(locale);
+ assertTrue("Unable to find expected text '" + needle + "' in text:\n" + haystack,
+ hay.contains(n)
+ );
+ }
+ public static void assertContainsIgnoreCase(String haystack, String needle) {
+ assertContainsIgnoreCase(haystack, needle, Locale.ROOT);
+ }
public static void assertNotContained(String haystack, String needle) {
assertNotNull(haystack);
Copied: poi/trunk/src/testcases/org/apache/poi/TestPOITestCase.java (from r1756350, poi/trunk/src/testcases/org/apache/poi/POITestCase.java)
URL: http://svn.apache.org/viewvc/poi/trunk/src/testcases/org/apache/poi/TestPOITestCase.java?p2=poi/trunk/src/testcases/org/apache/poi/TestPOITestCase.java&p1=poi/trunk/src/testcases/org/apache/poi/POITestCase.java&r1=1756350&r2=1756356&rev=1756356&view=diff
==============================================================================
--- poi/trunk/src/testcases/org/apache/poi/POITestCase.java (original)
+++ poi/trunk/src/testcases/org/apache/poi/TestPOITestCase.java Mon Aug 15 07:27:03 2016
@@ -17,145 +17,110 @@
package org.apache.poi;
-import static org.junit.Assert.assertArrayEquals;
import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
-import java.lang.reflect.AccessibleObject;
-import java.lang.reflect.Field;
-import java.lang.reflect.Method;
-import java.security.AccessController;
-import java.security.PrivilegedActionException;
-import java.security.PrivilegedExceptionAction;
-import java.util.ArrayList;
-import java.util.List;
+import java.util.Collections;
+import java.util.Locale;
import java.util.Map;
-import org.apache.poi.util.SuppressForbidden;
+import org.apache.poi.POITestCase;
+import org.junit.Ignore;
+import org.junit.Test;
/**
- * Util class for POI JUnit TestCases, which provide additional features
+ * A class for testing the POI Junit TestCase utility class
*/
-public final class POITestCase {
- public static void assertContains(String haystack, String needle) {
- assertNotNull(haystack);
- assertTrue(
- "Unable to find expected text '" + needle + "' in text:\n" + haystack,
- haystack.contains(needle)
- );
- }
-
- public static void assertNotContained(String haystack, String needle) {
- assertNotNull(haystack);
- assertFalse(
- "Unexpectedly found text '" + needle + "' in text:\n" + haystack,
- haystack.contains(needle)
- );
- }
-
- /**
- * @param map haystack
- * @param key needle
- */
- public static <T> void assertContains(Map<T, ?> map, T key) {
- if (map.containsKey(key)) {
- return;
- }
- fail("Unable to find " + key + " in " + map);
+public final class TestPOITestCase {
+ @Test
+ public void assertContains() {
+ POITestCase.assertContains("There is a needle in this haystack", "needle");
+ /*try {
+ POITestCase.assertContains("There is gold in this haystack", "needle");
+ fail("found a needle");
+ } catch (final junit.framework.AssertionFailedError e) {
+ // expected
+ }*/
+ }
+
+ @Test
+ public void assertContainsIgnoreCase_Locale() {
+ POITestCase.assertContainsIgnoreCase("There is a Needle in this haystack", "needlE", Locale.ROOT);
+ // FIXME: test failing case
+ }
+
+ @Test
+ public void assertContainsIgnoreCase() {
+ POITestCase.assertContainsIgnoreCase("There is a Needle in this haystack", "needlE");
+ // FIXME: test failing case
+ }
+
+ @Test
+ public void assertNotContained() {
+ POITestCase.assertNotContained("There is a needle in this haystack", "gold");
+ // FIXME: test failing case
+ }
+
+ @Test
+ public void assertMapContains() {
+ Map<String, String> haystack = Collections.singletonMap("needle", "value");
+ POITestCase.assertContains(haystack, "needle");
+ // FIXME: test failing case
}
+
/**
* Utility method to get the value of a private/protected field.
* Only use this method in test cases!!!
*/
- public static <R,T> R getFieldValue(final Class<? super T> clazz, final T instance, final Class<R> fieldType, final String fieldName) {
- assertTrue("Reflection of private fields is only allowed for POI classes.", clazz.getName().startsWith("org.apache.poi."));
- try {
- return AccessController.doPrivileged(new PrivilegedExceptionAction<R>() {
- @Override
- @SuppressWarnings("unchecked")
- @SuppressForbidden("For test usage only")
- public R run() throws Exception {
- Field f = clazz.getDeclaredField(fieldName);
- f.setAccessible(true);
- return (R) f.get(instance);
- }
- });
- } catch (PrivilegedActionException pae) {
- throw new RuntimeException("Cannot access field '" + fieldName + "' of class " + clazz, pae.getException());
- }
+ @Ignore
+ @Test
+ public void getFieldValue() {
+ /*
+ final Class<? super T> clazz;
+ final T instance;
+ final Class<R> fieldType;
+ final String fieldName;
+
+ final R expected;
+ final R actual = POITestCase.getFieldValue(clazz, instance, fieldType, fieldName);
+ assertEquals(expected, actual);
+ */
}
/**
* Utility method to call a private/protected method.
* Only use this method in test cases!!!
*/
- public static <R,T> R callMethod(final Class<? super T> clazz, final T instance, final Class<R> returnType, final String methodName,
- final Class<?>[] parameterTypes, final Object[] parameters) {
- assertTrue("Reflection of private methods is only allowed for POI classes.", clazz.getName().startsWith("org.apache.poi."));
- try {
- return AccessController.doPrivileged(new PrivilegedExceptionAction<R>() {
- @Override
- @SuppressWarnings("unchecked")
- @SuppressForbidden("For test usage only")
- public R run() throws Exception {
- Method m = clazz.getDeclaredMethod(methodName, parameterTypes);
- m.setAccessible(true);
- return (R) m.invoke(instance, parameters);
- }
- });
- } catch (PrivilegedActionException pae) {
- throw new RuntimeException("Cannot access method '" + methodName + "' of class " + clazz, pae.getException());
- }
+ @Ignore
+ @Test
+ public void callMethod() {
+ /*
+ final Class<? super T> clazz;
+ final T instance;
+ final Class<R> returnType;
+ final String methodName;
+ final Class<?>[] parameterTypes;
+ final Object[] parameters;
+
+ final R expected;
+ final R actual = POITestCase.callMethod(clazz, instance, returnType, methodName, parameterTypes, parameters);
+ assertEquals(expected, actual);
+ */
}
/**
* Utility method to shallow compare all fields of the objects
* Only use this method in test cases!!!
*/
- public static void assertReflectEquals(final Object expected, Object actual) throws Exception {
- final List<Field> fields;
- try {
- fields = AccessController.doPrivileged(new PrivilegedExceptionAction<List<Field>>() {
- @Override
- @SuppressForbidden("Test only")
- public List<Field> run() throws Exception {
- List<Field> flds = new ArrayList<Field>();
- for (Class<?> c = expected.getClass(); c != null; c = c.getSuperclass()) {
- Field[] fs = c.getDeclaredFields();
- AccessibleObject.setAccessible(fs, true);
- for (Field f : fs) {
- // JaCoCo Code Coverage adds it's own field, don't look at this one here
- if(f.getName().equals("$jacocoData")) {
- continue;
- }
-
- flds.add(f);
- }
- }
- return flds;
- }
- });
- } catch (PrivilegedActionException pae) {
- throw pae.getException();
- }
-
- for (Field f : fields) {
- Class<?> t = f.getType();
- if (t.isArray()) {
- if (Object[].class.isAssignableFrom(t)) {
- assertArrayEquals((Object[])f.get(expected), (Object[])f.get(actual));
- } else if (byte[].class.isAssignableFrom(t)) {
- assertArrayEquals((byte[])f.get(expected), (byte[])f.get(actual));
- } else {
- fail("Array type is not yet implemented ... add it!");
- }
- } else {
- assertEquals(f.get(expected), f.get(actual));
- }
- }
+ @Ignore
+ @Test
+ public void assertReflectEquals() throws Exception {
+ /*
+ final Object expected;
+ final Object actual;
+ POITestCase.assertReflectEquals(expected, actual);
+ */
}
}
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@poi.apache.org
For additional commands, e-mail: commits-help@poi.apache.org