You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tapestry.apache.org by jk...@apache.org on 2006/06/27 20:21:40 UTC
svn commit: r417545 [10/12] - in /tapestry/tapestry4/trunk: ./
examples/TimeTracker/src/context/ framework/
framework/src/java/org/apache/tapestry/form/validator/
framework/src/java/org/apache/tapestry/json/
framework/src/java/org/apache/tapestry/valid...
Modified: tapestry/tapestry4/trunk/framework/src/test/org/apache/tapestry/services/impl/EngineFactoryTest.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry4/trunk/framework/src/test/org/apache/tapestry/services/impl/EngineFactoryTest.java?rev=417545&r1=417544&r2=417545&view=diff
==============================================================================
--- tapestry/tapestry4/trunk/framework/src/test/org/apache/tapestry/services/impl/EngineFactoryTest.java (original)
+++ tapestry/tapestry4/trunk/framework/src/test/org/apache/tapestry/services/impl/EngineFactoryTest.java Tue Jun 27 11:21:31 2006
@@ -14,12 +14,16 @@
package org.apache.tapestry.services.impl;
+import static org.easymock.EasyMock.expect;
+import static org.testng.AssertJUnit.assertEquals;
+import static org.testng.AssertJUnit.assertTrue;
+
import java.util.Locale;
import org.apache.hivemind.ApplicationRuntimeException;
import org.apache.hivemind.ErrorLog;
import org.apache.hivemind.impl.DefaultClassResolver;
-import org.apache.hivemind.test.HiveMindTestCase;
+import org.apache.tapestry.BaseComponentTestCase;
import org.apache.tapestry.IEngine;
import org.apache.tapestry.engine.AbstractEngine;
import org.apache.tapestry.engine.BaseEngine;
@@ -31,11 +35,11 @@
* @author Howard Lewis Ship
* @since 4.0
*/
-public class EngineFactoryTest extends HiveMindTestCase
+public class EngineFactoryTest extends BaseComponentTestCase
{
public void testUseDefault()
{
- IApplicationSpecification spec = newSpec();
+ IApplicationSpecification spec = newAppSpec();
// Training
@@ -47,7 +51,7 @@
f.setClassResolver(new DefaultClassResolver());
f.setDefaultEngineClassName(BaseEngine.class.getName());
- replayControls();
+ replay();
f.initializeService();
@@ -56,23 +60,22 @@
assertTrue(result instanceof BaseEngine);
assertEquals(Locale.CANADA_FRENCH, result.getLocale());
- verifyControls();
+ verify();
}
private void trainGetEngineClassName(IApplicationSpecification spec, String engineClassName)
{
- spec.getEngineClassName();
- setReturnValue(spec, engineClassName);
+ expect(spec.getEngineClassName()).andReturn(engineClassName);
}
- private IApplicationSpecification newSpec()
+ private IApplicationSpecification newAppSpec()
{
return (IApplicationSpecification) newMock(IApplicationSpecification.class);
}
public void testDefinedInSpec()
{
- IApplicationSpecification spec = newSpec();
+ IApplicationSpecification spec = newAppSpec();
trainGetEngineClassName(spec, EngineFixture.class.getName());
@@ -81,7 +84,7 @@
f.setApplicationSpecification(spec);
f.setClassResolver(new DefaultClassResolver());
- replayControls();
+ replay();
f.initializeService();
@@ -90,12 +93,12 @@
assertTrue(result instanceof EngineFixture);
assertEquals(Locale.CHINESE, result.getLocale());
- verifyControls();
+ verify();
}
public void testUnableToInstantiate()
{
- IApplicationSpecification spec = newSpec();
+ IApplicationSpecification spec = newAppSpec();
// Training
@@ -106,7 +109,7 @@
f.setApplicationSpecification(spec);
f.setClassResolver(new DefaultClassResolver());
- replayControls();
+ replay();
f.initializeService();
@@ -122,12 +125,12 @@
"Unable to instantiate engine as instance of class org.apache.tapestry.engine.AbstractEngine");
}
- verifyControls();
+ verify();
}
public void testInvalidClass()
{
- IApplicationSpecification spec = newSpec();
+ IApplicationSpecification spec = newAppSpec();
trainGetEngineClassName(spec, "foo.XyzzYx");
@@ -142,7 +145,7 @@
f.setErrorLog(log);
f.setDefaultEngineClassName(BaseEngine.class.getName());
- replayControls();
+ replay();
f.initializeService();
@@ -150,6 +153,6 @@
assertTrue(result instanceof BaseEngine);
- verifyControls();
+ verify();
}
}
Modified: tapestry/tapestry4/trunk/framework/src/test/org/apache/tapestry/services/impl/EngineServiceInnerProxyTest.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry4/trunk/framework/src/test/org/apache/tapestry/services/impl/EngineServiceInnerProxyTest.java?rev=417545&r1=417544&r2=417545&view=diff
==============================================================================
--- tapestry/tapestry4/trunk/framework/src/test/org/apache/tapestry/services/impl/EngineServiceInnerProxyTest.java (original)
+++ tapestry/tapestry4/trunk/framework/src/test/org/apache/tapestry/services/impl/EngineServiceInnerProxyTest.java Tue Jun 27 11:21:31 2006
@@ -14,6 +14,10 @@
package org.apache.tapestry.services.impl;
+import static org.easymock.EasyMock.expect;
+import static org.testng.AssertJUnit.assertEquals;
+import static org.testng.AssertJUnit.assertSame;
+
import org.apache.tapestry.IRequestCycle;
import org.apache.tapestry.engine.IEngineService;
import org.apache.tapestry.engine.ILink;
@@ -30,8 +34,7 @@
{
EngineServiceSource source = newSource();
- source.resolveEngineService(name);
- setReturnValue(source, service);
+ expect(source.resolveEngineService(name)).andReturn(service);
return source;
}
@@ -41,14 +44,14 @@
EngineServiceOuterProxy outer = new EngineServiceOuterProxy("Outer");
EngineServiceSource source = newSource();
- replayControls();
+ replay();
EngineServiceInnerProxy proxy = new EngineServiceInnerProxy("Inner", outer, source);
assertEquals("Inner", proxy.getName());
assertEquals("<InnerProxy for engine service 'Inner'>", proxy.toString());
- verifyControls();
+ verify();
}
protected EngineServiceSource newSource()
@@ -68,7 +71,7 @@
EngineServiceSource source = newSource("fred", service);
- replayControls();
+ replay();
EngineServiceOuterProxy outer = new EngineServiceOuterProxy("fred");
EngineServiceInnerProxy inner = new EngineServiceInnerProxy("fred", outer, source);
@@ -79,7 +82,7 @@
assertSame(service, outer.getDelegate());
- verifyControls();
+ verify();
}
public void testGetLinkPost()
@@ -94,7 +97,7 @@
EngineServiceSource source = newSource("fred", service);
- replayControls();
+ replay();
EngineServiceOuterProxy outer = new EngineServiceOuterProxy("fred");
EngineServiceInnerProxy inner = new EngineServiceInnerProxy("fred", outer, source);
@@ -105,7 +108,7 @@
assertSame(service, outer.getDelegate());
- verifyControls();
+ verify();
}
public void testService() throws Exception
{
@@ -116,7 +119,7 @@
EngineServiceSource source = newSource("fred", service);
- replayControls();
+ replay();
EngineServiceOuterProxy outer = new EngineServiceOuterProxy("fred");
EngineServiceInnerProxy inner = new EngineServiceInnerProxy("fred", outer, source);
@@ -127,6 +130,6 @@
assertSame(service, outer.getDelegate());
- verifyControls();
+ verify();
}
}
Modified: tapestry/tapestry4/trunk/framework/src/test/org/apache/tapestry/services/impl/EngineServiceOuterProxyTest.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry4/trunk/framework/src/test/org/apache/tapestry/services/impl/EngineServiceOuterProxyTest.java?rev=417545&r1=417544&r2=417545&view=diff
==============================================================================
--- tapestry/tapestry4/trunk/framework/src/test/org/apache/tapestry/services/impl/EngineServiceOuterProxyTest.java (original)
+++ tapestry/tapestry4/trunk/framework/src/test/org/apache/tapestry/services/impl/EngineServiceOuterProxyTest.java Tue Jun 27 11:21:31 2006
@@ -14,6 +14,9 @@
package org.apache.tapestry.services.impl;
+import static org.testng.AssertJUnit.assertEquals;
+import static org.testng.AssertJUnit.assertSame;
+
import org.apache.tapestry.IRequestCycle;
import org.apache.tapestry.engine.IEngineService;
import org.apache.tapestry.engine.ILink;
@@ -47,7 +50,7 @@
delegate.service(cycle);
- replayControls();
+ replay();
EngineServiceOuterProxy proxy = new EngineServiceOuterProxy("xxx");
proxy.installDelegate(delegate);
@@ -56,7 +59,7 @@
proxy.service(cycle);
- verifyControls();
+ verify();
}
public void testGetLink() throws Exception
@@ -67,21 +70,21 @@
trainGetLink(delegate, false, parameter, link);
- replayControls();
+ replay();
EngineServiceOuterProxy proxy = new EngineServiceOuterProxy("xxx");
proxy.installDelegate(delegate);
assertSame(link, proxy.getLink(false, parameter));
- verifyControls();
+ verify();
trainGetLink(delegate, true, parameter, link);
- replayControls();
+ replay();
assertSame(link, proxy.getLink(true, parameter));
- verifyControls();
+ verify();
}
}
Modified: tapestry/tapestry4/trunk/framework/src/test/org/apache/tapestry/services/impl/LinkFactoryTest.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry4/trunk/framework/src/test/org/apache/tapestry/services/impl/LinkFactoryTest.java?rev=417545&r1=417544&r2=417545&view=diff
==============================================================================
--- tapestry/tapestry4/trunk/framework/src/test/org/apache/tapestry/services/impl/LinkFactoryTest.java (original)
+++ tapestry/tapestry4/trunk/framework/src/test/org/apache/tapestry/services/impl/LinkFactoryTest.java Tue Jun 27 11:21:31 2006
@@ -14,6 +14,9 @@
package org.apache.tapestry.services.impl;
+import static org.easymock.EasyMock.expect;
+import static org.testng.AssertJUnit.assertEquals;
+
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
@@ -23,7 +26,7 @@
import org.apache.hivemind.ApplicationRuntimeException;
import org.apache.hivemind.ErrorLog;
-import org.apache.hivemind.test.HiveMindTestCase;
+import org.apache.tapestry.BaseComponentTestCase;
import org.apache.tapestry.IEngine;
import org.apache.tapestry.IRequestCycle;
import org.apache.tapestry.engine.IEngineService;
@@ -44,16 +47,11 @@
* @author Howard M. Lewis Ship
* @since 4.0
*/
-public class LinkFactoryTest extends HiveMindTestCase
+public class LinkFactoryTest extends BaseComponentTestCase
{
private ErrorLog newErrorLog()
{
- return (ErrorLog) newMock(ErrorLog.class);
- }
-
- private WebRequest newRequest()
- {
- return (WebRequest) newMock(WebRequest.class);
+ return newMock(ErrorLog.class);
}
private static class NoopEncoder implements ServiceEncoder
@@ -105,24 +103,12 @@
private IEngine newEngine()
{
- return (IEngine) newMock(IEngine.class);
- }
-
- private IRequestCycle newCycle()
- {
- return (IRequestCycle) newMock(IRequestCycle.class);
+ return newMock(IEngine.class);
}
private void trainGetOutputEncoding(IEngine engine, String outputEncoding)
{
- engine.getOutputEncoding();
- setReturnValue(engine, outputEncoding);
- }
-
- private void trainGetEngine(IRequestCycle cycle, IEngine engine)
- {
- cycle.getEngine();
- setReturnValue(cycle, engine);
+ expect(engine.getOutputEncoding()).andReturn(outputEncoding);
}
public void testNoEncoders()
@@ -138,7 +124,7 @@
trainEncodeURL(cycle, "/context/app?service=myservice", "/context/app?service=myservice");
- replayControls();
+ replay();
LinkFactoryImpl lf = new LinkFactoryImpl();
@@ -157,15 +143,14 @@
assertEquals("/context/app?service=myservice", link.getURL());
- verifyControls();
+ verify();
}
private IEngineService newService(String name)
{
- IEngineService service = (IEngineService) newMock(IEngineService.class);
+ IEngineService service = newMock(IEngineService.class);
- service.getName();
- setReturnValue(service, name);
+ expect(service.getName()).andReturn(name);
return service;
}
@@ -183,7 +168,7 @@
trainEncodeURL(cycle, "/context/app?foo=bar&service=myservice", "{encoded}");
- replayControls();
+ replay();
LinkFactoryImpl lf = new LinkFactoryImpl();
@@ -203,13 +188,7 @@
assertEquals("{encoded}", link.getURL());
- verifyControls();
- }
-
- private void trainEncodeURL(IRequestCycle cycle, String inputURL, String encodeURL)
- {
- cycle.encodeURL(inputURL);
- setReturnValue(cycle, encodeURL);
+ verify();
}
public void testNoopEncoders()
@@ -224,7 +203,7 @@
trainGetOutputEncoding(engine, "utf-8");
trainEncodeURL(cycle, "/context/app?service=myservice", "/context/app?service=myservice");
- replayControls();
+ replay();
List l = new ArrayList();
l.add(newContribution("fred", new NoopEncoder()));
@@ -247,7 +226,7 @@
assertEquals("/context/app?service=myservice", link.getURL());
- verifyControls();
+ verify();
}
public void testActiveEncoder()
@@ -262,7 +241,7 @@
trainGetOutputEncoding(engine, "utf-8");
trainEncodeURL(cycle, "/context/Barney.html", "/context/Barney.html");
- replayControls();
+ replay();
PageServiceEncoder e = new PageServiceEncoder();
e.setServiceName("page");
@@ -288,7 +267,7 @@
assertEquals("/context/Barney.html", link.getURL());
- verifyControls();
+ verify();
}
public void testServiceNameIsNull()
@@ -297,7 +276,7 @@
Map parameters = new HashMap();
- replayControls();
+ replay();
LinkFactory lf = new LinkFactoryImpl();
@@ -311,7 +290,7 @@
assertEquals(ImplMessages.serviceNameIsNull(), ex.getMessage());
}
- verifyControls();
+ verify();
}
public void testWithServiceParameters()
@@ -326,7 +305,7 @@
trainGetOutputEncoding(engine, "utf-8");
trainEncodeURL(cycle, "/context/Barney.ext?sp=T", "/context/Barney.ext?sp=T");
- replayControls();
+ replay();
PageServiceEncoder e = new PageServiceEncoder();
e.setServiceName("external");
@@ -355,6 +334,6 @@
assertEquals("/context/Barney.ext?sp=T", link.getURL());
- verifyControls();
+ verify();
}
}
Modified: tapestry/tapestry4/trunk/framework/src/test/org/apache/tapestry/services/impl/TestAbsoluteURLBuilder.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry4/trunk/framework/src/test/org/apache/tapestry/services/impl/TestAbsoluteURLBuilder.java?rev=417545&r1=417544&r2=417545&view=diff
==============================================================================
--- tapestry/tapestry4/trunk/framework/src/test/org/apache/tapestry/services/impl/TestAbsoluteURLBuilder.java (original)
+++ tapestry/tapestry4/trunk/framework/src/test/org/apache/tapestry/services/impl/TestAbsoluteURLBuilder.java Tue Jun 27 11:21:31 2006
@@ -14,10 +14,12 @@
package org.apache.tapestry.services.impl;
+import static org.easymock.EasyMock.expect;
+import static org.testng.AssertJUnit.assertEquals;
+
import org.apache.tapestry.junit.TapestryTestCase;
import org.apache.tapestry.services.AbsoluteURLBuilder;
import org.apache.tapestry.web.WebRequest;
-import org.easymock.MockControl;
/**
* Tests for {@link org.apache.tapestry.services.impl.AbsoluteURLBuilderImpl}.
@@ -38,19 +40,15 @@
private void attemptDefault(String expected, String URI, String scheme, String server, int port)
{
- MockControl control = newControl(WebRequest.class);
- WebRequest request = (WebRequest) control.getMock();
+ WebRequest request = newMock(WebRequest.class);
- request.getScheme();
- control.setReturnValue(scheme);
+ expect(request.getScheme()).andReturn(scheme);
- request.getServerName();
- control.setReturnValue(server);
+ expect(request.getServerName()).andReturn(server);
- request.getServerPort();
- control.setReturnValue(port);
+ expect(request.getServerPort()).andReturn(port);
- replayControls();
+ replay();
AbsoluteURLBuilderImpl b = new AbsoluteURLBuilderImpl();
b.setRequest(request);
@@ -59,7 +57,7 @@
assertEquals(expected, actual);
- verifyControls();
+ verify();
}
public void testURIIncludesServer()
Modified: tapestry/tapestry4/trunk/framework/src/test/org/apache/tapestry/services/impl/TestApplicationSpecificationInitializer.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry4/trunk/framework/src/test/org/apache/tapestry/services/impl/TestApplicationSpecificationInitializer.java?rev=417545&r1=417544&r2=417545&view=diff
==============================================================================
--- tapestry/tapestry4/trunk/framework/src/test/org/apache/tapestry/services/impl/TestApplicationSpecificationInitializer.java (original)
+++ tapestry/tapestry4/trunk/framework/src/test/org/apache/tapestry/services/impl/TestApplicationSpecificationInitializer.java Tue Jun 27 11:21:31 2006
@@ -14,6 +14,11 @@
package org.apache.tapestry.services.impl;
+import static org.easymock.EasyMock.expect;
+import static org.testng.AssertJUnit.assertEquals;
+import static org.testng.AssertJUnit.assertNotNull;
+import static org.testng.AssertJUnit.assertSame;
+
import java.net.URL;
import javax.servlet.ServletConfig;
@@ -25,15 +30,14 @@
import org.apache.hivemind.Resource;
import org.apache.hivemind.impl.DefaultClassResolver;
import org.apache.hivemind.impl.RegistryBuilder;
-import org.apache.hivemind.test.HiveMindTestCase;
import org.apache.hivemind.util.ClasspathResource;
import org.apache.hivemind.util.ContextResource;
+import org.apache.tapestry.BaseComponentTestCase;
import org.apache.tapestry.parse.ISpecificationParser;
import org.apache.tapestry.services.ApplicationGlobals;
import org.apache.tapestry.services.ApplicationInitializer;
import org.apache.tapestry.spec.ApplicationSpecification;
import org.apache.tapestry.spec.IApplicationSpecification;
-import org.easymock.MockControl;
/**
* Tests for the {@link org.apache.tapestry.services.impl.ApplicationSpecificationInitializer}.
@@ -41,7 +45,7 @@
* @author Howard Lewis Ship
* @since 4.0
*/
-public class TestApplicationSpecificationInitializer extends HiveMindTestCase
+public class TestApplicationSpecificationInitializer extends BaseComponentTestCase
{
public void testOnClasspath() throws Exception
{
@@ -61,30 +65,27 @@
i.setClasspathResourceFactory(cf);
HttpServlet servlet = new ServletFixture();
+
+ ServletConfig config = newMock(ServletConfig.class);
- MockControl configControl = newControl(ServletConfig.class);
- ServletConfig config = (ServletConfig) configControl.getMock();
-
- trainForServletInit(configControl, config);
+ trainForServletInit(config);
- config.getInitParameter(ApplicationSpecificationInitializer.APP_SPEC_PATH_PARAM);
- configControl.setReturnValue(appSpecResource.getPath());
+ expect(config.getInitParameter(ApplicationSpecificationInitializer.APP_SPEC_PATH_PARAM))
+ .andReturn(appSpecResource.getPath());
IApplicationSpecification as = new ApplicationSpecification();
-
- MockControl parserControl = newControl(ISpecificationParser.class);
- ISpecificationParser parser = (ISpecificationParser) parserControl.getMock();
+
+ ISpecificationParser parser = newMock(ISpecificationParser.class);
i.setParser(parser);
- parser.parseApplicationSpecification(appSpecResource);
- parserControl.setReturnValue(as);
+ expect(parser.parseApplicationSpecification(appSpecResource)).andReturn(as);
ApplicationGlobals ag = new ApplicationGlobalsImpl();
i.setGlobals(ag);
- replayControls();
+ replay();
servlet.init(config);
@@ -95,19 +96,16 @@
assertNotNull(ag.getActivator());
assertSame(as, ag.getSpecification());
- verifyControls();
+ verify();
}
- private void trainForServletInit(MockControl configControl, ServletConfig config)
+ private void trainForServletInit(ServletConfig config)
{
- MockControl contextControl = newControl(ServletContext.class);
- ServletContext context = (ServletContext) contextControl.getMock();
+ ServletContext context = newMock(ServletContext.class);
- config.getServletContext();
- configControl.setReturnValue(context);
+ expect(config.getServletContext()).andReturn(context);
- config.getServletName();
- configControl.setReturnValue("test");
+ expect(config.getServletName()).andReturn("test");
context.log("test: init");
}
@@ -117,12 +115,9 @@
DefaultClassResolver cr = new DefaultClassResolver();
ApplicationSpecificationInitializer i = new ApplicationSpecificationInitializer();
-
- MockControl contextControl = newControl(ServletContext.class);
- ServletContext context = (ServletContext) contextControl.getMock();
-
- MockControl logControl = newControl(Log.class);
- Log log = (Log) logControl.getMock();
+
+ ServletContext context = newMock(ServletContext.class);
+ Log log = newLog();
i.setLog(log);
@@ -132,48 +127,42 @@
i.setClasspathResourceFactory(cf);
HttpServlet servlet = new ServletFixture();
+
+ ServletConfig config = newMock(ServletConfig.class);
- MockControl configControl = newControl(ServletConfig.class);
- ServletConfig config = (ServletConfig) configControl.getMock();
-
- trainForServletInit(configControl, config);
+ trainForServletInit(config);
- config.getInitParameter(ApplicationSpecificationInitializer.APP_SPEC_PATH_PARAM);
- configControl.setReturnValue(null);
+ expect(config.getInitParameter(ApplicationSpecificationInitializer.APP_SPEC_PATH_PARAM))
+ .andReturn(null);
- config.getServletContext();
- configControl.setReturnValue(context);
+ expect(config.getServletContext()).andReturn(context);
- config.getServletName();
- configControl.setReturnValue("fred");
+ expect(config.getServletName()).andReturn("fred");
- log.isDebugEnabled();
- logControl.setReturnValue(true);
+ expect(log.isDebugEnabled()).andReturn(true);
Resource r = new ContextResource(context, "/WEB-INF/fred/fred.application");
log.debug("Checking for existence of " + r);
- context.getResource(r.getPath());
- contextControl.setReturnValue(new URL("file:/context" + r.getPath()));
+ expect(context.getResource(r.getPath()))
+ .andReturn(new URL("file:/context" + r.getPath()));
log.debug("Found " + r);
IApplicationSpecification as = new ApplicationSpecification();
-
- MockControl parserControl = newControl(ISpecificationParser.class);
- ISpecificationParser parser = (ISpecificationParser) parserControl.getMock();
+
+ ISpecificationParser parser = newMock(ISpecificationParser.class);
i.setParser(parser);
- parser.parseApplicationSpecification(r);
- parserControl.setReturnValue(as);
+ expect(parser.parseApplicationSpecification(r)).andReturn(as);
ApplicationGlobals ag = new ApplicationGlobalsImpl();
i.setGlobals(ag);
- replayControls();
+ replay();
servlet.init(config);
@@ -181,7 +170,7 @@
i.initialize(servlet);
- verifyControls();
+ verify();
}
public void testInWebInfFolder() throws Exception
@@ -190,11 +179,8 @@
ApplicationSpecificationInitializer i = new ApplicationSpecificationInitializer();
- MockControl contextControl = newControl(ServletContext.class);
- ServletContext context = (ServletContext) contextControl.getMock();
-
- MockControl logControl = newControl(Log.class);
- Log log = (Log) logControl.getMock();
+ ServletContext context = newMock(ServletContext.class);
+ Log log = newLog();
i.setLog(log);
@@ -205,51 +191,43 @@
HttpServlet servlet = new ServletFixture();
- MockControl configControl = newControl(ServletConfig.class);
- ServletConfig config = (ServletConfig) configControl.getMock();
+ ServletConfig config = newMock(ServletConfig.class);
- trainForServletInit(configControl, config);
+ trainForServletInit(config);
- config.getInitParameter(ApplicationSpecificationInitializer.APP_SPEC_PATH_PARAM);
- configControl.setReturnValue(null);
+ expect(config.getInitParameter(ApplicationSpecificationInitializer.APP_SPEC_PATH_PARAM))
+ .andReturn(null);
- config.getServletContext();
- configControl.setReturnValue(context);
+ expect(config.getServletContext()).andReturn(context);
- config.getServletName();
- configControl.setReturnValue("barney");
+ expect(config.getServletName()).andReturn("barney");
- log.isDebugEnabled();
- logControl.setReturnValue(false);
+ expect(log.isDebugEnabled()).andReturn(false);
Resource r = new ContextResource(context, "/WEB-INF/barney.application");
- context.getResource("/WEB-INF/barney/barney.application");
- contextControl.setReturnValue(null);
+ expect(context.getResource("/WEB-INF/barney/barney.application")).andReturn(null);
- log.isDebugEnabled();
- logControl.setReturnValue(false);
+ expect(log.isDebugEnabled()).andReturn(false);
- context.getResource(r.getPath());
- contextControl.setReturnValue(new URL("file:/context" + r.getPath()));
+ expect(context.getResource(r.getPath()))
+ .andReturn(new URL("file:/context" + r.getPath()));
log.debug("Found " + r);
IApplicationSpecification as = new ApplicationSpecification();
-
- MockControl parserControl = newControl(ISpecificationParser.class);
- ISpecificationParser parser = (ISpecificationParser) parserControl.getMock();
+
+ ISpecificationParser parser = newMock(ISpecificationParser.class);
i.setParser(parser);
- parser.parseApplicationSpecification(r);
- parserControl.setReturnValue(as);
+ expect(parser.parseApplicationSpecification(r)).andReturn(as);
ApplicationGlobals ag = new ApplicationGlobalsImpl();
i.setGlobals(ag);
- replayControls();
+ replay();
servlet.init(config);
@@ -257,7 +235,7 @@
i.initialize(servlet);
- verifyControls();
+ verify();
}
public void testNoAppSpec() throws Exception
@@ -266,11 +244,8 @@
ApplicationSpecificationInitializer i = new ApplicationSpecificationInitializer();
- MockControl contextControl = newControl(ServletContext.class);
- ServletContext context = (ServletContext) contextControl.getMock();
-
- MockControl logControl = newControl(Log.class);
- Log log = (Log) logControl.getMock();
+ ServletContext context = newMock(ServletContext.class);
+ Log log = newLog();
i.setLog(log);
@@ -281,48 +256,37 @@
HttpServlet servlet = new ServletFixture();
- MockControl configControl = newControl(ServletConfig.class);
- ServletConfig config = (ServletConfig) configControl.getMock();
+ ServletConfig config = newMock(ServletConfig.class);
- trainForServletInit(configControl, config);
+ trainForServletInit(config);
- config.getInitParameter(ApplicationSpecificationInitializer.APP_SPEC_PATH_PARAM);
- configControl.setReturnValue(null);
+ expect(config.getInitParameter(ApplicationSpecificationInitializer.APP_SPEC_PATH_PARAM)).andReturn(null);
- config.getServletContext();
- configControl.setReturnValue(context);
+ expect(config.getServletContext()).andReturn(context);
- config.getServletName();
- configControl.setReturnValue("wilma");
+ expect(config.getServletName()).andReturn("wilma");
- log.isDebugEnabled();
- logControl.setReturnValue(false);
+ expect(log.isDebugEnabled()).andReturn(false);
- context.getResource("/WEB-INF/wilma/wilma.application");
- contextControl.setReturnValue(null);
+ expect(context.getResource("/WEB-INF/wilma/wilma.application")).andReturn(null);
- log.isDebugEnabled();
- logControl.setReturnValue(false);
+ expect(log.isDebugEnabled()).andReturn(false);
- context.getResource("/WEB-INF/wilma.application");
- contextControl.setReturnValue(null);
+ expect(context.getResource("/WEB-INF/wilma.application")).andReturn(null);
- config.getServletName();
- configControl.setReturnValue("wilma");
+ expect(config.getServletName()).andReturn("wilma");
log.debug("Could not find an application specification for application servlet wilma.");
- config.getServletName();
- configControl.setReturnValue("wilma");
+ expect(config.getServletName()).andReturn("wilma");
- config.getServletContext();
- configControl.setReturnValue(context);
+ expect(config.getServletContext()).andReturn(context);
ApplicationGlobals ag = new ApplicationGlobalsImpl();
i.setGlobals(ag);
- replayControls();
+ replay();
servlet.init(config);
@@ -330,7 +294,7 @@
i.initialize(servlet);
- verifyControls();
+ verify();
IApplicationSpecification as = ag.getSpecification();
@@ -344,31 +308,25 @@
*/
public void testIntegration() throws Exception
{
- MockControl contextControl = newControl(ServletContext.class);
- ServletContext context = (ServletContext) contextControl.getMock();
+ ServletContext context = newMock(ServletContext.class);
HttpServlet servlet = new ServletFixture();
+
+ ServletConfig config = newMock(ServletConfig.class);
- // Create a non-strict control
- MockControl configControl = MockControl.createControl(ServletConfig.class);
- addControl(configControl);
- ServletConfig config = (ServletConfig) configControl.getMock();
-
- config.getInitParameter(ApplicationSpecificationInitializer.APP_SPEC_PATH_PARAM);
- configControl.setReturnValue(null);
+ expect(config.getInitParameter(ApplicationSpecificationInitializer.APP_SPEC_PATH_PARAM))
+ .andReturn(null);
- config.getServletContext();
- configControl.setReturnValue(context, 2);
+ expect(config.getServletContext()).andReturn(context).times(2);
- config.getServletName();
- configControl.setReturnValue("dino", 2);
+ expect(config.getServletName()).andReturn("dino").times(2);
context.log("dino: init");
- context.getResource("/WEB-INF/dino/dino.application");
- contextControl.setReturnValue(getClass().getResource("ParseApp.application"), 2);
+ expect(context.getResource("/WEB-INF/dino/dino.application"))
+ .andReturn(getClass().getResource("ParseApp.application")).times(2);
- replayControls();
+ replay();
servlet.init(config);
@@ -386,7 +344,7 @@
assertEquals("ParseApp", ag.getSpecification().getName());
- verifyControls();
+ verify();
}
}
Modified: tapestry/tapestry4/trunk/framework/src/test/org/apache/tapestry/services/impl/TestBaseTagWriter.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry4/trunk/framework/src/test/org/apache/tapestry/services/impl/TestBaseTagWriter.java?rev=417545&r1=417544&r2=417545&view=diff
==============================================================================
--- tapestry/tapestry4/trunk/framework/src/test/org/apache/tapestry/services/impl/TestBaseTagWriter.java (original)
+++ tapestry/tapestry4/trunk/framework/src/test/org/apache/tapestry/services/impl/TestBaseTagWriter.java Tue Jun 27 11:21:31 2006
@@ -14,12 +14,13 @@
package org.apache.tapestry.services.impl;
-import org.apache.hivemind.test.HiveMindTestCase;
+import static org.easymock.EasyMock.expect;
+
+import org.apache.tapestry.BaseComponentTestCase;
import org.apache.tapestry.IMarkupWriter;
import org.apache.tapestry.INamespace;
import org.apache.tapestry.IPage;
import org.apache.tapestry.IRequestCycle;
-import org.easymock.MockControl;
/**
* Tests for {@link org.apache.tapestry.services.impl.BaseTagWriter}.
@@ -27,11 +28,11 @@
* @author Howard M. Lewis Ship
* @since 4.0
*/
-public class TestBaseTagWriter extends HiveMindTestCase
+public class TestBaseTagWriter extends BaseComponentTestCase
{
private IMarkupWriter newWriter(String url)
{
- IMarkupWriter writer = (IMarkupWriter) newMock(IMarkupWriter.class);
+ IMarkupWriter writer = newMock(IMarkupWriter.class);
writer.beginEmpty("base");
writer.attribute("href", url);
@@ -43,32 +44,22 @@
private INamespace newNamespace(String id)
{
- MockControl control = newControl(INamespace.class);
- INamespace ns = (INamespace) control.getMock();
+ INamespace ns = newMock(INamespace.class);
- ns.getId();
- control.setReturnValue(id);
+ expect(ns.getId()).andReturn(id);
return ns;
}
- private IPage newPage(String pageName)
- {
- return newPage(newNamespace(null), pageName);
- }
-
private IPage newPage(INamespace ns, String pageName)
{
- MockControl control = newControl(IPage.class);
- IPage page = (IPage) control.getMock();
+ IPage page = newPage();
- page.getNamespace();
- control.setReturnValue(ns);
+ expect(page.getNamespace()).andReturn(ns);
if (pageName != null)
{
- page.getPageName();
- control.setReturnValue(pageName);
+ expect(page.getPageName()).andReturn(pageName);
}
return page;
@@ -76,25 +67,22 @@
private IRequestCycle newRequestCycle(IPage page, String url)
{
- MockControl control = newControl(IRequestCycle.class);
- IRequestCycle cycle = (IRequestCycle) control.getMock();
+ IRequestCycle cycle = newCycle();
- cycle.getPage();
- control.setReturnValue(page);
+ expect(cycle.getPage()).andReturn(page);
- cycle.getAbsoluteURL(url);
- control.setReturnValue("http://foo.com/context" + url);
+ expect(cycle.getAbsoluteURL(url)).andReturn("http://foo.com/context" + url);
return cycle;
}
private void run(IMarkupWriter writer, IRequestCycle cycle)
{
- replayControls();
-
+ replay();
+
new BaseTagWriter().render(writer, cycle);
- verifyControls();
+ verify();
}
public void testNotApplicationNamespace()
Modified: tapestry/tapestry4/trunk/framework/src/test/org/apache/tapestry/services/impl/TestBasicInfrastructure.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry4/trunk/framework/src/test/org/apache/tapestry/services/impl/TestBasicInfrastructure.java?rev=417545&r1=417544&r2=417545&view=diff
==============================================================================
--- tapestry/tapestry4/trunk/framework/src/test/org/apache/tapestry/services/impl/TestBasicInfrastructure.java (original)
+++ tapestry/tapestry4/trunk/framework/src/test/org/apache/tapestry/services/impl/TestBasicInfrastructure.java Tue Jun 27 11:21:31 2006
@@ -14,6 +14,10 @@
package org.apache.tapestry.services.impl;
+import static org.easymock.EasyMock.expect;
+import static org.testng.AssertJUnit.assertEquals;
+import static org.testng.AssertJUnit.assertSame;
+
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
@@ -23,13 +27,12 @@
import org.apache.hivemind.Registry;
import org.apache.hivemind.impl.DefaultClassResolver;
import org.apache.hivemind.impl.RegistryBuilder;
-import org.apache.hivemind.test.HiveMindTestCase;
import org.apache.hivemind.util.ClasspathResource;
+import org.apache.tapestry.BaseComponentTestCase;
import org.apache.tapestry.engine.IPropertySource;
import org.apache.tapestry.services.ClasspathResourceFactory;
import org.apache.tapestry.services.Infrastructure;
import org.apache.tapestry.services.ResetEventHub;
-import org.easymock.MockControl;
/**
* Tests for:
@@ -43,7 +46,7 @@
* @author Howard Lewis Ship
* @since 4.0
*/
-public class TestBasicInfrastructure extends HiveMindTestCase
+public class TestBasicInfrastructure extends BaseComponentTestCase
{
public void testRequestGlobals()
{
@@ -52,14 +55,14 @@
HttpServletRequest r = (HttpServletRequest) newMock(HttpServletRequest.class);
HttpServletResponse p = (HttpServletResponse) newMock(HttpServletResponse.class);
- replayControls();
+ replay();
si.store(r, p);
assertSame(r, si.getRequest());
assertSame(p, si.getResponse());
- verifyControls();
+ verify();
}
public void testClasspathResourceFactory()
@@ -97,37 +100,33 @@
public void testGlobalPropertyObjectProviderSuccess()
{
- MockControl sourceControl = newControl(IPropertySource.class);
- IPropertySource source = (IPropertySource) sourceControl.getMock();
+ IPropertySource source = newMock(IPropertySource.class);
// Training
- source.getPropertyValue("foo");
- sourceControl.setReturnValue("bar");
+ expect(source.getPropertyValue("foo")).andReturn("bar");
- replayControls();
+ replay();
PropertyObjectProvider p = new PropertyObjectProvider();
p.setSource(source);
assertEquals("bar", p.provideObject(null, null, "foo", null));
- verifyControls();
+ verify();
}
public void testGlobalPropertyObjectProviderFailure()
{
Location l = fabricateLocation(223);
- MockControl sourceControl = newControl(IPropertySource.class);
- IPropertySource source = (IPropertySource) sourceControl.getMock();
+ IPropertySource source = newMock(IPropertySource.class);
// Training
- source.getPropertyValue("foo");
- sourceControl.setThrowable(new ApplicationRuntimeException("failure"));
+ expect(source.getPropertyValue("foo")).andThrow(new ApplicationRuntimeException("failure"));
- replayControls();
+ replay();
PropertyObjectProvider p = new PropertyObjectProvider();
p.setSource(source);
@@ -142,20 +141,18 @@
assertEquals(l, ex.getLocation());
}
- verifyControls();
+ verify();
}
public void testSuccessfulInfrastructureLookup()
{
- MockControl ifrControl = newControl(Infrastructure.class);
- Infrastructure ifr = (Infrastructure) ifrControl.getMock();
+ Infrastructure ifr = newMock(Infrastructure.class);
ResetEventHub coord = (ResetEventHub) newMock(ResetEventHub.class);
- ifr.getResetEventHub();
- ifrControl.setReturnValue(coord);
+ expect(ifr.getResetEventHub()).andReturn(coord);
- replayControls();
+ replay();
InfrastructureObjectProvider p = new InfrastructureObjectProvider();
@@ -165,6 +162,6 @@
assertSame(coord, actual);
- verifyControls();
+ verify();
}
}
Modified: tapestry/tapestry4/trunk/framework/src/test/org/apache/tapestry/services/impl/TestBindingSource.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry4/trunk/framework/src/test/org/apache/tapestry/services/impl/TestBindingSource.java?rev=417545&r1=417544&r2=417545&view=diff
==============================================================================
--- tapestry/tapestry4/trunk/framework/src/test/org/apache/tapestry/services/impl/TestBindingSource.java (original)
+++ tapestry/tapestry4/trunk/framework/src/test/org/apache/tapestry/services/impl/TestBindingSource.java Tue Jun 27 11:21:31 2006
@@ -14,6 +14,9 @@
package org.apache.tapestry.services.impl;
+import static org.easymock.EasyMock.expect;
+import static org.testng.AssertJUnit.assertSame;
+
import java.util.Collections;
import org.apache.hivemind.Location;
@@ -44,10 +47,9 @@
// Training
- factory.createBinding(component, "foo", "a literal value without a prefix", l);
- setReturnValue(factory,binding);
+ expect(factory.createBinding(component, "foo", "a literal value without a prefix", l)).andReturn(binding);
- replayControls();
+ replay();
BindingSourceImpl bs = new BindingSourceImpl();
bs.setContributions(Collections.singletonList(c));
@@ -63,7 +65,7 @@
assertSame(binding, actual);
- verifyControls();
+ verify();
}
public void testNoPrefixWithDefault()
@@ -75,14 +77,13 @@
// Training
- factory.createBinding(component, "foo", "an-expression", l);
- setReturnValue(factory,binding);
+ expect(factory.createBinding(component, "foo", "an-expression", l)).andReturn(binding);
BindingPrefixContribution c = new BindingPrefixContribution();
c.setPrefix(BindingConstants.OGNL_PREFIX);
c.setFactory(factory);
- replayControls();
+ replay();
BindingSourceImpl bs = new BindingSourceImpl();
bs.setContributions(Collections.singletonList(c));
@@ -97,7 +98,7 @@
assertSame(binding, actual);
- verifyControls();
+ verify();
}
public void testKnownPrefix()
@@ -109,14 +110,13 @@
// Training
- factory.createBinding(component, "bar", "path part of locator", l);
- setReturnValue(factory,binding);
+ expect(factory.createBinding(component, "bar", "path part of locator", l)).andReturn(binding);
BindingPrefixContribution c = new BindingPrefixContribution();
c.setPrefix("prefix");
c.setFactory(factory);
- replayControls();
+ replay();
BindingSourceImpl bs = new BindingSourceImpl();
bs.setContributions(Collections.singletonList(c));
@@ -132,7 +132,7 @@
assertSame(binding, actual);
- verifyControls();
+ verify();
}
public void testPrefixNoMatch()
@@ -144,14 +144,13 @@
// Training
- factory.createBinding(component, "zip", "unknown:path part of locator", l);
- setReturnValue(factory,binding);
+ expect(factory.createBinding(component, "zip", "unknown:path part of locator", l)).andReturn(binding);
BindingPrefixContribution c = new BindingPrefixContribution();
c.setPrefix(BindingConstants.LITERAL_PREFIX);
c.setFactory(factory);
- replayControls();
+ replay();
BindingSourceImpl bs = new BindingSourceImpl();
bs.setContributions(Collections.singletonList(c));
@@ -167,7 +166,7 @@
assertSame(binding, actual);
- verifyControls();
+ verify();
}
protected BindingFactory newFactory()
Modified: tapestry/tapestry4/trunk/framework/src/test/org/apache/tapestry/services/impl/TestDeferredObjectTranslator.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry4/trunk/framework/src/test/org/apache/tapestry/services/impl/TestDeferredObjectTranslator.java?rev=417545&r1=417544&r2=417545&view=diff
==============================================================================
--- tapestry/tapestry4/trunk/framework/src/test/org/apache/tapestry/services/impl/TestDeferredObjectTranslator.java (original)
+++ tapestry/tapestry4/trunk/framework/src/test/org/apache/tapestry/services/impl/TestDeferredObjectTranslator.java Tue Jun 27 11:21:31 2006
@@ -14,11 +14,13 @@
package org.apache.tapestry.services.impl;
+import static org.easymock.EasyMock.expect;
+import static org.testng.AssertJUnit.assertSame;
+
import org.apache.hivemind.Location;
import org.apache.hivemind.internal.Module;
import org.apache.hivemind.schema.Translator;
-import org.apache.hivemind.test.HiveMindTestCase;
-import org.easymock.MockControl;
+import org.apache.tapestry.BaseComponentTestCase;
/**
* Tests for {@link org.apache.tapestry.services.impl.DeferredObjectImpl} and
@@ -27,7 +29,7 @@
* @author Howard M. Lewis Ship
* @since 4.0
*/
-public class TestDeferredObjectTranslator extends HiveMindTestCase
+public class TestDeferredObjectTranslator extends BaseComponentTestCase
{
private Module newModule()
{
@@ -37,11 +39,9 @@
private Translator newTranslator(Module module, String objectReference, Location location,
Object result)
{
- MockControl control = newControl(Translator.class);
- Translator translator = (Translator) control.getMock();
+ Translator translator = newMock(Translator.class);
- translator.translate(module, Object.class, objectReference, location);
- control.setReturnValue(result);
+ expect(translator.translate(module, Object.class, objectReference, location)).andReturn(result);
return translator;
}
@@ -53,7 +53,7 @@
Location l = newLocation();
Translator translator = newTranslator(module, "OBJ-REFERENCE", l, object);
- replayControls();
+ replay();
DeferredObject deferred = new DeferredObjectImpl(translator, module, "OBJ-REFERENCE", l);
@@ -63,7 +63,7 @@
assertSame(object, deferred.getObject());
- verifyControls();
+ verify();
assertSame(l, deferred.getLocation());
}
@@ -75,7 +75,7 @@
Location l = newLocation();
Translator objectTranslator = newTranslator(module, "OBJ-REFERENCE", l, object);
- replayControls();
+ replay();
DeferredObjectTranslator translator = new DeferredObjectTranslator();
translator.setObjectTranslator(objectTranslator);
@@ -92,7 +92,7 @@
assertSame(object, deferred.getObject());
- verifyControls();
+ verify();
assertSame(l, deferred.getLocation());
}
Modified: tapestry/tapestry4/trunk/framework/src/test/org/apache/tapestry/services/impl/TestDisableCachingFilter.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry4/trunk/framework/src/test/org/apache/tapestry/services/impl/TestDisableCachingFilter.java?rev=417545&r1=417544&r2=417545&view=diff
==============================================================================
--- tapestry/tapestry4/trunk/framework/src/test/org/apache/tapestry/services/impl/TestDisableCachingFilter.java (original)
+++ tapestry/tapestry4/trunk/framework/src/test/org/apache/tapestry/services/impl/TestDisableCachingFilter.java Tue Jun 27 11:21:31 2006
@@ -14,15 +14,16 @@
package org.apache.tapestry.services.impl;
+import static org.easymock.EasyMock.expectLastCall;
+
import org.apache.hivemind.ApplicationRuntimeException;
import org.apache.hivemind.ErrorLog;
import org.apache.hivemind.Location;
-import org.apache.hivemind.test.HiveMindTestCase;
+import org.apache.tapestry.BaseComponentTestCase;
import org.apache.tapestry.services.ResetEventHub;
import org.apache.tapestry.services.WebRequestServicer;
import org.apache.tapestry.web.WebRequest;
import org.apache.tapestry.web.WebResponse;
-import org.easymock.MockControl;
/**
* Tests for {@link org.apache.tapestry.services.impl.DisableCachingFilter}.
@@ -30,13 +31,8 @@
* @author Howard M. Lewis Ship
* @since 4.0
*/
-public class TestDisableCachingFilter extends HiveMindTestCase
+public class TestDisableCachingFilter extends BaseComponentTestCase
{
- private WebRequest newRequest()
- {
- return (WebRequest) newMock(WebRequest.class);
- }
-
private WebResponse newResponse()
{
return (WebResponse) newMock(WebResponse.class);
@@ -62,14 +58,14 @@
servicer.service(request, response);
rec.fireResetEvent();
- replayControls();
+ replay();
DisableCachingFilter f = new DisableCachingFilter();
f.setResetEventHub(rec);
f.service(request, response, servicer);
- verifyControls();
+ verify();
}
public void testResetFailure() throws Exception
@@ -77,8 +73,8 @@
WebRequest request = newRequest();
WebResponse response = newResponse();
WebRequestServicer servicer = newServicer();
- MockControl control = newControl(ResetEventHub.class);
- ResetEventHub rec = (ResetEventHub) control.getMock();
+
+ ResetEventHub rec = newMock(ResetEventHub.class);
ErrorLog log = (ErrorLog) newMock(ErrorLog.class);
Location l = fabricateLocation(99);
@@ -88,11 +84,11 @@
servicer.service(request, response);
rec.fireResetEvent();
- control.setThrowable(t);
+ expectLastCall().andThrow(t);
log.error(ImplMessages.errorResetting(t), l, t);
- replayControls();
+ replay();
DisableCachingFilter f = new DisableCachingFilter();
f.setResetEventHub(rec);
@@ -100,7 +96,7 @@
f.service(request, response, servicer);
- verifyControls();
+ verify();
}
}
Modified: tapestry/tapestry4/trunk/framework/src/test/org/apache/tapestry/services/impl/TestEngineManager.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry4/trunk/framework/src/test/org/apache/tapestry/services/impl/TestEngineManager.java?rev=417545&r1=417544&r2=417545&view=diff
==============================================================================
--- tapestry/tapestry4/trunk/framework/src/test/org/apache/tapestry/services/impl/TestEngineManager.java (original)
+++ tapestry/tapestry4/trunk/framework/src/test/org/apache/tapestry/services/impl/TestEngineManager.java Tue Jun 27 11:21:31 2006
@@ -14,14 +14,16 @@
package org.apache.tapestry.services.impl;
+import static org.easymock.EasyMock.expect;
+import static org.testng.AssertJUnit.assertSame;
+
import java.util.Locale;
-import org.apache.hivemind.test.HiveMindTestCase;
+import org.apache.tapestry.BaseComponentTestCase;
import org.apache.tapestry.IEngine;
import org.apache.tapestry.services.EngineFactory;
import org.apache.tapestry.services.ObjectPool;
import org.apache.tapestry.services.RequestLocaleManager;
-import org.easymock.MockControl;
/**
* Tests for {@link org.apache.tapestry.services.impl.EngineManagerImpl}.
@@ -29,29 +31,24 @@
* @author Howard Lewis Ship
* @since 4.0
*/
-public class TestEngineManager extends HiveMindTestCase
+public class TestEngineManager extends BaseComponentTestCase
{
public void testGetFromPool()
{
-
- MockControl extractorControl = newControl(RequestLocaleManager.class);
- RequestLocaleManager extractor = (RequestLocaleManager) extractorControl.getMock();
-
- MockControl poolControl = newControl(ObjectPool.class);
- ObjectPool pool = (ObjectPool) poolControl.getMock();
+ RequestLocaleManager extractor = newMock(RequestLocaleManager.class);
+
+ ObjectPool pool = newMock(ObjectPool.class);
// Training
- extractor.extractLocaleForCurrentRequest();
- extractorControl.setReturnValue(Locale.CHINESE);
+ expect(extractor.extractLocaleForCurrentRequest()).andReturn(Locale.CHINESE);
- IEngine engine = (IEngine) newMock(IEngine.class);
+ IEngine engine = newMock(IEngine.class);
- pool.get(Locale.CHINESE);
- poolControl.setReturnValue(engine);
+ expect(pool.get(Locale.CHINESE)).andReturn(engine);
- replayControls();
+ replay();
EngineManagerImpl m = new EngineManagerImpl();
@@ -62,35 +59,28 @@
assertSame(engine, actual);
- verifyControls();
+ verify();
}
public void testGetNotInPool()
{
-
- MockControl extractorControl = newControl(RequestLocaleManager.class);
- RequestLocaleManager extractor = (RequestLocaleManager) extractorControl.getMock();
-
- MockControl poolControl = newControl(ObjectPool.class);
- ObjectPool pool = (ObjectPool) poolControl.getMock();
+ RequestLocaleManager extractor = newMock(RequestLocaleManager.class);
+
+ ObjectPool pool = newMock(ObjectPool.class);
// Training
- extractor.extractLocaleForCurrentRequest();
- extractorControl.setReturnValue(Locale.CHINESE);
-
- IEngine engine = (IEngine) newMock(IEngine.class);
+ expect(extractor.extractLocaleForCurrentRequest()).andReturn(Locale.CHINESE);
- pool.get(Locale.CHINESE);
- poolControl.setReturnValue(null);
+ IEngine engine = newMock(IEngine.class);
- MockControl factoryControl = newControl(EngineFactory.class);
- EngineFactory factory = (EngineFactory) factoryControl.getMock();
+ expect(pool.get(Locale.CHINESE)).andReturn(null);
+
+ EngineFactory factory = newMock(EngineFactory.class);
- factory.constructNewEngineInstance(Locale.CHINESE);
- factoryControl.setReturnValue(engine);
+ expect(factory.constructNewEngineInstance(Locale.CHINESE)).andReturn(engine);
- replayControls();
+ replay();
EngineManagerImpl m = new EngineManagerImpl();
@@ -102,25 +92,22 @@
assertSame(engine, actual);
- verifyControls();
+ verify();
}
public void testStoreNoSession()
{
+ IEngine engine = newMock(IEngine.class);
- MockControl engineControl = newControl(IEngine.class);
- IEngine engine = (IEngine) engineControl.getMock();
-
- ObjectPool pool = (ObjectPool) newMock(ObjectPool.class);
+ ObjectPool pool = newMock(ObjectPool.class);
// Training
- engine.getLocale();
- engineControl.setReturnValue(Locale.KOREAN);
+ expect(engine.getLocale()).andReturn(Locale.KOREAN);
pool.store(Locale.KOREAN, engine);
- replayControls();
+ replay();
EngineManagerImpl m = new EngineManagerImpl();
@@ -128,7 +115,7 @@
m.storeEngineInstance(engine);
- verifyControls();
+ verify();
}
}
Modified: tapestry/tapestry4/trunk/framework/src/test/org/apache/tapestry/services/impl/TestEngineServiceObjectProvider.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry4/trunk/framework/src/test/org/apache/tapestry/services/impl/TestEngineServiceObjectProvider.java?rev=417545&r1=417544&r2=417545&view=diff
==============================================================================
--- tapestry/tapestry4/trunk/framework/src/test/org/apache/tapestry/services/impl/TestEngineServiceObjectProvider.java (original)
+++ tapestry/tapestry4/trunk/framework/src/test/org/apache/tapestry/services/impl/TestEngineServiceObjectProvider.java Tue Jun 27 11:21:31 2006
@@ -14,29 +14,29 @@
package org.apache.tapestry.services.impl;
-import org.apache.hivemind.test.HiveMindTestCase;
+import static org.easymock.EasyMock.expect;
+import static org.testng.AssertJUnit.assertSame;
+
+import org.apache.tapestry.BaseComponentTestCase;
import org.apache.tapestry.engine.IEngineService;
import org.apache.tapestry.services.ServiceMap;
-import org.easymock.MockControl;
/**
* Tests for {@link org.apache.tapestry.services.impl.EngineServiceObjectProvider}.
*
* @author Howard M. Lewis Ship
*/
-public class TestEngineServiceObjectProvider extends HiveMindTestCase
+public class TestEngineServiceObjectProvider extends BaseComponentTestCase
{
public void testProvideObject()
{
- MockControl mapControl = newControl(ServiceMap.class);
- ServiceMap map = (ServiceMap) mapControl.getMock();
+ ServiceMap map = newMock(ServiceMap.class);
- IEngineService service = (IEngineService) newMock(IEngineService.class);
+ IEngineService service = newMock(IEngineService.class);
- map.getService("page");
- mapControl.setReturnValue(service);
+ expect(map.getService("page")).andReturn(service);
- replayControls();
+ replay();
EngineServiceObjectProvider p = new EngineServiceObjectProvider();
@@ -44,6 +44,6 @@
assertSame(service, p.provideObject(null, null, "page", null));
- verifyControls();
+ verify();
}
}
Modified: tapestry/tapestry4/trunk/framework/src/test/org/apache/tapestry/services/impl/TestExpressionEvaluator.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry4/trunk/framework/src/test/org/apache/tapestry/services/impl/TestExpressionEvaluator.java?rev=417545&r1=417544&r2=417545&view=diff
==============================================================================
--- tapestry/tapestry4/trunk/framework/src/test/org/apache/tapestry/services/impl/TestExpressionEvaluator.java (original)
+++ tapestry/tapestry4/trunk/framework/src/test/org/apache/tapestry/services/impl/TestExpressionEvaluator.java Tue Jun 27 11:21:31 2006
@@ -14,26 +14,32 @@
package org.apache.tapestry.services.impl;
+import static org.easymock.EasyMock.eq;
+import static org.easymock.EasyMock.expect;
+import static org.easymock.EasyMock.isA;
+import static org.testng.AssertJUnit.assertEquals;
+import static org.testng.AssertJUnit.assertSame;
+
import java.lang.reflect.Method;
import java.util.Collections;
import java.util.Date;
+import java.util.Map;
import ognl.TypeConverter;
import org.apache.hivemind.ApplicationRuntimeException;
-import org.apache.hivemind.test.HiveMindTestCase;
+import org.apache.tapestry.BaseComponentTestCase;
import org.apache.tapestry.Tapestry;
import org.apache.tapestry.services.ExpressionCache;
import org.apache.tapestry.services.ExpressionEvaluator;
import org.apache.tapestry.spec.IApplicationSpecification;
import org.easymock.AbstractMatcher;
-import org.easymock.MockControl;
/**
* @author Howard M. Lewis Ship
* @since 4.0
*/
-public class TestExpressionEvaluator extends HiveMindTestCase
+public class TestExpressionEvaluator extends BaseComponentTestCase
{
private ExpressionEvaluatorImpl create()
{
@@ -152,7 +158,7 @@
ee.setContributions(Collections.EMPTY_LIST);
ee.setNullHandlerContributions(Collections.EMPTY_LIST);
- replayControls();
+ replay();
ee.initializeService();
@@ -162,16 +168,14 @@
assertEquals(false, ee.isConstant("bar()"));
assertEquals(true, ee.isConstant("@org.apache.tapestry.Tapestry@HOME_SERVICE"));
- verifyControls();
+ verify();
}
private IApplicationSpecification newAppSpec()
{
- MockControl control = newControl(IApplicationSpecification.class);
- IApplicationSpecification spec = (IApplicationSpecification) control.getMock();
+ IApplicationSpecification spec = newMock(IApplicationSpecification.class);
- spec.checkExtension(Tapestry.OGNL_TYPE_CONVERTER);
- control.setReturnValue(false);
+ expect(spec.checkExtension(Tapestry.OGNL_TYPE_CONVERTER)).andReturn(false);
return spec;
}
@@ -194,21 +198,17 @@
public void testTypeConverter() throws Exception
{
- MockControl asc = newControl(IApplicationSpecification.class);
- IApplicationSpecification as = (IApplicationSpecification) asc.getMock();
-
- MockControl tcc = newControl(TypeConverter.class);
- TypeConverter tc = (TypeConverter) tcc.getMock();
+ IApplicationSpecification as = newMock(IApplicationSpecification.class);
+
+ TypeConverter tc = newMock(TypeConverter.class);
// Training
- as.checkExtension(Tapestry.OGNL_TYPE_CONVERTER);
- asc.setReturnValue(true);
+ expect(as.checkExtension(Tapestry.OGNL_TYPE_CONVERTER)).andReturn(true);
- as.getExtension(Tapestry.OGNL_TYPE_CONVERTER, TypeConverter.class);
- asc.setReturnValue(tc);
+ expect(as.getExtension(Tapestry.OGNL_TYPE_CONVERTER, TypeConverter.class)).andReturn(tc);
- replayControls();
+ replay();
ExpressionCache cache = new ExpressionCacheImpl();
@@ -221,7 +221,7 @@
ee.initializeService();
- verifyControls();
+ verify();
Fixture f = new Fixture();
@@ -234,17 +234,15 @@
// Since we have no idea what OGNL will stuff into that Map parameter,
// we just ignore it.
- tc.convertValue(null, f, m, "value", d, String.class);
- tcc.setMatcher(new NullMeansIgnoreMatcher());
-
- tcc.setReturnValue("FROM-TYPE-CONVERTER");
+ expect(tc.convertValue(isA(Map.class), eq(f), eq(m), eq("value"), eq(d), eq(String.class)))
+ .andReturn("FROM-TYPE-CONVERTER");
- replayControls();
+ replay();
ee.write(f, "value", d);
assertEquals("FROM-TYPE-CONVERTER", f.getValue());
- verifyControls();
+ verify();
}
}
Modified: tapestry/tapestry4/trunk/framework/src/test/org/apache/tapestry/services/impl/TestExtensionLookupFactory.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry4/trunk/framework/src/test/org/apache/tapestry/services/impl/TestExtensionLookupFactory.java?rev=417545&r1=417544&r2=417545&view=diff
==============================================================================
--- tapestry/tapestry4/trunk/framework/src/test/org/apache/tapestry/services/impl/TestExtensionLookupFactory.java (original)
+++ tapestry/tapestry4/trunk/framework/src/test/org/apache/tapestry/services/impl/TestExtensionLookupFactory.java Tue Jun 27 11:21:31 2006
@@ -14,6 +14,9 @@
package org.apache.tapestry.services.impl;
+import static org.easymock.EasyMock.expect;
+import static org.testng.AssertJUnit.assertSame;
+
import java.util.Collections;
import java.util.List;
@@ -21,9 +24,8 @@
import org.apache.hivemind.Location;
import org.apache.hivemind.ServiceImplementationFactoryParameters;
import org.apache.hivemind.lib.DefaultImplementationBuilder;
-import org.apache.hivemind.test.HiveMindTestCase;
+import org.apache.tapestry.BaseComponentTestCase;
import org.apache.tapestry.spec.IApplicationSpecification;
-import org.easymock.MockControl;
/**
* Tests {@link org.apache.tapestry.services.impl.ExtensionLookupFactory}.
@@ -31,7 +33,7 @@
* @author Howard Lewis Ship
* @since 4.0
*/
-public class TestExtensionLookupFactory extends HiveMindTestCase
+public class TestExtensionLookupFactory extends BaseComponentTestCase
{
private List createParameters(String extensionName)
{
@@ -50,30 +52,23 @@
public void testInSpecification()
{
- MockControl specControl = newControl(IApplicationSpecification.class);
- IApplicationSpecification spec = (IApplicationSpecification) specControl.getMock();
-
- Runnable r = (Runnable) newMock(Runnable.class);
+ IApplicationSpecification spec = newMock(IApplicationSpecification.class);
- MockControl fpc = newControl(ServiceImplementationFactoryParameters.class);
- ServiceImplementationFactoryParameters fp = (ServiceImplementationFactoryParameters) fpc
- .getMock();
+ Runnable r = newMock(Runnable.class);
+
+ ServiceImplementationFactoryParameters fp = newMock(ServiceImplementationFactoryParameters.class);
// Training
- fp.getParameters();
- fpc.setReturnValue(createParameters("foo.bar"));
+ expect(fp.getParameters()).andReturn(createParameters("foo.bar"));
- fp.getServiceInterface();
- fpc.setReturnValue(Runnable.class);
+ expect(fp.getServiceInterface()).andReturn(Runnable.class);
- spec.checkExtension("foo.bar");
- specControl.setReturnValue(true);
+ expect(spec.checkExtension("foo.bar")).andReturn(true);
- spec.getExtension("foo.bar", Runnable.class);
- specControl.setReturnValue(r);
+ expect(spec.getExtension("foo.bar", Runnable.class)).andReturn(r);
- replayControls();
+ replay();
ExtensionLookupFactory f = new ExtensionLookupFactory();
f.setSpecification(spec);
@@ -82,38 +77,30 @@
assertSame(r, actual);
- verifyControls();
+ verify();
}
public void testSyntheticDefault()
{
- MockControl specControl = newControl(IApplicationSpecification.class);
- IApplicationSpecification spec = (IApplicationSpecification) specControl.getMock();
+ IApplicationSpecification spec = newMock(IApplicationSpecification.class);
+
+ DefaultImplementationBuilder dib = newMock(DefaultImplementationBuilder.class);
- MockControl dibControl = newControl(DefaultImplementationBuilder.class);
- DefaultImplementationBuilder dib = (DefaultImplementationBuilder) dibControl.getMock();
+ Runnable r = newMock(Runnable.class);
- Runnable r = (Runnable) newMock(Runnable.class);
-
- MockControl fpc = newControl(ServiceImplementationFactoryParameters.class);
- ServiceImplementationFactoryParameters fp = (ServiceImplementationFactoryParameters) fpc
- .getMock();
+ ServiceImplementationFactoryParameters fp = newMock(ServiceImplementationFactoryParameters.class);
// Training
- fp.getParameters();
- fpc.setReturnValue(createParameters("foo.bar"));
-
- fp.getServiceInterface();
- fpc.setReturnValue(Runnable.class);
+ expect(fp.getParameters()).andReturn(createParameters("foo.bar"));
- spec.checkExtension("foo.bar");
- specControl.setReturnValue(false);
+ expect(fp.getServiceInterface()).andReturn(Runnable.class);
+
+ expect(spec.checkExtension("foo.bar")).andReturn(false);
- dib.buildDefaultImplementation(Runnable.class);
- dibControl.setReturnValue(r);
+ expect(dib.buildDefaultImplementation(Runnable.class)).andReturn(r);
- replayControls();
+ replay();
ExtensionLookupFactory f = new ExtensionLookupFactory();
f.setSpecification(spec);
@@ -123,32 +110,26 @@
assertSame(r, actual);
- verifyControls();
+ verify();
}
public void testConfigurationDefault()
{
- MockControl specControl = newControl(IApplicationSpecification.class);
- IApplicationSpecification spec = (IApplicationSpecification) specControl.getMock();
+ IApplicationSpecification spec = newMock(IApplicationSpecification.class);
- Runnable r = (Runnable) newMock(Runnable.class);
+ Runnable r = newMock(Runnable.class);
- MockControl fpc = newControl(ServiceImplementationFactoryParameters.class);
- ServiceImplementationFactoryParameters fp = (ServiceImplementationFactoryParameters) fpc
- .getMock();
+ ServiceImplementationFactoryParameters fp = newMock(ServiceImplementationFactoryParameters.class);
// Training
- fp.getParameters();
- fpc.setReturnValue(createParameters("foo.bar", r));
+ expect(fp.getParameters()).andReturn(createParameters("foo.bar", r));
- fp.getServiceInterface();
- fpc.setReturnValue(Runnable.class);
+ expect(fp.getServiceInterface()).andReturn(Runnable.class);
- spec.checkExtension("foo.bar");
- specControl.setReturnValue(false);
+ expect(spec.checkExtension("foo.bar")).andReturn(false);
- replayControls();
+ replay();
ExtensionLookupFactory f = new ExtensionLookupFactory();
f.setSpecification(spec);
@@ -157,7 +138,7 @@
assertSame(r, actual);
- verifyControls();
+ verify();
}
public void testFailure()
@@ -168,19 +149,15 @@
p.setLocation(l);
p.setExtensionName("gnip.gnop");
- MockControl fpc = newControl(ServiceImplementationFactoryParameters.class);
- ServiceImplementationFactoryParameters fp = (ServiceImplementationFactoryParameters) fpc
- .getMock();
+ ServiceImplementationFactoryParameters fp = newMock(ServiceImplementationFactoryParameters.class);
- fp.getParameters();
- fpc.setReturnValue(Collections.singletonList(p));
+ expect(fp.getParameters()).andReturn(Collections.singletonList(p));
- fp.getServiceInterface();
- fpc.setReturnValue(null);
+ expect(fp.getServiceInterface()).andReturn(null);
ExtensionLookupFactory f = new ExtensionLookupFactory();
- replayControls();
+ replay();
try
{
@@ -193,6 +170,6 @@
assertSame(l, ex.getLocation());
}
- verifyControls();
+ verify();
}
}
Modified: tapestry/tapestry4/trunk/framework/src/test/org/apache/tapestry/services/impl/TestInfrastructure.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry4/trunk/framework/src/test/org/apache/tapestry/services/impl/TestInfrastructure.java?rev=417545&r1=417544&r2=417545&view=diff
==============================================================================
--- tapestry/tapestry4/trunk/framework/src/test/org/apache/tapestry/services/impl/TestInfrastructure.java (original)
+++ tapestry/tapestry4/trunk/framework/src/test/org/apache/tapestry/services/impl/TestInfrastructure.java Tue Jun 27 11:21:31 2006
@@ -14,6 +14,9 @@
package org.apache.tapestry.services.impl;
+import static org.testng.AssertJUnit.assertEquals;
+import static org.testng.AssertJUnit.assertSame;
+
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
@@ -21,7 +24,7 @@
import org.apache.hivemind.ApplicationRuntimeException;
import org.apache.hivemind.ErrorLog;
import org.apache.hivemind.Location;
-import org.apache.hivemind.test.HiveMindTestCase;
+import org.apache.tapestry.BaseComponentTestCase;
/**
* Tests for {@link org.apache.tapestry.services.impl.InfrastructureImpl}.
@@ -29,7 +32,7 @@
* @author Howard M. Lewis Ship
* @since 4.0
*/
-public class TestInfrastructure extends HiveMindTestCase
+public class TestInfrastructure extends BaseComponentTestCase
{
private static class DeferredObjectFixture implements DeferredObject
{
@@ -215,7 +218,7 @@
log.error(ImplMessages.duplicateInfrastructureContribution(conflict, l1), l2, null);
- replayControls();
+ replay();
InfrastructureImpl infra = new InfrastructureImpl();
infra.setNormalContributions(l);
@@ -226,6 +229,6 @@
assertSame(fredModal, infra.getProperty("fred"));
- verifyControls();
+ verify();
}
}
Modified: tapestry/tapestry4/trunk/framework/src/test/org/apache/tapestry/services/impl/TestLocalizedPropertySource.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry4/trunk/framework/src/test/org/apache/tapestry/services/impl/TestLocalizedPropertySource.java?rev=417545&r1=417544&r2=417545&view=diff
==============================================================================
--- tapestry/tapestry4/trunk/framework/src/test/org/apache/tapestry/services/impl/TestLocalizedPropertySource.java (original)
+++ tapestry/tapestry4/trunk/framework/src/test/org/apache/tapestry/services/impl/TestLocalizedPropertySource.java Tue Jun 27 11:21:31 2006
@@ -14,11 +14,14 @@
package org.apache.tapestry.services.impl;
+import static org.easymock.EasyMock.expect;
+import static org.testng.AssertJUnit.assertEquals;
+import static org.testng.AssertJUnit.assertNull;
+
import java.util.Locale;
-import org.apache.hivemind.test.HiveMindTestCase;
+import org.apache.tapestry.BaseComponentTestCase;
import org.apache.tapestry.engine.IPropertySource;
-import org.easymock.MockControl;
/**
* Tests for {@link org.apache.tapestry.services.impl.LocalizedPropertySource}.
@@ -26,20 +29,17 @@
* @author Howard M. Lewis Ship
* @since 4.0
*/
-public class TestLocalizedPropertySource extends HiveMindTestCase
+public class TestLocalizedPropertySource extends BaseComponentTestCase
{
public void testFound()
{
- MockControl control = newControl(IPropertySource.class);
- IPropertySource ps = (IPropertySource) control.getMock();
+ IPropertySource ps = newMock(IPropertySource.class);
- ps.getPropertyValue("property-name_en");
- control.setReturnValue(null);
+ expect(ps.getPropertyValue("property-name_en")).andReturn(null);
- ps.getPropertyValue("property-name");
- control.setReturnValue("fred");
+ expect(ps.getPropertyValue("property-name")).andReturn("fred");
- replayControls();
+ replay();
LocalizedPropertySource lps = new LocalizedPropertySource(ps);
@@ -47,26 +47,23 @@
assertEquals("fred", result);
- verifyControls();
+ verify();
}
public void testNotFound()
{
- MockControl control = newControl(IPropertySource.class);
- IPropertySource ps = (IPropertySource) control.getMock();
+ IPropertySource ps = newMock(IPropertySource.class);
- ps.getPropertyValue("property-name_fr");
- control.setReturnValue(null);
+ expect(ps.getPropertyValue("property-name_fr")).andReturn(null);
- ps.getPropertyValue("property-name");
- control.setReturnValue(null);
+ expect(ps.getPropertyValue("property-name")).andReturn(null);
- replayControls();
+ replay();
LocalizedPropertySource lps = new LocalizedPropertySource(ps);
assertNull(lps.getPropertyValue("property-name", Locale.FRENCH));
- verifyControls();
+ verify();
}
}
Modified: tapestry/tapestry4/trunk/framework/src/test/org/apache/tapestry/services/impl/TestNamespaceResources.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry4/trunk/framework/src/test/org/apache/tapestry/services/impl/TestNamespaceResources.java?rev=417545&r1=417544&r2=417545&view=diff
==============================================================================
--- tapestry/tapestry4/trunk/framework/src/test/org/apache/tapestry/services/impl/TestNamespaceResources.java (original)
+++ tapestry/tapestry4/trunk/framework/src/test/org/apache/tapestry/services/impl/TestNamespaceResources.java Tue Jun 27 11:21:31 2006
@@ -14,11 +14,14 @@
package org.apache.tapestry.services.impl;
+import static org.easymock.EasyMock.expect;
+import static org.testng.AssertJUnit.assertSame;
+
import java.net.URL;
import org.apache.hivemind.Location;
import org.apache.hivemind.Resource;
-import org.apache.hivemind.test.HiveMindTestCase;
+import org.apache.tapestry.BaseComponentTestCase;
import org.apache.tapestry.IAsset;
import org.apache.tapestry.asset.AssetSource;
import org.apache.tapestry.engine.ISpecificationSource;
@@ -32,7 +35,7 @@
* @author Howard M. Lewis Ship
* @since 4.0
*/
-public class TestNamespaceResources extends HiveMindTestCase
+public class TestNamespaceResources extends BaseComponentTestCase
{
protected Resource newResource()
{
@@ -41,14 +44,12 @@
protected void trainGetRelativeResource(Resource parent, String path, Resource child)
{
- parent.getRelativeResource(path);
- setReturnValue(parent,child);
+ expect(parent.getRelativeResource(path)).andReturn(child);
}
protected void trainGetResourceURL(Resource resource, URL url)
{
- resource.getResourceURL();
- setReturnValue(resource,url);
+ expect(resource.getResourceURL()).andReturn(url);
}
protected ISpecificationSource newSource()
@@ -56,7 +57,7 @@
return (ISpecificationSource) newMock(ISpecificationSource.class);
}
- protected ILibrarySpecification newSpec()
+ protected ILibrarySpecification newLSpec()
{
return (ILibrarySpecification) newMock(ILibrarySpecification.class);
}
@@ -71,7 +72,7 @@
Resource parent = newResource();
Resource child = newResource();
ISpecificationSource source = newSource();
- ILibrarySpecification spec = newSpec();
+ ILibrarySpecification spec = newLSpec();
AssetSource assetSource = newAssetSource();
Location l = newLocation();
@@ -79,13 +80,13 @@
trainGetLibrarySpecification(source, child, spec);
- replayControls();
+ replay();
NamespaceResources nr = new NamespaceResourcesImpl(source, assetSource);
assertSame(spec, nr.findChildLibrarySpecification(parent, "foo/bar.library", l));
- verifyControls();
+ verify();
}
@@ -94,11 +95,9 @@
{
IAsset asset = newAsset();
- assetSource.findAsset(parent, childPath, null, location);
- setReturnValue(assetSource,asset);
+ expect(assetSource.findAsset(parent, childPath, null, location)).andReturn(asset);
- asset.getResourceLocation();
- setReturnValue(asset,child);
+ expect(asset.getResourceLocation()).andReturn(child);
}
protected IAsset newAsset()
@@ -114,8 +113,7 @@
protected void trainGetLibrarySpecification(ISpecificationSource source, Resource resource,
ILibrarySpecification spec)
{
- source.getLibrarySpecification(resource);
- setReturnValue(source,spec);
+ expect(source.getLibrarySpecification(resource)).andReturn(spec);
}
protected IComponentSpecification newComponentSpec()
@@ -134,16 +132,15 @@
trainResolveChildResource(assetSource, libraryResource, "Foo.page", l, specResource);
- source.getPageSpecification(specResource);
- setReturnValue(source,spec);
+ expect(source.getPageSpecification(specResource)).andReturn(spec);
- replayControls();
+ replay();
NamespaceResources nr = new NamespaceResourcesImpl(source, assetSource);
assertSame(spec, nr.getPageSpecification(libraryResource, "Foo.page", l));
- verifyControls();
+ verify();
}
public void testGetComponentSpecification()
@@ -157,15 +154,14 @@
trainResolveChildResource(assetSource, libraryResource, "Foo.jwc", l, specResource);
- source.getComponentSpecification(specResource);
- setReturnValue(source,spec);
+ expect(source.getComponentSpecification(specResource)).andReturn(spec);
- replayControls();
+ replay();
NamespaceResources nr = new NamespaceResourcesImpl(source, assetSource);
assertSame(spec, nr.getComponentSpecification(libraryResource, "Foo.jwc", l));
- verifyControls();
+ verify();
}
}
Modified: tapestry/tapestry4/trunk/framework/src/test/org/apache/tapestry/services/impl/TestRequestLocaleManager.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry4/trunk/framework/src/test/org/apache/tapestry/services/impl/TestRequestLocaleManager.java?rev=417545&r1=417544&r2=417545&view=diff
==============================================================================
--- tapestry/tapestry4/trunk/framework/src/test/org/apache/tapestry/services/impl/TestRequestLocaleManager.java (original)
+++ tapestry/tapestry4/trunk/framework/src/test/org/apache/tapestry/services/impl/TestRequestLocaleManager.java Tue Jun 27 11:21:31 2006
@@ -14,14 +14,17 @@
package org.apache.tapestry.services.impl;
+import static org.easymock.EasyMock.expect;
+import static org.testng.AssertJUnit.assertEquals;
+import static org.testng.AssertJUnit.assertSame;
+
import java.util.Locale;
import org.apache.hivemind.service.ThreadLocale;
-import org.apache.hivemind.test.HiveMindTestCase;
+import org.apache.tapestry.BaseComponentTestCase;
import org.apache.tapestry.TapestryConstants;
import org.apache.tapestry.services.CookieSource;
import org.apache.tapestry.web.WebRequest;
-import org.easymock.MockControl;
/**
* Tests for {@link org.apache.tapestry.services.impl.RequestLocaleManagerImpl}.
@@ -29,7 +32,7 @@
* @author Howard Lewis Ship
* @since 4.0
*/
-public class TestRequestLocaleManager extends HiveMindTestCase
+public class TestRequestLocaleManager extends BaseComponentTestCase
{
private ThreadLocale newThreadLocale()
{
@@ -38,36 +41,30 @@
private ThreadLocale newThreadLocale(Locale locale)
{
- MockControl control = newControl(ThreadLocale.class);
- ThreadLocale threadLocale = (ThreadLocale) control.getMock();
+ ThreadLocale threadLocale = newMock(ThreadLocale.class);
- threadLocale.getLocale();
- control.setReturnValue(locale);
+ expect(threadLocale.getLocale()).andReturn(locale);
return threadLocale;
}
public void testSuppliedByRequest()
{
- MockControl sourceControl = newControl(CookieSource.class);
- CookieSource source = (CookieSource) sourceControl.getMock();
-
- MockControl requestControl = newControl(WebRequest.class);
- WebRequest request = (WebRequest) requestControl.getMock();
+ CookieSource source = newMock(CookieSource.class);
+
+ WebRequest request = newRequest();
ThreadLocale tl = newThreadLocale();
// Training
- source.readCookieValue(TapestryConstants.LOCALE_COOKIE_NAME);
- sourceControl.setReturnValue(null);
+ expect(source.readCookieValue(TapestryConstants.LOCALE_COOKIE_NAME)).andReturn(null);
- request.getLocale();
- requestControl.setReturnValue(Locale.JAPANESE);
+ expect(request.getLocale()).andReturn(Locale.JAPANESE);
tl.setLocale(Locale.JAPANESE);
- replayControls();
+ replay();
RequestLocaleManagerImpl manager = new RequestLocaleManagerImpl();
manager.setCookieSource(source);
@@ -78,24 +75,22 @@
assertEquals(Locale.JAPANESE, actual);
- verifyControls();
+ verify();
}
private void attempt(String localeName, Locale expectedLocale)
{
- MockControl sourceControl = newControl(CookieSource.class);
- CookieSource source = (CookieSource) sourceControl.getMock();
+ CookieSource source = newMock(CookieSource.class);
ThreadLocale tl = newThreadLocale();
// Training
- source.readCookieValue(TapestryConstants.LOCALE_COOKIE_NAME);
- sourceControl.setReturnValue(localeName);
+ expect(source.readCookieValue(TapestryConstants.LOCALE_COOKIE_NAME)).andReturn(localeName);
tl.setLocale(expectedLocale);
- replayControls();
+ replay();
RequestLocaleManagerImpl manager = new RequestLocaleManagerImpl();
manager.setCookieSource(source);
@@ -105,7 +100,7 @@
assertEquals(expectedLocale, actual);
- verifyControls();
+ verify();
}
public void testJustLanguage()
@@ -127,14 +122,14 @@
{
Locale locale = Locale.SIMPLIFIED_CHINESE;
- CookieSource source = (CookieSource) newMock(CookieSource.class);
+ CookieSource source = newMock(CookieSource.class);
ThreadLocale threadLocale = newThreadLocale(locale);
// Training
source.writeCookieValue(TapestryConstants.LOCALE_COOKIE_NAME, locale.toString());
- replayControls();
+ replay();
RequestLocaleManagerImpl m = new RequestLocaleManagerImpl();
m.setCookieSource(source);
@@ -142,31 +137,26 @@
m.persistLocale();
- verifyControls();
+ verify();
}
public void testPersistNoChange()
{
- MockControl sourceControl = newControl(CookieSource.class);
- CookieSource source = (CookieSource) sourceControl.getMock();
-
- MockControl requestControl = newControl(WebRequest.class);
- WebRequest request = (WebRequest) requestControl.getMock();
-
- MockControl tlc = newControl(ThreadLocale.class);
- ThreadLocale tl = (ThreadLocale) tlc.getMock();
+ CookieSource source = newMock(CookieSource.class);
+
+ WebRequest request = newRequest();
+
+ ThreadLocale tl = newMock(ThreadLocale.class);
// Training
- source.readCookieValue(TapestryConstants.LOCALE_COOKIE_NAME);
- sourceControl.setReturnValue(null);
-
- request.getLocale();
- requestControl.setReturnValue(Locale.JAPANESE);
+ expect(source.readCookieValue(TapestryConstants.LOCALE_COOKIE_NAME)).andReturn(null);
+
+ expect(request.getLocale()).andReturn(Locale.JAPANESE);
tl.setLocale(Locale.JAPANESE);
- replayControls();
+ replay();
RequestLocaleManagerImpl manager = new RequestLocaleManagerImpl();
manager.setCookieSource(source);
@@ -177,18 +167,17 @@
assertEquals(Locale.JAPANESE, actual);
- verifyControls();
+ verify();
- tl.getLocale();
- tlc.setReturnValue(Locale.JAPANESE);
+ expect(tl.getLocale()).andReturn(Locale.JAPANESE);
- replayControls();
+ replay();
// Should do nothing, beacuse it isn't a change.
manager.persistLocale();
- verifyControls();
+ verify();
}
public void testGetLocaleValuesAreCached()