Example #1
0
  @Test
  public void testObjectSourceConstructor() {
    final MockObjectSource source = new MockObjectSource(15);
    assertEquals(15, source.getId());

    assertEquals(0, source.getAttached());
    source.attach();
    assertEquals(1, source.getAttached());
  }
  @Test
  public void testLeftInputAdapterNode() {
    final MockObjectSource source = new MockObjectSource(15);
    final LeftInputAdapterNode liaNode = new LeftInputAdapterNode(23, source, buildContext);
    assertEquals(23, liaNode.getId());

    assertEquals(0, source.getAttached());
    source.attach();
    assertEquals(1, source.getAttached());
  }
Example #3
0
  @Test
  public void testAddObjectSink() throws Exception {
    final MockObjectSource source = new MockObjectSource(15);

    // We need to re-assign this var each time the sink changes references
    final Field field = ObjectSource.class.getDeclaredField("sink");
    field.setAccessible(true);
    ObjectSinkPropagator sink = (ObjectSinkPropagator) field.get(source);

    assertSame(EmptyObjectSinkAdapter.getInstance(), sink);

    final MockObjectSink sink1 = new MockObjectSink();
    source.addObjectSink(sink1);
    sink = (ObjectSinkPropagator) field.get(source);
    assertSame(SingleObjectSinkAdapter.class, sink.getClass());
    assertEquals(1, sink.getSinks().length);

    final MockObjectSink sink2 = new MockObjectSink();
    source.addObjectSink(sink2);
    sink = (ObjectSinkPropagator) field.get(source);
    assertSame(CompositeObjectSinkAdapter.class, sink.getClass());
    assertEquals(2, sink.getSinks().length);

    final MockObjectSink sink3 = new MockObjectSink();
    source.addObjectSink(sink3);
    assertSame(CompositeObjectSinkAdapter.class, sink.getClass());
    assertEquals(3, sink.getSinks().length);

    source.removeObjectSink(sink2);
    assertSame(CompositeObjectSinkAdapter.class, sink.getClass());
    assertEquals(2, sink.getSinks().length);

    source.removeObjectSink(sink1);
    sink = (ObjectSinkPropagator) field.get(source);
    assertSame(SingleObjectSinkAdapter.class, sink.getClass());
    assertEquals(1, sink.getSinks().length);

    source.removeObjectSink(sink3);
    sink = (ObjectSinkPropagator) field.get(source);
    assertSame(EmptyObjectSinkAdapter.getInstance(), sink);
    assertEquals(0, sink.getSinks().length);
  }