[jboss-cvs] JBossAS SVN: r107970 - in projects/cluster/ha-server-ispn/trunk/src/test/java/org/jboss/ha/ispn: config/xml and 1 other directory.
jboss-cvs-commits at lists.jboss.org
jboss-cvs-commits at lists.jboss.org
Thu Sep 2 22:47:36 EDT 2010
Author: pferraro
Date: 2010-09-02 22:47:33 -0400 (Thu, 02 Sep 2010)
New Revision: 107970
Modified:
projects/cluster/ha-server-ispn/trunk/src/test/java/org/jboss/ha/ispn/DefaultCacheContainerRegistryTest.java
projects/cluster/ha-server-ispn/trunk/src/test/java/org/jboss/ha/ispn/config/xml/PropertyReplacementFilterTest.java
Log:
Use mock control.
Modified: projects/cluster/ha-server-ispn/trunk/src/test/java/org/jboss/ha/ispn/DefaultCacheContainerRegistryTest.java
===================================================================
--- projects/cluster/ha-server-ispn/trunk/src/test/java/org/jboss/ha/ispn/DefaultCacheContainerRegistryTest.java 2010-09-03 01:55:29 UTC (rev 107969)
+++ projects/cluster/ha-server-ispn/trunk/src/test/java/org/jboss/ha/ispn/DefaultCacheContainerRegistryTest.java 2010-09-03 02:47:33 UTC (rev 107970)
@@ -42,6 +42,7 @@
import org.easymock.Capture;
import org.easymock.CaptureType;
import org.easymock.EasyMock;
+import org.easymock.IMocksControl;
import org.infinispan.config.Configuration;
import org.infinispan.config.GlobalConfiguration;
import org.infinispan.manager.EmbeddedCacheManager;
@@ -49,6 +50,7 @@
import org.jboss.ha.ispn.config.CacheContainerRegistryConfigurationEntry;
import org.jboss.ha.ispn.config.CacheContainerRegistryConfigurationSource;
import org.jboss.util.naming.NonSerializableFactory;
+import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
@@ -58,8 +60,10 @@
*/
public class DefaultCacheContainerRegistryTest
{
- static Context context = EasyMock.createNiceMock(Context.class);
+ static Context context;
+ private IMocksControl control;
+
@BeforeClass
public static void beforeClass() throws NamingException
{
@@ -81,6 +85,13 @@
NamingManager.setInitialContextFactoryBuilder(builder);
}
+ @Before
+ public void before()
+ {
+ this.control = EasyMock.createControl();
+ context = this.control.createMock(Context.class);
+ }
+
/**
* Test with unspecified default config and default base jndi name
* @throws Exception
@@ -88,13 +99,13 @@
@Test
public void defaults() throws Exception
{
- CacheContainerFactory factory = EasyMock.createStrictMock(CacheContainerFactory.class);
- CacheContainerRegistryConfigurationSource source = EasyMock.createStrictMock(CacheContainerRegistryConfigurationSource.class);
- EmbeddedCacheManager defaultContainer = EasyMock.createStrictMock(EmbeddedCacheManager.class);
- EmbeddedCacheManager otherContainer = EasyMock.createStrictMock(EmbeddedCacheManager.class);
- NameParser parser = EasyMock.createStrictMock(NameParser.class);
- Name name = EasyMock.createStrictMock(Name.class);
- Name subcontextName = EasyMock.createStrictMock(Name.class);
+ CacheContainerFactory factory = this.control.createMock(CacheContainerFactory.class);
+ CacheContainerRegistryConfigurationSource source = this.control.createMock(CacheContainerRegistryConfigurationSource.class);
+ EmbeddedCacheManager defaultContainer = this.control.createMock(EmbeddedCacheManager.class);
+ EmbeddedCacheManager otherContainer = this.control.createMock(EmbeddedCacheManager.class);
+ NameParser parser = this.control.createMock(NameParser.class);
+ Name name = this.control.createMock(Name.class);
+ Name subcontextName = this.control.createMock(Name.class);
Capture<Reference> capturedReferences = new Capture<Reference>(CaptureType.ALL);
CacheContainerConfiguration defaultConfig = new CacheContainerConfiguration(new GlobalConfiguration(), new Configuration());
@@ -141,12 +152,12 @@
EasyMock.expect(name.getPrefix(1)).andReturn(subcontextName);
EasyMock.expect(context.lookup(EasyMock.same(subcontextName))).andReturn(null);
context.rebind(EasyMock.eq("java:CacheManager/other"), EasyMock.capture(capturedReferences));
-
- EasyMock.replay(factory, source, context, defaultContainer, otherContainer, parser, name, subcontextName);
+ this.control.replay();
+
registry.start();
- EasyMock.verify(factory, source, context, defaultContainer, otherContainer, parser, name, subcontextName);
+ this.control.verify();
Set<String> names = registry.getCacheContainers();
Assert.assertEquals(2, names.size());
@@ -174,24 +185,24 @@
Assert.assertSame(defaultContainer, registry.getCacheContainer("unknown"));
Assert.assertSame(otherContainer, registry.getCacheContainer("other"));
- EasyMock.reset(factory, source, context, defaultContainer, otherContainer, parser, name, subcontextName);
+ this.control.reset();
defaultContainer.stop();
context.unbind("java:CacheManager/default");
otherContainer.stop();
context.unbind("java:CacheManager/other");
- EasyMock.replay(factory, source, context, defaultContainer, otherContainer, parser, name, subcontextName);
+ this.control.replay();
registry.stop();
- EasyMock.verify(factory, source, context, defaultContainer, otherContainer, parser, name, subcontextName);
-
+ this.control.verify();
+
Assert.assertNull(DefaultCacheContainerRegistry.getInstance());
Assert.assertNull(NonSerializableFactory.lookup("java:CacheManager/default"));
Assert.assertNull(NonSerializableFactory.lookup("java:CacheManager/other"));
- EasyMock.reset(factory, source, context, defaultContainer, otherContainer, parser, name, subcontextName);
+ this.control.reset();
}
/**
@@ -201,13 +212,13 @@
@Test
public void custom() throws Exception
{
- CacheContainerFactory factory = EasyMock.createStrictMock(CacheContainerFactory.class);
- CacheContainerRegistryConfigurationSource source = EasyMock.createStrictMock(CacheContainerRegistryConfigurationSource.class);
- EmbeddedCacheManager defaultContainer = EasyMock.createStrictMock(EmbeddedCacheManager.class);
- EmbeddedCacheManager otherContainer = EasyMock.createStrictMock(EmbeddedCacheManager.class);
- NameParser parser = EasyMock.createStrictMock(NameParser.class);
- Name name = EasyMock.createStrictMock(Name.class);
- Name subcontextName = EasyMock.createStrictMock(Name.class);
+ CacheContainerFactory factory = this.control.createMock(CacheContainerFactory.class);
+ CacheContainerRegistryConfigurationSource source = this.control.createMock(CacheContainerRegistryConfigurationSource.class);
+ EmbeddedCacheManager defaultContainer = this.control.createMock(EmbeddedCacheManager.class);
+ EmbeddedCacheManager otherContainer = this.control.createMock(EmbeddedCacheManager.class);
+ NameParser parser = this.control.createMock(NameParser.class);
+ Name name = this.control.createMock(Name.class);
+ Name subcontextName = this.control.createMock(Name.class);
Capture<Reference> capturedReferences = new Capture<Reference>(CaptureType.ALL);
CacheContainerConfiguration otherConfig = new CacheContainerConfiguration(new GlobalConfiguration(), new Configuration());
@@ -244,7 +255,7 @@
EasyMock.expect(parser.parse("java:other")).andReturn(name);
EasyMock.expect(name.size()).andReturn(1);
context.rebind(EasyMock.eq("java:other"), EasyMock.capture(capturedReferences));
-
+
EasyMock.expect(factory.createCacheContainer(EasyMock.same(defaultConfig))).andReturn(defaultContainer);
defaultContainer.start();
@@ -256,12 +267,12 @@
EasyMock.expect(context.lookup(EasyMock.same(subcontextName))).andThrow(new NameNotFoundException());
EasyMock.expect(context.createSubcontext(EasyMock.same(subcontextName))).andReturn(null);
context.rebind(EasyMock.eq("java:Infinispan/default"), EasyMock.capture(capturedReferences));
-
- EasyMock.replay(factory, source, context, defaultContainer, otherContainer, parser, name, subcontextName);
+ this.control.replay();
+
registry.start();
- EasyMock.verify(factory, source, context, defaultContainer, otherContainer, parser, name, subcontextName);
+ this.control.verify();
Set<String> names = registry.getCacheContainers();
Assert.assertEquals(2, names.size());
@@ -283,7 +294,7 @@
Assert.assertEquals("java:Infinispan/default", addr.getContent());
Assert.assertSame(registry.getCacheContainer("default"), NonSerializableFactory.lookup("java:Infinispan/default"));
- EasyMock.reset(factory, source, context, defaultContainer, otherContainer, parser, name, subcontextName);
+ this.control.reset();
Assert.assertSame(defaultContainer, registry.getCacheContainer());
Assert.assertSame(defaultContainer, registry.getCacheContainer(null));
@@ -300,16 +311,16 @@
otherContainer.stop();
context.unbind("java:other");
- EasyMock.replay(factory, context, defaultContainer, otherContainer, parser, name, subcontextName);
+ this.control.replay();
registry.stop();
- EasyMock.verify(factory, context, defaultContainer, otherContainer, parser, name, subcontextName);
+ this.control.verify();
Assert.assertNull(DefaultCacheContainerRegistry.getInstance());
Assert.assertNull(NonSerializableFactory.lookup("java:other"));
Assert.assertNull(NonSerializableFactory.lookup("java:Infinispan/default"));
- EasyMock.reset(factory, context, defaultContainer, otherContainer, parser, name, subcontextName);
+ this.control.reset();
}
}
Modified: projects/cluster/ha-server-ispn/trunk/src/test/java/org/jboss/ha/ispn/config/xml/PropertyReplacementFilterTest.java
===================================================================
--- projects/cluster/ha-server-ispn/trunk/src/test/java/org/jboss/ha/ispn/config/xml/PropertyReplacementFilterTest.java 2010-09-03 01:55:29 UTC (rev 107969)
+++ projects/cluster/ha-server-ispn/trunk/src/test/java/org/jboss/ha/ispn/config/xml/PropertyReplacementFilterTest.java 2010-09-03 02:47:33 UTC (rev 107970)
@@ -25,6 +25,7 @@
import org.easymock.Capture;
import org.easymock.EasyMock;
+import org.easymock.IMocksControl;
import org.junit.AfterClass;
import org.junit.Assert;
import org.junit.Before;
@@ -48,13 +49,13 @@
*/
public class PropertyReplacementFilterTest
{
- private ContentHandler contentHandler = EasyMock.createStrictMock(ContentHandler.class);
- private DTDHandler dtdHandler = EasyMock.createStrictMock(DTDHandler.class);
- private ErrorHandler errorHandler = EasyMock.createStrictMock(ErrorHandler.class);
- private EntityResolver resolver = EasyMock.createStrictMock(EntityResolver.class);
- private XMLReader parent = EasyMock.createStrictMock(XMLReader.class);
-
- private XMLFilterImpl filter = new PropertyReplacementFilter(this.parent);
+ private IMocksControl control;
+ private ContentHandler contentHandler;
+ private DTDHandler dtdHandler;
+ private ErrorHandler errorHandler;
+ private EntityResolver resolver;
+ private XMLReader parent;
+ private XMLFilterImpl filter;
private static String oldExistingValue;
private static String oldNonExistingValue;
@@ -87,6 +88,14 @@
@Before
public void before()
{
+ this.control = EasyMock.createControl();
+ this.contentHandler = this.control.createMock(ContentHandler.class);
+ this.dtdHandler = this.control.createMock(DTDHandler.class);
+ this.errorHandler = this.control.createMock(ErrorHandler.class);
+ this.resolver = this.control.createMock(EntityResolver.class);
+ this.parent = this.control.createMock(XMLReader.class);
+
+ this.filter = new PropertyReplacementFilter(this.parent);
this.filter.setContentHandler(this.contentHandler);
this.filter.setDTDHandler(this.dtdHandler);
this.filter.setEntityResolver(this.resolver);
@@ -100,31 +109,30 @@
this.contentHandler.characters(EasyMock.aryEq(plain.toCharArray()), EasyMock.eq(0), EasyMock.eq(plain.length()));
- EasyMock.replay(this.contentHandler);
+ this.control.replay();
this.filter.characters(plain.toCharArray(), 0, plain.length());
+
+ this.control.verify();
+ this.control.reset();
- EasyMock.verify(this.contentHandler);
- EasyMock.reset(this.contentHandler);
-
String string = "${existing:Free} the ${non-existing:Kraken}!";
String expected = "Release the Kraken!";
this.contentHandler.characters(EasyMock.aryEq(expected.toCharArray()), EasyMock.eq(0), EasyMock.eq(expected.length()));
- EasyMock.replay(this.contentHandler);
+ this.control.replay();
this.filter.characters(string.toCharArray(), 0, string.length());
- EasyMock.verify(this.contentHandler);
- EasyMock.reset(this.contentHandler);
+ this.control.verify();
}
@Test
public void startElement() throws SAXException
{
- Attributes attributes = EasyMock.createNiceMock(Attributes.class);
+ Attributes attributes = this.control.createMock(Attributes.class);
Capture<Attributes> capturedAttributes = new Capture<Attributes>();
String plain = "test";
@@ -145,11 +153,11 @@
this.contentHandler.startElement(EasyMock.eq(elementURI), EasyMock.eq(elementLocalName), EasyMock.eq(elementQName), EasyMock.capture(capturedAttributes));
- EasyMock.replay(this.contentHandler, attributes);
+ this.control.replay();
this.filter.startElement(elementURI, elementLocalName, elementQName, attributes);
- EasyMock.verify(this.contentHandler, attributes);
+ this.control.verify();
Attributes attr = capturedAttributes.getValue();
Assert.assertEquals(1, attr.getLength());
@@ -159,7 +167,7 @@
Assert.assertSame(attributeType, attr.getType(0));
Assert.assertEquals(plain, attr.getValue(0));
- EasyMock.reset(this.contentHandler, attributes);
+ this.control.reset();
String string = "${existing:Free} the ${non-existing:Kraken}!";
@@ -169,24 +177,24 @@
EasyMock.expect(attributes.getURI(0)).andReturn(attributeURI);
EasyMock.expect(attributes.getLocalName(0)).andReturn(attributeLocalName);
EasyMock.expect(attributes.getQName(0)).andReturn(attributeQName);
+ EasyMock.expect(attributes.getType(0)).andReturn(attributeType);
EasyMock.expect(attributes.getValue(0)).andReturn(string);
this.contentHandler.startElement(EasyMock.eq(elementURI), EasyMock.eq(elementLocalName), EasyMock.eq(elementQName), EasyMock.capture(capturedAttributes));
- EasyMock.replay(this.contentHandler, attributes);
+ this.control.replay();
this.filter.startElement(elementURI, elementLocalName, elementQName, attributes);
- EasyMock.verify(this.contentHandler, attributes);
+ this.control.verify();
attr = capturedAttributes.getValue();
Assert.assertEquals(1, attr.getLength());
Assert.assertSame(attributeURI, attr.getURI(0));
Assert.assertSame(attributeLocalName, attr.getLocalName(0));
Assert.assertSame(attributeQName, attr.getQName(0));
+ Assert.assertSame(attributeType, attr.getType(0));
Assert.assertEquals(expected, attr.getValue(0));
-
- EasyMock.reset(this.contentHandler, attributes);
}
@Test
@@ -220,7 +228,7 @@
EasyMock.expect(this.parent.getFeature(feature)).andReturn(true);
- EasyMock.replay(this.parent);
+ this.control.replay();
SAXException exception = null;
Boolean result = null;
@@ -233,14 +241,13 @@
exception = e;
}
- EasyMock.verify(this.parent);
+ this.control.verify();
Assert.assertNull(exception);
Assert.assertNotNull(result);
Assert.assertTrue(result);
- EasyMock.reset(this.parent);
-
+ this.control.reset();
this.getFeature(feature, new SAXNotRecognizedException());
this.getFeature(feature, new SAXNotSupportedException());
@@ -250,7 +257,7 @@
{
EasyMock.expect(this.parent.getFeature(feature)).andThrow(expected);
- EasyMock.replay(this.parent);
+ this.control.replay();
SAXException exception = null;
Boolean result = null;
@@ -263,27 +270,25 @@
exception = e;
}
- EasyMock.verify(this.parent);
-
+ this.control.verify();
+
Assert.assertNull(result);
Assert.assertNotNull(exception);
Assert.assertSame(expected, exception);
- EasyMock.reset(this.parent);
+ this.control.reset();
}
@Test
public void getParent()
{
- EasyMock.replay(this.parent);
+ this.control.replay();
XMLReader result = this.filter.getParent();
- EasyMock.verify(this.parent);
+ this.control.verify();
Assert.assertSame(this.parent, result);
-
- EasyMock.reset(this.parent);
}
@Test
@@ -294,16 +299,15 @@
EasyMock.expect(this.parent.getProperty(property)).andReturn(expected);
- EasyMock.replay(this.parent);
+ this.control.replay();
Object result = this.filter.getProperty(property);
- EasyMock.verify(this.parent);
+ this.control.verify();
Assert.assertSame(expected, result);
- EasyMock.reset(this.parent);
-
+ this.control.reset();
this.getProperty(property, new SAXNotRecognizedException());
this.getProperty(property, new SAXNotSupportedException());
@@ -313,7 +317,7 @@
{
EasyMock.expect(this.parent.getProperty(property)).andThrow(expected);
- EasyMock.replay(this.parent);
+ this.control.replay();
SAXException exception = null;
@@ -326,12 +330,12 @@
exception = e;
}
- EasyMock.verify(this.parent);
+ this.control.verify();
Assert.assertNotNull(exception);
Assert.assertSame(expected, exception);
- EasyMock.reset(this.parent);
+ this.control.reset();
}
@Test
@@ -348,12 +352,11 @@
this.parent.parse(source);
- EasyMock.replay(this.parent);
+ this.control.replay();
this.filter.parse(source);
- EasyMock.verify(this.parent);
- EasyMock.reset(this.parent);
+ this.control.verify();
}
@Test
@@ -371,16 +374,14 @@
this.parent.parse(EasyMock.capture(capturedSource));
- EasyMock.replay(this.parent);
+ this.control.replay();
this.filter.parse(systemId);
- EasyMock.verify(this.parent);
+ this.control.verify();
InputSource source = capturedSource.getValue();
Assert.assertSame(systemId, source.getSystemId());
-
- EasyMock.reset(this.parent);
}
@Test
@@ -391,7 +392,7 @@
this.parent.setFeature(feature, enabled);
- EasyMock.replay(this.parent);
+ this.control.replay();
SAXException exception = null;
try
@@ -403,11 +404,11 @@
exception = e;
}
- EasyMock.verify(this.parent);
+ this.control.verify();
Assert.assertNull(exception);
- EasyMock.reset(this.parent);
+ this.control.reset();
this.setFeature(feature, enabled, new SAXNotRecognizedException());
this.setFeature(feature, enabled, new SAXNotSupportedException());
@@ -418,7 +419,7 @@
this.parent.setFeature(feature, enabled);
EasyMock.expectLastCall().andThrow(expected);
- EasyMock.replay(this.parent);
+ this.control.replay();
SAXException exception = null;
try
@@ -430,11 +431,11 @@
exception = e;
}
- EasyMock.verify(this.parent);
+ this.control.verify();
Assert.assertSame(expected, exception);
- EasyMock.reset(this.parent);
+ this.control.reset();
}
@Test
@@ -442,12 +443,11 @@
{
this.contentHandler.endDocument();
- EasyMock.replay(this.contentHandler);
+ this.control.replay();
this.filter.endDocument();
- EasyMock.verify(this.contentHandler);
- EasyMock.reset(this.contentHandler);
+ this.control.verify();
}
@Test
@@ -455,12 +455,11 @@
{
this.contentHandler.endElement("uri", "localName", "qName");
- EasyMock.replay(this.contentHandler);
+ this.control.replay();
this.filter.endElement("uri", "localName", "qName");
- EasyMock.verify(this.contentHandler);
- EasyMock.reset(this.contentHandler);
+ this.control.verify();
}
@Test
@@ -468,12 +467,11 @@
{
this.contentHandler.endPrefixMapping("prefix");
- EasyMock.replay(this.contentHandler);
+ this.control.replay();
this.filter.endPrefixMapping("prefix");
- EasyMock.verify(this.contentHandler);
- EasyMock.reset(this.contentHandler);
+ this.control.verify();
}
@Test
@@ -483,12 +481,11 @@
this.errorHandler.error(error);
- EasyMock.replay(this.errorHandler);
+ this.control.replay();
this.filter.error(error);
- EasyMock.verify(this.errorHandler);
- EasyMock.reset(this.errorHandler);
+ this.control.verify();
}
@Test
@@ -498,12 +495,11 @@
this.errorHandler.fatalError(error);
- EasyMock.replay(this.errorHandler);
+ this.control.replay();
this.filter.fatalError(error);
- EasyMock.verify(this.errorHandler);
- EasyMock.reset(this.errorHandler);
+ this.control.verify();
}
@Test
@@ -513,12 +509,11 @@
this.contentHandler.ignorableWhitespace(EasyMock.aryEq(space.toCharArray()), EasyMock.eq(0), EasyMock.eq(space.length()));
- EasyMock.replay(this.contentHandler);
+ this.control.replay();
this.filter.ignorableWhitespace(space.toCharArray(), 0, space.length());
- EasyMock.verify(this.contentHandler);
- EasyMock.reset(this.contentHandler);
+ this.control.verify();
}
@Test
@@ -526,12 +521,11 @@
{
this.dtdHandler.notationDecl("name", "publicId", "systemId");
- EasyMock.replay(this.dtdHandler);
+ this.control.replay();
this.filter.notationDecl("name", "publicId", "systemId");
- EasyMock.verify(this.dtdHandler);
- EasyMock.reset(this.dtdHandler);
+ this.control.verify();
}
@Test
@@ -539,12 +533,11 @@
{
this.contentHandler.processingInstruction("target", "data");
- EasyMock.replay(this.contentHandler);
+ this.control.replay();
this.filter.processingInstruction("target", "data");
- EasyMock.verify(this.contentHandler);
- EasyMock.reset(this.contentHandler);
+ this.control.verify();
}
@Test
@@ -554,15 +547,13 @@
EasyMock.expect(this.resolver.resolveEntity("publicId", "systemId")).andReturn(expected);
- EasyMock.replay(this.resolver);
+ this.control.replay();
InputSource result = this.filter.resolveEntity("publicId", "systemId");
- EasyMock.verify(this.resolver);
+ this.control.verify();
Assert.assertSame(expected, result);
-
- EasyMock.reset(this.resolver);
}
@Test
@@ -570,12 +561,11 @@
{
this.contentHandler.skippedEntity("name");
- EasyMock.replay(this.contentHandler);
+ this.control.replay();
this.filter.skippedEntity("name");
- EasyMock.verify(this.contentHandler);
- EasyMock.reset(this.contentHandler);
+ this.control.verify();
}
@Test
@@ -583,12 +573,11 @@
{
this.contentHandler.startDocument();
- EasyMock.replay(this.contentHandler);
+ this.control.replay();
this.filter.startDocument();
- EasyMock.verify(this.contentHandler);
- EasyMock.reset(this.contentHandler);
+ this.control.verify();
}
@Test
@@ -596,12 +585,11 @@
{
this.contentHandler.startPrefixMapping("prefix", "uri");
- EasyMock.replay(this.contentHandler);
+ this.control.replay();
this.filter.startPrefixMapping("prefix", "uri");
- EasyMock.verify(this.contentHandler);
- EasyMock.reset(this.contentHandler);
+ this.control.verify();
}
@Test
@@ -609,12 +597,11 @@
{
this.dtdHandler.unparsedEntityDecl("name", "publicId", "systemId", "notationName");
- EasyMock.replay(this.dtdHandler);
+ this.control.replay();
this.filter.unparsedEntityDecl("name", "publicId", "systemId", "notationName");
- EasyMock.verify(this.dtdHandler);
- EasyMock.reset(this.dtdHandler);
+ this.control.verify();
}
@Test
@@ -624,11 +611,10 @@
this.errorHandler.warning(error);
- EasyMock.replay(this.errorHandler);
+ this.control.replay();
this.filter.warning(error);
- EasyMock.verify(this.errorHandler);
- EasyMock.reset(this.errorHandler);
+ this.control.verify();
}
}
More information about the jboss-cvs-commits
mailing list