You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@tapestry.apache.org by hl...@apache.org on 2011/04/01 04:18:04 UTC
svn commit: r1087557 - in /tapestry/tapestry5/trunk: tapestry-ioc/
tapestry-ioc/src/main/java/org/apache/tapestry5/ioc/services/
tapestry-ioc/src/main/java/org/apache/tapestry5/ioc/test/
tapestry-ioc/src/test/java/org/apache/tapestry5/ioc/internal/serv...
Author: hlship
Date: Fri Apr 1 02:18:03 2011
New Revision: 1087557
URL: http://svn.apache.org/viewvc?rev=1087557&view=rev
Log:
TAP5-1362: Tapestry should provide coercions from String to JSONObject and JSONArray
Added:
tapestry/tapestry5/trunk/tapestry-test/src/main/java/org/apache/tapestry5/ioc/
tapestry/tapestry5/trunk/tapestry-test/src/main/java/org/apache/tapestry5/ioc/test/
tapestry/tapestry5/trunk/tapestry-test/src/main/java/org/apache/tapestry5/ioc/test/MockTester.java
- copied, changed from r1087556, tapestry/tapestry5/trunk/tapestry-ioc/src/main/java/org/apache/tapestry5/ioc/test/MockTester.java
tapestry/tapestry5/trunk/tapestry-test/src/main/java/org/apache/tapestry5/ioc/test/TestBase.java
- copied, changed from r1087556, tapestry/tapestry5/trunk/tapestry-ioc/src/main/java/org/apache/tapestry5/ioc/test/TestBase.java
tapestry/tapestry5/trunk/tapestry-test/src/main/java/org/apache/tapestry5/ioc/test/TestUtils.java
- copied, changed from r1087556, tapestry/tapestry5/trunk/tapestry-ioc/src/main/java/org/apache/tapestry5/ioc/test/TestUtils.java
Removed:
tapestry/tapestry5/trunk/tapestry-ioc/src/main/java/org/apache/tapestry5/ioc/test/MockTester.java
tapestry/tapestry5/trunk/tapestry-ioc/src/main/java/org/apache/tapestry5/ioc/test/TestBase.java
tapestry/tapestry5/trunk/tapestry-ioc/src/main/java/org/apache/tapestry5/ioc/test/TestUtils.java
Modified:
tapestry/tapestry5/trunk/tapestry-ioc/build.gradle
tapestry/tapestry5/trunk/tapestry-ioc/pom.xml
tapestry/tapestry5/trunk/tapestry-ioc/src/main/java/org/apache/tapestry5/ioc/services/TapestryIOCModule.java
tapestry/tapestry5/trunk/tapestry-ioc/src/test/java/org/apache/tapestry5/ioc/internal/services/TypeCoercerImplTest.java
tapestry/tapestry5/trunk/tapestry-json/build.gradle
tapestry/tapestry5/trunk/tapestry-json/pom.xml
tapestry/tapestry5/trunk/tapestry-test/build.gradle
tapestry/tapestry5/trunk/tapestry-test/pom.xml
Modified: tapestry/tapestry5/trunk/tapestry-ioc/build.gradle
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-ioc/build.gradle?rev=1087557&r1=1087556&r2=1087557&view=diff
==============================================================================
--- tapestry/tapestry5/trunk/tapestry-ioc/build.gradle (original)
+++ tapestry/tapestry5/trunk/tapestry-ioc/build.gradle Fri Apr 1 02:18:03 2011
@@ -3,8 +3,9 @@ description = "A code-centric, high-perf
dependencies {
compile project(':tapestry-func')
compile project(':tapestry-annotations')
+ compile project(':tapestry-json')
- testCompile project(':tapestry-test')
+ provided project(':tapestry-test')
compile "javassist:javassist:3.12.1.GA"
@@ -13,8 +14,6 @@ dependencies {
compile "org.slf4j:slf4j-api:1.6.1"
compile "log4j:log4j:1.2.14"
compile "org.slf4j:slf4j-log4j12:1.6.1"
-
- compile "org.easymock:easymock:$easymockVersion"
-
+
compile "org.testng:testng:$testngVersion", { transitive = false }
}
\ No newline at end of file
Modified: tapestry/tapestry5/trunk/tapestry-ioc/pom.xml
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-ioc/pom.xml?rev=1087557&r1=1087556&r2=1087557&view=diff
==============================================================================
--- tapestry/tapestry5/trunk/tapestry-ioc/pom.xml (original)
+++ tapestry/tapestry5/trunk/tapestry-ioc/pom.xml Fri Apr 1 02:18:03 2011
@@ -30,6 +30,26 @@
<version>${project.version}</version>
</dependency>
+ <dependency>
+ <groupId>org.apache.tapestry</groupId>
+ <artifactId>tapestry-json</artifactId>
+ <version>${project.version}</version>
+ </dependency>
+
+ <dependency>
+ <groupId>org.apache.tapestry</groupId>
+ <artifactId>tapestry-test</artifactId>
+ <version>${project.version}</version>
+ <scope>provided</scope>
+ </dependency>
+
+ <!-- Override parent pom: needed at compile time. -->
+ <dependency>
+ <groupId>org.easymock</groupId>
+ <artifactId>easymock</artifactId>
+ <scope>provided</scope>
+ </dependency>
+
<dependency>
<groupId>javassist</groupId>
<artifactId>javassist</artifactId>
@@ -63,23 +83,6 @@
<artifactId>slf4j-log4j12</artifactId>
<version>1.6.1</version>
</dependency>
-
-
- <!-- Override parent pom: needed at compile time. -->
- <dependency>
- <groupId>org.easymock</groupId>
- <artifactId>easymock</artifactId>
- <scope>provided</scope>
- </dependency>
- <!-- Override parent pom: needed at compile time. -->
- <dependency>
- <groupId>org.testng</groupId>
- <artifactId>testng</artifactId>
- <!-- Looks like if you override scope, you have to provide version (and
- classifier) as well. Or perhaps this has something to do with classifier. -->
- <version>${testng-version}</version>
- <scope>provided</scope>
- </dependency>
</dependencies>
<build>
<plugins>
Modified: tapestry/tapestry5/trunk/tapestry-ioc/src/main/java/org/apache/tapestry5/ioc/services/TapestryIOCModule.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-ioc/src/main/java/org/apache/tapestry5/ioc/services/TapestryIOCModule.java?rev=1087557&r1=1087556&r2=1087557&view=diff
==============================================================================
--- tapestry/tapestry5/trunk/tapestry-ioc/src/main/java/org/apache/tapestry5/ioc/services/TapestryIOCModule.java (original)
+++ tapestry/tapestry5/trunk/tapestry-ioc/src/main/java/org/apache/tapestry5/ioc/services/TapestryIOCModule.java Fri Apr 1 02:18:03 2011
@@ -31,17 +31,58 @@ import java.util.concurrent.ThreadPoolEx
import java.util.concurrent.TimeUnit;
import org.apache.tapestry5.func.Flow;
-import org.apache.tapestry5.ioc.*;
+import org.apache.tapestry5.ioc.AnnotationProvider;
+import org.apache.tapestry5.ioc.Configuration;
+import org.apache.tapestry5.ioc.IOCSymbols;
+import org.apache.tapestry5.ioc.MappedConfiguration;
+import org.apache.tapestry5.ioc.ObjectLocator;
+import org.apache.tapestry5.ioc.ObjectProvider;
+import org.apache.tapestry5.ioc.OrderedConfiguration;
+import org.apache.tapestry5.ioc.ScopeConstants;
+import org.apache.tapestry5.ioc.ServiceBinder;
+import org.apache.tapestry5.ioc.ServiceLifecycle;
+import org.apache.tapestry5.ioc.ServiceLifecycle2;
import org.apache.tapestry5.ioc.annotations.Contribute;
import org.apache.tapestry5.ioc.annotations.IntermediateType;
import org.apache.tapestry5.ioc.annotations.Local;
import org.apache.tapestry5.ioc.annotations.Marker;
import org.apache.tapestry5.ioc.annotations.PreventServiceDecoration;
import org.apache.tapestry5.ioc.annotations.Symbol;
-import org.apache.tapestry5.ioc.internal.services.*;
+import org.apache.tapestry5.ioc.internal.services.AspectDecoratorImpl;
+import org.apache.tapestry5.ioc.internal.services.AutobuildObjectProvider;
+import org.apache.tapestry5.ioc.internal.services.ChainBuilderImpl;
+import org.apache.tapestry5.ioc.internal.services.ClassNameLocatorImpl;
+import org.apache.tapestry5.ioc.internal.services.ClasspathURLConverterImpl;
+import org.apache.tapestry5.ioc.internal.services.DefaultImplementationBuilderImpl;
+import org.apache.tapestry5.ioc.internal.services.ExceptionAnalyzerImpl;
+import org.apache.tapestry5.ioc.internal.services.ExceptionTrackerImpl;
+import org.apache.tapestry5.ioc.internal.services.LazyAdvisorImpl;
+import org.apache.tapestry5.ioc.internal.services.LoggingAdvisorImpl;
+import org.apache.tapestry5.ioc.internal.services.LoggingDecoratorImpl;
+import org.apache.tapestry5.ioc.internal.services.MapSymbolProvider;
+import org.apache.tapestry5.ioc.internal.services.MasterObjectProviderImpl;
+import org.apache.tapestry5.ioc.internal.services.NonParallelExecutor;
+import org.apache.tapestry5.ioc.internal.services.ParallelExecutorImpl;
+import org.apache.tapestry5.ioc.internal.services.PerThreadServiceLifecycle;
+import org.apache.tapestry5.ioc.internal.services.PipelineBuilderImpl;
+import org.apache.tapestry5.ioc.internal.services.PropertyAccessImpl;
+import org.apache.tapestry5.ioc.internal.services.PropertyShadowBuilderImpl;
+import org.apache.tapestry5.ioc.internal.services.RegistryStartup;
+import org.apache.tapestry5.ioc.internal.services.ServiceOverrideImpl;
+import org.apache.tapestry5.ioc.internal.services.StrategyBuilderImpl;
+import org.apache.tapestry5.ioc.internal.services.SymbolObjectProvider;
+import org.apache.tapestry5.ioc.internal.services.SymbolSourceImpl;
+import org.apache.tapestry5.ioc.internal.services.SystemPropertiesSymbolProvider;
+import org.apache.tapestry5.ioc.internal.services.ThreadLocaleImpl;
+import org.apache.tapestry5.ioc.internal.services.ThunkCreatorImpl;
+import org.apache.tapestry5.ioc.internal.services.TypeCoercerImpl;
+import org.apache.tapestry5.ioc.internal.services.UpdateListenerHubImpl;
+import org.apache.tapestry5.ioc.internal.services.ValueObjectProvider;
import org.apache.tapestry5.ioc.internal.util.CollectionFactory;
import org.apache.tapestry5.ioc.internal.util.InternalUtils;
import org.apache.tapestry5.ioc.util.TimeInterval;
+import org.apache.tapestry5.json.JSONArray;
+import org.apache.tapestry5.json.JSONObject;
import org.apache.tapestry5.services.UpdateListenerHub;
/**
@@ -183,6 +224,8 @@ public final class TapestryIOCModule
* <li>Collection to Object[] (via the toArray() method)
* <li>{@link Flow} to List</li>
* <li>{@link Flow} to Boolean (false if empty)</li>
+ * <li>{@link String} to {@link JSONObject}</li>
+ * <li>{@link String} to {@link JSONArray}</li>
* </ul>
*/
@Contribute(TypeCoercer.class)
@@ -429,6 +472,22 @@ public final class TapestryIOCModule
return !input.isEmpty();
}
});
+
+ add(configuration, String.class, JSONArray.class, new Coercion<String, JSONArray>()
+ {
+ public JSONArray coerce(String input)
+ {
+ return new JSONArray(input);
+ }
+ });
+
+ add(configuration, String.class, JSONObject.class, new Coercion<String, JSONObject>()
+ {
+ public JSONObject coerce(String input)
+ {
+ return new JSONObject(input);
+ }
+ });
}
private static <S, T> void add(Configuration<CoercionTuple> configuration, Class<S> sourceType,
Modified: tapestry/tapestry5/trunk/tapestry-ioc/src/test/java/org/apache/tapestry5/ioc/internal/services/TypeCoercerImplTest.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-ioc/src/test/java/org/apache/tapestry5/ioc/internal/services/TypeCoercerImplTest.java?rev=1087557&r1=1087556&r2=1087557&view=diff
==============================================================================
--- tapestry/tapestry5/trunk/tapestry-ioc/src/test/java/org/apache/tapestry5/ioc/internal/services/TypeCoercerImplTest.java (original)
+++ tapestry/tapestry5/trunk/tapestry-ioc/src/test/java/org/apache/tapestry5/ioc/internal/services/TypeCoercerImplTest.java Fri Apr 1 02:18:03 2011
@@ -20,6 +20,8 @@ import org.apache.tapestry5.ioc.internal
import org.apache.tapestry5.ioc.services.Coercion;
import org.apache.tapestry5.ioc.services.TypeCoercer;
import org.apache.tapestry5.ioc.util.TimeInterval;
+import org.apache.tapestry5.json.JSONArray;
+import org.apache.tapestry5.json.JSONObject;
import org.testng.annotations.AfterClass;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.DataProvider;
@@ -280,6 +282,10 @@ public class TypeCoercerImplTest extends
{ F.flow(1, 2, 3), List.class, Arrays.asList(1, 2, 3) },
+ { "[1, true]", JSONArray.class, new JSONArray(1, true) },
+
+ { "{ 'fred': 1, 'barney': 2}", JSONObject.class, new JSONObject().put("fred", 1).put("barney", 2) },
+
// null to arbitrary object is still null
{ null, XMLReader.class, null } };
Modified: tapestry/tapestry5/trunk/tapestry-json/build.gradle
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-json/build.gradle?rev=1087557&r1=1087556&r2=1087557&view=diff
==============================================================================
--- tapestry/tapestry5/trunk/tapestry-json/build.gradle (original)
+++ tapestry/tapestry5/trunk/tapestry-json/build.gradle Fri Apr 1 02:18:03 2011
@@ -3,6 +3,5 @@ description = "Repackaged, improved (and
dependencies {
testCompile project(':tapestry-test')
- testCompile project(':tapestry-ioc')
}
\ No newline at end of file
Modified: tapestry/tapestry5/trunk/tapestry-json/pom.xml
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-json/pom.xml?rev=1087557&r1=1087556&r2=1087557&view=diff
==============================================================================
--- tapestry/tapestry5/trunk/tapestry-json/pom.xml (original)
+++ tapestry/tapestry5/trunk/tapestry-json/pom.xml Fri Apr 1 02:18:03 2011
@@ -20,11 +20,6 @@
<artifactId>tapestry-test</artifactId>
<scope>test</scope>
</dependency>
- <dependency>
- <groupId>org.apache.tapestry</groupId>
- <artifactId>tapestry-ioc</artifactId>
- <scope>test</scope>
- </dependency>
</dependencies>
<build>
<plugins>
Modified: tapestry/tapestry5/trunk/tapestry-test/build.gradle
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-test/build.gradle?rev=1087557&r1=1087556&r2=1087557&view=diff
==============================================================================
--- tapestry/tapestry5/trunk/tapestry-test/build.gradle (original)
+++ tapestry/tapestry5/trunk/tapestry-test/build.gradle Fri Apr 1 02:18:03 2011
@@ -13,5 +13,6 @@ dependencies {
compile "org.apache.tomcat:catalina:$tomcatVersion"
compile "org.apache.tomcat:coyote:$tomcatVersion"
-
+
+ compile "org.easymock:easymock:$easymockVersion"
}
\ No newline at end of file
Modified: tapestry/tapestry5/trunk/tapestry-test/pom.xml
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-test/pom.xml?rev=1087557&r1=1087556&r2=1087557&view=diff
==============================================================================
--- tapestry/tapestry5/trunk/tapestry-test/pom.xml (original)
+++ tapestry/tapestry5/trunk/tapestry-test/pom.xml Fri Apr 1 02:18:03 2011
@@ -1,5 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
-<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>org.apache.tapestry</groupId>
<artifactId>tapestry-test</artifactId>
@@ -56,24 +57,29 @@
<version>5.1.12</version>
<scope>compile</scope>
</dependency>
-
+ <!-- Override parent pom: needed at compile time. -->
+ <dependency>
+ <groupId>org.easymock</groupId>
+ <artifactId>easymock</artifactId>
+ <scope>provided</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.tomcat</groupId>
+ <artifactId>catalina</artifactId>
+ <version>6.0.30</version>
+ <scope>compile</scope>
+ </dependency>
<dependency>
- <groupId>org.apache.tomcat</groupId>
- <artifactId>catalina</artifactId>
- <version>6.0.30</version>
- <scope>compile</scope>
- </dependency>
- <dependency>
- <groupId>org.apache.tomcat</groupId>
- <artifactId>coyote</artifactId>
- <version>6.0.30</version>
- <scope>compile</scope>
- </dependency>
- <dependency>
- <groupId>org.apache.tomcat</groupId>
- <artifactId>dbcp</artifactId>
- <version>6.0.30</version>
- <scope>compile</scope>
+ <groupId>org.apache.tomcat</groupId>
+ <artifactId>coyote</artifactId>
+ <version>6.0.30</version>
+ <scope>compile</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.tomcat</groupId>
+ <artifactId>dbcp</artifactId>
+ <version>6.0.30</version>
+ <scope>compile</scope>
</dependency>
</dependencies>
<build>
Copied: tapestry/tapestry5/trunk/tapestry-test/src/main/java/org/apache/tapestry5/ioc/test/MockTester.java (from r1087556, tapestry/tapestry5/trunk/tapestry-ioc/src/main/java/org/apache/tapestry5/ioc/test/MockTester.java)
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-test/src/main/java/org/apache/tapestry5/ioc/test/MockTester.java?p2=tapestry/tapestry5/trunk/tapestry-test/src/main/java/org/apache/tapestry5/ioc/test/MockTester.java&p1=tapestry/tapestry5/trunk/tapestry-ioc/src/main/java/org/apache/tapestry5/ioc/test/MockTester.java&r1=1087556&r2=1087557&rev=1087557&view=diff
==============================================================================
--- tapestry/tapestry5/trunk/tapestry-ioc/src/main/java/org/apache/tapestry5/ioc/test/MockTester.java (original)
+++ tapestry/tapestry5/trunk/tapestry-test/src/main/java/org/apache/tapestry5/ioc/test/MockTester.java Fri Apr 1 02:18:03 2011
@@ -1,10 +1,10 @@
-// Copyright 2007 The Apache Software Foundation
+// Copyright 2007, 2011 The Apache Software Foundation
//
// Licensed 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
+// 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,
@@ -22,6 +22,9 @@ import org.easymock.IMocksControl;
* suite. A <em>single</em> standard mock control is used for all mock instances. The control does not care about
* execution order, but will balk at any unexpected method invocations. This class is thread safe (it used a thread
* local to store the mock control).
+ * <p>
+ * This class was originally in the tapestry-ioc module as was moved to tapestry-test; the package name was not changed
+ * to ensure backwards compatibility.
*/
public final class MockTester
{
@@ -52,9 +55,11 @@ public final class MockTester
/**
* Creates a new mock object of the indicated type. The shared mock control does <strong>not</strong> check order,
* but does fail on any unexpected method invocations.
- *
- * @param <T> the type of the mock object
- * @param mockClass the class to mock
+ *
+ * @param <T>
+ * the type of the mock object
+ * @param mockClass
+ * the class to mock
* @return the mock object, ready for training
*/
public <T> T newMock(Class<T> mockClass)
Copied: tapestry/tapestry5/trunk/tapestry-test/src/main/java/org/apache/tapestry5/ioc/test/TestBase.java (from r1087556, tapestry/tapestry5/trunk/tapestry-ioc/src/main/java/org/apache/tapestry5/ioc/test/TestBase.java)
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-test/src/main/java/org/apache/tapestry5/ioc/test/TestBase.java?p2=tapestry/tapestry5/trunk/tapestry-test/src/main/java/org/apache/tapestry5/ioc/test/TestBase.java&p1=tapestry/tapestry5/trunk/tapestry-ioc/src/main/java/org/apache/tapestry5/ioc/test/TestBase.java&r1=1087556&r2=1087557&rev=1087557&view=diff
==============================================================================
--- tapestry/tapestry5/trunk/tapestry-ioc/src/main/java/org/apache/tapestry5/ioc/test/TestBase.java (original)
+++ tapestry/tapestry5/trunk/tapestry-test/src/main/java/org/apache/tapestry5/ioc/test/TestBase.java Fri Apr 1 02:18:03 2011
@@ -1,4 +1,4 @@
-// Copyright 2006, 2007, 2008, 2010 The Apache Software Foundation
+// Copyright 2006, 2007, 2008, 2010, 2011 The Apache Software Foundation
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
@@ -14,7 +14,6 @@
package org.apache.tapestry5.ioc.test;
-
import org.easymock.Capture;
import org.easymock.EasyMock;
import org.easymock.IAnswer;
@@ -37,6 +36,9 @@ import org.testng.annotations.AfterMetho
* <p/>
* This class is thread safe (it uses a thread local to store the mock control). In theory, this should allow TestNG to
* execute tests in parallel.
+ * <p>
+ * This class was originally in the tapestry-ioc module as was moved to tapestry-test; the package name was not changed
+ * to ensure backwards compatibility.
*
* @see org.easymock.EasyMock#createControl()
* @see org.apache.tapestry5.ioc.test.MockTester
Copied: tapestry/tapestry5/trunk/tapestry-test/src/main/java/org/apache/tapestry5/ioc/test/TestUtils.java (from r1087556, tapestry/tapestry5/trunk/tapestry-ioc/src/main/java/org/apache/tapestry5/ioc/test/TestUtils.java)
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-test/src/main/java/org/apache/tapestry5/ioc/test/TestUtils.java?p2=tapestry/tapestry5/trunk/tapestry-test/src/main/java/org/apache/tapestry5/ioc/test/TestUtils.java&p1=tapestry/tapestry5/trunk/tapestry-ioc/src/main/java/org/apache/tapestry5/ioc/test/TestUtils.java&r1=1087556&r2=1087557&rev=1087557&view=diff
==============================================================================
--- tapestry/tapestry5/trunk/tapestry-ioc/src/main/java/org/apache/tapestry5/ioc/test/TestUtils.java (original)
+++ tapestry/tapestry5/trunk/tapestry-test/src/main/java/org/apache/tapestry5/ioc/test/TestUtils.java Fri Apr 1 02:18:03 2011
@@ -1,4 +1,4 @@
-// Copyright 2010 The Apache Software Foundation
+// Copyright 2010, 2011 The Apache Software Foundation
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
@@ -19,12 +19,14 @@ import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
-import org.apache.tapestry5.ioc.internal.util.InternalUtils;
import org.testng.Assert;
/**
* Extra assertions on top of the standard set, packaged as a base class for easy referencing in tests. Also,
* utilities for instantiation objects and setting and reading private fields of those objects.
+ * <p>
+ * This class was originally in the tapestry-ioc module as was moved to tapestry-test; the package name was not changed
+ * to ensure backwards compatibility.
*
* @since 5.2.0
*/
@@ -94,15 +96,16 @@ public class TestUtils extends Assert
List<String> actualStrings = toStrings(actual);
List<String> expectedStrings = toStrings(expected);
- String format = String.format("%%3d: [%%-%ds] [%%-%ds]\n", maxLength(actualStrings), maxLength(expectedStrings));
+ String format = String
+ .format("%%3d: [%%-%ds] [%%-%ds]\n", maxLength(actualStrings), maxLength(expectedStrings));
int count = Math.max(actual.size(), expected.size());
System.out.flush();
System.err.flush();
-
+
System.err.println("List results differ (actual vs. expected):");
-
+
for (int i = 0; i < count; i++)
{
System.err.printf(format, i, get(actualStrings, i), get(expectedStrings, i));
@@ -201,7 +204,7 @@ public class TestUtils extends Assert
catch (Exception ex)
{
throw new RuntimeException(String.format("Unable to set field '%s' of %s to %s: %s", fieldName, object,
- fieldValue, InternalUtils.toMessage(ex)), ex);
+ fieldValue, toMessage(ex)), ex);
}
}
@@ -221,7 +224,7 @@ public class TestUtils extends Assert
public static Object get(Object object, String fieldName)
{
assert object != null;
- assert InternalUtils.isNonBlank(fieldName);
+
try
{
Field field = findField(object.getClass(), fieldName);
@@ -233,10 +236,20 @@ public class TestUtils extends Assert
catch (Exception ex)
{
throw new RuntimeException(String.format("Unable to read field '%s' of %s: %s", fieldName, object,
- InternalUtils.toMessage(ex)), ex);
+ toMessage(ex)), ex);
}
}
+ private static String toMessage(Throwable exception)
+ {
+ String message = exception.getMessage();
+
+ if (message != null)
+ return message;
+
+ return exception.getClass().getName();
+ }
+
private static Field findField(Class objectClass, String fieldName)
{
@@ -281,7 +294,7 @@ public class TestUtils extends Assert
catch (Exception ex)
{
throw new RuntimeException(String.format("Unable to instantiate instance of %s: %s", objectType.getName(),
- InternalUtils.toMessage(ex)), ex);
+ toMessage(ex)), ex);
}
return set(result, fieldValues);