Author: britter
Date: Thu Oct 2 10:12:12 2014
New Revision: 1628922
URL: http://svn.apache.org/r1628922
Log:
LANG-1041: Fix MethodUtilsTest so it does not depend on JDK method ordering.
This fixes #30 from github. Thanks to Alexandre Bartel.
Modified:
commons/proper/lang/trunk/pom.xml
commons/proper/lang/trunk/src/changes/changes.xml
commons/proper/lang/trunk/src/test/java/org/apache/commons/lang3/reflect/MethodUtilsTest.java
Modified: commons/proper/lang/trunk/pom.xml
URL:
http://svn.apache.org/viewvc/commons/proper/lang/trunk/pom.xml?rev=1628922&r1=1628921&r2=1628922&view=diff
==============================================================================
--- commons/proper/lang/trunk/pom.xml (original)
+++ commons/proper/lang/trunk/pom.xml Thu Oct 2 10:12:12 2014
@@ -473,6 +473,12 @@
<version>4.11</version>
<scope>test</scope>
</dependency>
+ <dependency>
+ <groupId>org.hamcrest</groupId>
+ <artifactId>hamcrest-all</artifactId>
+ <version>1.3</version>
+ <scope>test</scope>
+ </dependency>
<dependency>
<groupId>commons-io</groupId>
Modified: commons/proper/lang/trunk/src/changes/changes.xml
URL:
http://svn.apache.org/viewvc/commons/proper/lang/trunk/src/changes/changes.xml?rev=1628922&r1=1628921&r2=1628922&view=diff
==============================================================================
--- commons/proper/lang/trunk/src/changes/changes.xml [utf-8] (original)
+++ commons/proper/lang/trunk/src/changes/changes.xml [utf-8] Thu Oct 2
10:12:12 2014
@@ -22,6 +22,7 @@
<body>
<release version="3.4" date="tba" description="tba">
+ <action issue="LANG-1041" type="fix" dev="britter" due-to="Alexandre
Bartel">Fix MethodUtilsTest so it does not depend on JDK method
ordering</action>
<action issue="LANG-827" type="update" dev="djones">CompareToBuilder's doc
doesn't specify precedence of fields it uses in performing comparisons</action>
<action issue="LANG-1000" type="fix" dev="djones">ParseException when
trying to parse UTC dates with Z as zone designator using
DateFormatUtils.ISO_DATETIME_TIME_ZONE_FORMAT</action>
<action issue="LANG-1035" type="fix" dev="djones">Javadoc for
EqualsBuilder.reflectionEquals() is unclear</action>
Modified:
commons/proper/lang/trunk/src/test/java/org/apache/commons/lang3/reflect/MethodUtilsTest.java
URL:
http://svn.apache.org/viewvc/commons/proper/lang/trunk/src/test/java/org/apache/commons/lang3/reflect/MethodUtilsTest.java?rev=1628922&r1=1628921&r2=1628922&view=diff
==============================================================================
---
commons/proper/lang/trunk/src/test/java/org/apache/commons/lang3/reflect/MethodUtilsTest.java
(original)
+++
commons/proper/lang/trunk/src/test/java/org/apache/commons/lang3/reflect/MethodUtilsTest.java
Thu Oct 2 10:12:12 2014
@@ -16,6 +16,8 @@
*/
package org.apache.commons.lang3.reflect;
+import static org.hamcrest.Matchers.hasItemInArray;
+import static org.hamcrest.Matchers.hasItems;
import static org.junit.Assert.assertArrayEquals;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
@@ -23,6 +25,7 @@ import static org.junit.Assert.assertNot
import static org.junit.Assert.assertNotSame;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertSame;
+import static org.junit.Assert.assertThat;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
@@ -432,11 +435,11 @@ public class MethodUtilsTest {
@Annotated
public void testGetMethodsWithAnnotation() throws NoSuchMethodException {
assertArrayEquals(new Method[0],
MethodUtils.getMethodsWithAnnotation(Object.class, Annotated.class));
- final Method[] annotatedMethods = new Method[]{
-
MethodUtilsTest.class.getMethod("testGetMethodsWithAnnotation"),
-
MethodUtilsTest.class.getMethod("testGetMethodsListWithAnnotation")
- };
- assertArrayEquals(annotatedMethods,
MethodUtils.getMethodsWithAnnotation(MethodUtilsTest.class, Annotated.class));
+
+ Method[] methodsWithAnnotation =
MethodUtils.getMethodsWithAnnotation(MethodUtilsTest.class, Annotated.class);
+ assertEquals(2, methodsWithAnnotation.length);
+ assertThat(methodsWithAnnotation,
hasItemInArray(MethodUtilsTest.class.getMethod("testGetMethodsWithAnnotation")));
+ assertThat(methodsWithAnnotation,
hasItemInArray(MethodUtilsTest.class.getMethod("testGetMethodsListWithAnnotation")));
}
@Test(expected = IllegalArgumentException.class)
@@ -458,14 +461,13 @@ public class MethodUtilsTest {
@Annotated
public void testGetMethodsListWithAnnotation() throws
NoSuchMethodException {
assertEquals(0, MethodUtils.getMethodsListWithAnnotation(Object.class,
Annotated.class).size());
- final List<Method> annotatedMethods = Arrays.asList(
+
+ final List<Method> methodWithAnnotation =
MethodUtils.getMethodsListWithAnnotation(MethodUtilsTest.class,
Annotated.class);
+ assertEquals(2, methodWithAnnotation.size());
+ assertThat(methodWithAnnotation, hasItems(
MethodUtilsTest.class.getMethod("testGetMethodsWithAnnotation"),
MethodUtilsTest.class.getMethod("testGetMethodsListWithAnnotation")
- );
- final List<Method> methodUtilsTestAnnotatedFields =
MethodUtils.getMethodsListWithAnnotation(MethodUtilsTest.class,
Annotated.class);
- assertEquals(annotatedMethods.size(),
methodUtilsTestAnnotatedFields.size());
-
assertTrue(methodUtilsTestAnnotatedFields.contains(annotatedMethods.get(0)));
-
assertTrue(methodUtilsTestAnnotatedFields.contains(annotatedMethods.get(1)));
+ ));
}
@Test(expected = IllegalArgumentException.class)