use of org.jmock.Sequence in project geode by apache.
the class CompositeOutputStreamJUnitTest method testRemoveOutputStreamWithTwoStreams.
@Test
public void testRemoveOutputStreamWithTwoStreams() 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 OutputStream streamTwo = mockContext.mock(OutputStream.class, "streamTwo");
mockContext.checking(new Expectations() {
{
never(streamTwo).write(2);
never(streamTwo).write(3);
never(streamTwo).write(4);
never(streamTwo).write(0);
never(streamTwo).write(1);
never(streamTwo).write(9);
never(streamTwo).flush();
never(streamTwo).flush();
never(streamTwo).close();
}
});
final CompositeOutputStream cos = new CompositeOutputStream(streamOne, streamTwo);
assertFalse(cos.isEmpty());
assertEquals(2, cos.size());
cos.removeOutputStream(streamTwo);
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 testAddOutputStreamWithTwoStreams.
@Test
public void testAddOutputStreamWithTwoStreams() 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 Sequence seqStreamThree = mockContext.sequence("seqStreamThree");
final OutputStream streamThree = mockContext.mock(OutputStream.class, "streamThree");
mockContext.checking(new Expectations() {
{
oneOf(streamThree).write(2);
inSequence(seqStreamThree);
oneOf(streamThree).write(3);
inSequence(seqStreamThree);
oneOf(streamThree).write(4);
inSequence(seqStreamThree);
oneOf(streamThree).write(0);
inSequence(seqStreamThree);
oneOf(streamThree).write(1);
inSequence(seqStreamThree);
oneOf(streamThree).write(9);
inSequence(seqStreamThree);
oneOf(streamThree).flush();
inSequence(seqStreamThree);
oneOf(streamThree).flush();
inSequence(seqStreamThree);
oneOf(streamThree).close();
inSequence(seqStreamThree);
}
});
final CompositeOutputStream cos = new CompositeOutputStream(streamOne, streamTwo);
assertFalse(cos.isEmpty());
assertEquals(2, cos.size());
cos.addOutputStream(streamThree);
assertEquals(3, 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 gradle by gradle.
the class PropertyReportTaskTest method passesEachProjectPropertyToRenderer.
@Test
public void passesEachProjectPropertyToRenderer() throws IOException {
context.checking(new Expectations() {
{
oneOf(project).getProperties();
will(returnValue(GUtil.map("b", "value2", "a", "value1")));
Sequence sequence = context.sequence("seq");
oneOf(renderer).addProperty("a", "value1");
inSequence(sequence);
oneOf(renderer).addProperty("b", "value2");
inSequence(sequence);
}
});
task.generate(project);
}
use of org.jmock.Sequence in project gradle by gradle.
the class TaskReportTaskTest method groupsTasksByTaskGroupAndPassesTasksToTheRenderer.
@Test
public void groupsTasksByTaskGroupAndPassesTasksToTheRenderer() throws IOException {
context.checking(new Expectations() {
{
Task task1 = task("a", "group a");
Task task2 = task("b", "group b");
Task task3 = task("c");
Task task4 = task("d", "group b", task3);
List<String> testDefaultTasks = toList("defaultTask1", "defaultTask2");
allowing(project).getDefaultTasks();
will(returnValue(testDefaultTasks));
allowing(taskContainer).realize();
allowing(taskContainer).size();
will(returnValue(4));
allowing(taskContainer).iterator();
will(returnIterator(toLinkedSet(task2, task3, task4, task1)));
allowing(implicitTasks).iterator();
will(returnIterator(toLinkedSet()));
allowing(taskContainer).getRules();
will(returnValue(toList()));
Sequence sequence = context.sequence("seq");
one(renderer).showDetail(false);
inSequence(sequence);
one(renderer).addDefaultTasks(testDefaultTasks);
inSequence(sequence);
one(renderer).startTaskGroup("group a");
inSequence(sequence);
one(renderer).addTask(with(isTask(task1)));
inSequence(sequence);
one(renderer).startTaskGroup("group b");
inSequence(sequence);
one(renderer).addTask(with(isTask(task2)));
inSequence(sequence);
one(renderer).addTask(with(isTask(task4)));
inSequence(sequence);
one(renderer).completeTasks();
inSequence(sequence);
}
});
task.generate(project);
}
use of org.jmock.Sequence in project geode by apache.
the class CompositeOutputStreamJUnitTest method testAddOneOutputStreamWhenEmpty.
@Test
public void testAddOneOutputStreamWhenEmpty() 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();
assertTrue(cos.isEmpty());
assertEquals(0, cos.size());
cos.addOutputStream(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();
}
Aggregations