use of org.jmock.Sequence in project geode by apache.
the class CompositeOutputStreamJUnitTest method testNewCompositeOutputStreamWithOneStream.
@Test
public void testNewCompositeOutputStreamWithOneStream() throws IOException {
final Sequence seqStreamOne = mockContext.sequence("seqStreamOne");
final OutputStream streamOne = mockContext.mock(OutputStream.class, "streamOne");
mockContext.checking(new Expectations() {
{
oneOf(streamOne).write(2);
inSequence(seqStreamOne);
oneOf(streamOne).write(3);
inSequence(seqStreamOne);
oneOf(streamOne).write(4);
inSequence(seqStreamOne);
oneOf(streamOne).write(0);
inSequence(seqStreamOne);
oneOf(streamOne).write(1);
inSequence(seqStreamOne);
oneOf(streamOne).write(9);
inSequence(seqStreamOne);
oneOf(streamOne).flush();
inSequence(seqStreamOne);
oneOf(streamOne).flush();
inSequence(seqStreamOne);
oneOf(streamOne).close();
inSequence(seqStreamOne);
}
});
final CompositeOutputStream cos = new CompositeOutputStream(streamOne);
assertFalse(cos.isEmpty());
assertEquals(1, cos.size());
cos.write(new byte[] { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 }, 2, 3);
cos.write(new byte[] { 0, 1 });
cos.write(9);
cos.flush();
cos.close();
}
use of org.jmock.Sequence in project geode by apache.
the class CompositeOutputStreamJUnitTest method testAddTwoOutputStreamsWhenEmpty.
@Test
public void testAddTwoOutputStreamsWhenEmpty() throws IOException {
final Sequence seqStreamOne = mockContext.sequence("seqStreamOne");
final OutputStream streamOne = mockContext.mock(OutputStream.class, "streamOne");
mockContext.checking(new Expectations() {
{
oneOf(streamOne).write(2);
inSequence(seqStreamOne);
oneOf(streamOne).write(3);
inSequence(seqStreamOne);
oneOf(streamOne).write(4);
inSequence(seqStreamOne);
oneOf(streamOne).write(0);
inSequence(seqStreamOne);
oneOf(streamOne).write(1);
inSequence(seqStreamOne);
oneOf(streamOne).write(9);
inSequence(seqStreamOne);
oneOf(streamOne).flush();
inSequence(seqStreamOne);
oneOf(streamOne).flush();
inSequence(seqStreamOne);
oneOf(streamOne).close();
inSequence(seqStreamOne);
}
});
final Sequence seqStreamTwo = mockContext.sequence("seqStreamTwo");
final OutputStream streamTwo = mockContext.mock(OutputStream.class, "streamTwo");
mockContext.checking(new Expectations() {
{
oneOf(streamTwo).write(2);
inSequence(seqStreamTwo);
oneOf(streamTwo).write(3);
inSequence(seqStreamTwo);
oneOf(streamTwo).write(4);
inSequence(seqStreamTwo);
oneOf(streamTwo).write(0);
inSequence(seqStreamTwo);
oneOf(streamTwo).write(1);
inSequence(seqStreamTwo);
oneOf(streamTwo).write(9);
inSequence(seqStreamTwo);
oneOf(streamTwo).flush();
inSequence(seqStreamTwo);
oneOf(streamTwo).flush();
inSequence(seqStreamTwo);
oneOf(streamTwo).close();
inSequence(seqStreamTwo);
}
});
final CompositeOutputStream cos = new CompositeOutputStream();
assertTrue(cos.isEmpty());
assertEquals(0, cos.size());
cos.addOutputStream(streamOne);
cos.addOutputStream(streamTwo);
assertFalse(cos.isEmpty());
assertEquals(2, cos.size());
cos.write(new byte[] { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 }, 2, 3);
cos.write(new byte[] { 0, 1 });
cos.write(9);
cos.flush();
cos.close();
}
use of org.jmock.Sequence in project geode by apache.
the class CompositeOutputStreamJUnitTest method testNewCompositeOutputStreamWithTwoStreams.
@Test
public void testNewCompositeOutputStreamWithTwoStreams() throws IOException {
final Sequence seqStreamOne = mockContext.sequence("seqStreamOne");
final OutputStream streamOne = mockContext.mock(OutputStream.class, "streamOne");
mockContext.checking(new Expectations() {
{
oneOf(streamOne).write(2);
inSequence(seqStreamOne);
oneOf(streamOne).write(3);
inSequence(seqStreamOne);
oneOf(streamOne).write(4);
inSequence(seqStreamOne);
oneOf(streamOne).write(0);
inSequence(seqStreamOne);
oneOf(streamOne).write(1);
inSequence(seqStreamOne);
oneOf(streamOne).write(9);
inSequence(seqStreamOne);
oneOf(streamOne).flush();
inSequence(seqStreamOne);
oneOf(streamOne).flush();
inSequence(seqStreamOne);
oneOf(streamOne).close();
inSequence(seqStreamOne);
}
});
final Sequence seqStreamTwo = mockContext.sequence("seqStreamTwo");
final OutputStream streamTwo = mockContext.mock(OutputStream.class, "streamTwo");
mockContext.checking(new Expectations() {
{
oneOf(streamTwo).write(2);
inSequence(seqStreamTwo);
oneOf(streamTwo).write(3);
inSequence(seqStreamTwo);
oneOf(streamTwo).write(4);
inSequence(seqStreamTwo);
oneOf(streamTwo).write(0);
inSequence(seqStreamTwo);
oneOf(streamTwo).write(1);
inSequence(seqStreamTwo);
oneOf(streamTwo).write(9);
inSequence(seqStreamTwo);
oneOf(streamTwo).flush();
inSequence(seqStreamTwo);
oneOf(streamTwo).flush();
inSequence(seqStreamTwo);
oneOf(streamTwo).close();
inSequence(seqStreamTwo);
}
});
final CompositeOutputStream cos = new CompositeOutputStream(streamOne, streamTwo);
assertFalse(cos.isEmpty());
assertEquals(2, cos.size());
cos.write(new byte[] { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 }, 2, 3);
cos.write(new byte[] { 0, 1 });
cos.write(9);
cos.flush();
cos.close();
}
use of org.jmock.Sequence in project sling by apache.
the class ClassLoadingTest method testLoading.
/**
* This method tests the dynamic class loading through the package admin.
* The returned class changes from map to array list.
*/
@Test
public void testLoading() throws Exception {
final Sequence sequence = this.context.sequence("load-sequence");
final BundleContext bundleContext = this.context.mock(BundleContext.class);
final PackageAdmin packageAdmin = this.context.mock(PackageAdmin.class);
final ExportedPackage ep = this.context.mock(ExportedPackage.class);
final Bundle bundle = this.context.mock(Bundle.class);
this.context.checking(new Expectations() {
{
allowing(bundleContext).createFilter(with(any(String.class)));
will(returnValue(null));
allowing(bundleContext).getServiceReferences(with(any(String.class)), with((String) null));
will(returnValue(null));
allowing(bundleContext).addServiceListener(with(any(ServiceListener.class)), with(any(String.class)));
allowing(bundleContext).removeServiceListener(with(any(ServiceListener.class)));
allowing(packageAdmin).getExportedPackages("org.apache.sling.test");
will(returnValue(new ExportedPackage[] { ep }));
allowing(ep).getExportingBundle();
will(returnValue(bundle));
allowing(ep).isRemovalPending();
will(returnValue(false));
allowing(bundle).getBundleId();
will(returnValue(2L));
allowing(bundle).getState();
will(returnValue(Bundle.ACTIVE));
allowing(bundle).getSymbolicName();
will(returnValue("org.apache.sling.test"));
allowing(bundle).getVersion();
will(returnValue(new Version("1.0.0")));
one(bundle).loadClass("org.apache.sling.test.A");
inSequence(sequence);
will(returnValue(java.util.Map.class));
one(bundle).loadClass("org.apache.sling.test.A");
inSequence(sequence);
will(returnValue(java.util.Map.class));
one(bundle).loadClass("org.apache.sling.test.A");
inSequence(sequence);
will(returnValue(java.util.ArrayList.class));
}
});
DynamicClassLoaderManagerImpl manager = new DynamicClassLoaderManagerImpl(bundleContext, packageAdmin, null, new DynamicClassLoaderManagerFactory(bundleContext, packageAdmin));
final ClassLoader cl = manager.getDynamicClassLoader();
final Class<?> c1 = cl.loadClass("org.apache.sling.test.A");
Assert.assertEquals("java.util.Map", c1.getName());
final Class<?> c2 = cl.loadClass("org.apache.sling.test.A");
Assert.assertEquals("java.util.Map", c2.getName());
// as we cache the result, we still get the map!
final Class<?> c3 = cl.loadClass("org.apache.sling.test.A");
Assert.assertEquals("java.util.Map", c3.getName());
}
Aggregations