Search in sources :

Example 11 with Sequence

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();
}
Also used : Expectations(org.jmock.Expectations) OutputStream(java.io.OutputStream) Sequence(org.jmock.Sequence) Test(org.junit.Test) UnitTest(org.apache.geode.test.junit.categories.UnitTest)

Example 12 with Sequence

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();
}
Also used : Expectations(org.jmock.Expectations) OutputStream(java.io.OutputStream) Sequence(org.jmock.Sequence) Test(org.junit.Test) UnitTest(org.apache.geode.test.junit.categories.UnitTest)

Example 13 with Sequence

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);
}
Also used : Expectations(org.jmock.Expectations) Sequence(org.jmock.Sequence) Test(org.junit.Test)

Example 14 with Sequence

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);
}
Also used : Expectations(org.jmock.Expectations) Task(org.gradle.api.Task) List(java.util.List) Sequence(org.jmock.Sequence) Test(org.junit.Test)

Example 15 with Sequence

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();
}
Also used : Expectations(org.jmock.Expectations) OutputStream(java.io.OutputStream) Sequence(org.jmock.Sequence) Test(org.junit.Test) UnitTest(org.apache.geode.test.junit.categories.UnitTest)

Aggregations

Expectations (org.jmock.Expectations)19 Sequence (org.jmock.Sequence)19 Test (org.junit.Test)19 OutputStream (java.io.OutputStream)7 UnitTest (org.apache.geode.test.junit.categories.UnitTest)7 BuildClientMetaData (org.gradle.initialization.BuildClientMetaData)3 List (java.util.List)2 IntegrationTest (org.apache.geode.test.junit.categories.IntegrationTest)2 Script (org.gradle.groovy.scripts.Script)2 StyledTextOutput (org.gradle.internal.logging.text.StyledTextOutput)2 File (java.io.File)1 GradleScriptException (org.gradle.api.GradleScriptException)1 Project (org.gradle.api.Project)1 Rule (org.gradle.api.Rule)1 Task (org.gradle.api.Task)1 TestUtil.createChildProject (org.gradle.util.TestUtil.createChildProject)1 Description (org.hamcrest.Description)1 Action (org.jmock.api.Action)1 Invocation (org.jmock.api.Invocation)1 Bundle (org.osgi.framework.Bundle)1