From 17b5c91920ab6d41349664edfc14bf6d59631924 Mon Sep 17 00:00:00 2001 From: Jens Wille Date: Fri, 29 Oct 2021 20:45:35 +0200 Subject: [PATCH 1/6] Fix indentation in Metamorph collector tests. --- .../metamorph/collectors/AllTest.java | 326 +++--- .../metamorph/collectors/AnyTest.java | 320 +++--- .../metamorph/collectors/ChooseTest.java | 504 ++++---- .../metamorph/collectors/CombineTest.java | 370 +++--- .../metamorph/collectors/ConcatTest.java | 330 +++--- .../metamorph/collectors/EntityTest.java | 1020 ++++++++--------- .../collectors/EqualsFilterTest.java | 550 ++++----- .../metamorph/collectors/GroupTest.java | 56 +- .../metamorph/collectors/NoneTest.java | 278 ++--- .../metamorph/collectors/RangeTest.java | 344 +++--- .../metamorph/collectors/SquareTest.java | 178 +-- .../collectors/TestCollectorBasics.java | 272 ++--- .../metamorph/collectors/TestCollectorIf.java | 454 ++++---- 13 files changed, 2501 insertions(+), 2501 deletions(-) diff --git a/metamorph/src/test/java/org/metafacture/metamorph/collectors/AllTest.java b/metamorph/src/test/java/org/metafacture/metamorph/collectors/AllTest.java index 3ca2f5010..3bac168ae 100644 --- a/metamorph/src/test/java/org/metafacture/metamorph/collectors/AllTest.java +++ b/metamorph/src/test/java/org/metafacture/metamorph/collectors/AllTest.java @@ -36,168 +36,168 @@ */ public final class AllTest { - @Rule - public final MockitoRule mockitoRule = MockitoJUnit.rule(); - - @Mock - private StreamReceiver receiver; - - private Metamorph metamorph; - - @Test - public void shouldFireOnlyIfAllElementsFire() { - metamorph = InlineMorph.in(this) - .with("") - .with(" ") - .with(" ") - .with(" ") - .with(" ") - .with("") - .createConnectedTo(receiver); - - metamorph.startRecord("1"); - metamorph.literal("data1", "A"); - metamorph.literal("data2", "B"); - metamorph.endRecord(); - metamorph.startRecord("2"); - metamorph.literal("data2", "C"); - metamorph.endRecord(); - - final InOrder ordered = inOrder(receiver); - ordered.verify(receiver).startRecord("1"); - ordered.verify(receiver).literal("", "true"); - ordered.verify(receiver).endRecord(); - ordered.verify(receiver).startRecord("2"); - ordered.verify(receiver).endRecord(); - ordered.verifyNoMoreInteractions(); - } - - @Test - public void shouldSupportUserdefinedNameAndValue() { - metamorph = InlineMorph.in(this) - .with("") - .with(" ") - .with(" ") - .with(" ") - .with(" ") - .with("") - .createConnectedTo(receiver); - - metamorph.startRecord("1"); - metamorph.literal("data1", "A"); - metamorph.literal("data2", "B"); - metamorph.endRecord(); - - final InOrder ordered = inOrder(receiver); - ordered.verify(receiver).startRecord("1"); - ordered.verify(receiver).literal("ALL", "found all"); - ordered.verify(receiver).endRecord(); - ordered.verifyNoMoreInteractions(); - } - - @Test - public void shouldFireAgainIfValueChangesAndResetIsFalse() { - metamorph = InlineMorph.in(this) - .with("") - .with(" ") - .with(" ") - .with(" ") - .with(" ") - .with("") - .createConnectedTo(receiver); - - metamorph.startRecord("1"); - metamorph.startEntity("entity"); - metamorph.literal("data1", "A"); - metamorph.literal("data2", "B"); - metamorph.endEntity(); - metamorph.startEntity("entity"); - metamorph.literal("data2", "C"); - metamorph.endEntity(); - metamorph.endRecord(); - - final InOrder ordered = inOrder(receiver); - ordered.verify(receiver).startRecord("1"); - ordered.verify(receiver, times(2)).literal("", "true"); - ordered.verify(receiver).endRecord(); - ordered.verifyNoMoreInteractions(); - } - - @Test - public void shouldNotFireAgainIfOnlyOneValueChangesAndResetIsTrue() { - metamorph = InlineMorph.in(this) - .with("") - .with(" ") - .with(" ") - .with(" ") - .with(" ") - .with("") - .createConnectedTo(receiver); - - metamorph.startRecord("1"); - metamorph.startEntity("entity"); - metamorph.literal("data1", "A"); - metamorph.literal("data2", "B"); - metamorph.endEntity(); - metamorph.startEntity("entity"); - metamorph.literal("data2", "B"); - metamorph.endEntity(); - metamorph.endRecord(); - - final InOrder ordered = inOrder(receiver); - ordered.verify(receiver).startRecord("1"); - ordered.verify(receiver).literal("", "true"); - ordered.verify(receiver).endRecord(); - ordered.verifyNoMoreInteractions(); - } - - @Test - public void shouldNotFireIfFlushingAnIncompleteCollection() { - metamorph = InlineMorph.in(this) - .with("") - .with(" ") - .with(" ") - .with(" ") - .with(" ") - .with("") - .createConnectedTo(receiver); - - metamorph.startRecord("1"); - metamorph.startEntity("entity"); - metamorph.literal("data1", "A"); - metamorph.endEntity(); - metamorph.endRecord(); - - final InOrder ordered = inOrder(receiver); - ordered.verify(receiver).startRecord("1"); - ordered.verify(receiver).endRecord(); - ordered.verifyNoMoreInteractions(); - } - - @Test - public void shouldResetWhenEntityChangesIfSameEntity() { - metamorph = InlineMorph.in(this) - .with("") - .with(" ") - .with(" ") - .with(" ") - .with(" ") - .with("") - .createConnectedTo(receiver); - - metamorph.startRecord("1"); - metamorph.startEntity("entity"); - metamorph.literal("data2", "A"); - metamorph.endEntity(); - metamorph.startEntity("entity"); - metamorph.literal("data1", "A"); - metamorph.endEntity(); - metamorph.endRecord(); - - final InOrder ordered = inOrder(receiver); - ordered.verify(receiver).startRecord("1"); - ordered.verify(receiver).endRecord(); - ordered.verifyNoMoreInteractions(); - } + @Rule + public final MockitoRule mockitoRule = MockitoJUnit.rule(); + + @Mock + private StreamReceiver receiver; + + private Metamorph metamorph; + + @Test + public void shouldFireOnlyIfAllElementsFire() { + metamorph = InlineMorph.in(this) + .with("") + .with(" ") + .with(" ") + .with(" ") + .with(" ") + .with("") + .createConnectedTo(receiver); + + metamorph.startRecord("1"); + metamorph.literal("data1", "A"); + metamorph.literal("data2", "B"); + metamorph.endRecord(); + metamorph.startRecord("2"); + metamorph.literal("data2", "C"); + metamorph.endRecord(); + + final InOrder ordered = inOrder(receiver); + ordered.verify(receiver).startRecord("1"); + ordered.verify(receiver).literal("", "true"); + ordered.verify(receiver).endRecord(); + ordered.verify(receiver).startRecord("2"); + ordered.verify(receiver).endRecord(); + ordered.verifyNoMoreInteractions(); + } + + @Test + public void shouldSupportUserdefinedNameAndValue() { + metamorph = InlineMorph.in(this) + .with("") + .with(" ") + .with(" ") + .with(" ") + .with(" ") + .with("") + .createConnectedTo(receiver); + + metamorph.startRecord("1"); + metamorph.literal("data1", "A"); + metamorph.literal("data2", "B"); + metamorph.endRecord(); + + final InOrder ordered = inOrder(receiver); + ordered.verify(receiver).startRecord("1"); + ordered.verify(receiver).literal("ALL", "found all"); + ordered.verify(receiver).endRecord(); + ordered.verifyNoMoreInteractions(); + } + + @Test + public void shouldFireAgainIfValueChangesAndResetIsFalse() { + metamorph = InlineMorph.in(this) + .with("") + .with(" ") + .with(" ") + .with(" ") + .with(" ") + .with("") + .createConnectedTo(receiver); + + metamorph.startRecord("1"); + metamorph.startEntity("entity"); + metamorph.literal("data1", "A"); + metamorph.literal("data2", "B"); + metamorph.endEntity(); + metamorph.startEntity("entity"); + metamorph.literal("data2", "C"); + metamorph.endEntity(); + metamorph.endRecord(); + + final InOrder ordered = inOrder(receiver); + ordered.verify(receiver).startRecord("1"); + ordered.verify(receiver, times(2)).literal("", "true"); + ordered.verify(receiver).endRecord(); + ordered.verifyNoMoreInteractions(); + } + + @Test + public void shouldNotFireAgainIfOnlyOneValueChangesAndResetIsTrue() { + metamorph = InlineMorph.in(this) + .with("") + .with(" ") + .with(" ") + .with(" ") + .with(" ") + .with("") + .createConnectedTo(receiver); + + metamorph.startRecord("1"); + metamorph.startEntity("entity"); + metamorph.literal("data1", "A"); + metamorph.literal("data2", "B"); + metamorph.endEntity(); + metamorph.startEntity("entity"); + metamorph.literal("data2", "B"); + metamorph.endEntity(); + metamorph.endRecord(); + + final InOrder ordered = inOrder(receiver); + ordered.verify(receiver).startRecord("1"); + ordered.verify(receiver).literal("", "true"); + ordered.verify(receiver).endRecord(); + ordered.verifyNoMoreInteractions(); + } + + @Test + public void shouldNotFireIfFlushingAnIncompleteCollection() { + metamorph = InlineMorph.in(this) + .with("") + .with(" ") + .with(" ") + .with(" ") + .with(" ") + .with("") + .createConnectedTo(receiver); + + metamorph.startRecord("1"); + metamorph.startEntity("entity"); + metamorph.literal("data1", "A"); + metamorph.endEntity(); + metamorph.endRecord(); + + final InOrder ordered = inOrder(receiver); + ordered.verify(receiver).startRecord("1"); + ordered.verify(receiver).endRecord(); + ordered.verifyNoMoreInteractions(); + } + + @Test + public void shouldResetWhenEntityChangesIfSameEntity() { + metamorph = InlineMorph.in(this) + .with("") + .with(" ") + .with(" ") + .with(" ") + .with(" ") + .with("") + .createConnectedTo(receiver); + + metamorph.startRecord("1"); + metamorph.startEntity("entity"); + metamorph.literal("data2", "A"); + metamorph.endEntity(); + metamorph.startEntity("entity"); + metamorph.literal("data1", "A"); + metamorph.endEntity(); + metamorph.endRecord(); + + final InOrder ordered = inOrder(receiver); + ordered.verify(receiver).startRecord("1"); + ordered.verify(receiver).endRecord(); + ordered.verifyNoMoreInteractions(); + } } diff --git a/metamorph/src/test/java/org/metafacture/metamorph/collectors/AnyTest.java b/metamorph/src/test/java/org/metafacture/metamorph/collectors/AnyTest.java index 8a697c650..df44b17b1 100644 --- a/metamorph/src/test/java/org/metafacture/metamorph/collectors/AnyTest.java +++ b/metamorph/src/test/java/org/metafacture/metamorph/collectors/AnyTest.java @@ -36,165 +36,165 @@ */ public final class AnyTest { - @Rule - public final MockitoRule mockitoRule = MockitoJUnit.rule(); - - @Mock - private StreamReceiver receiver; - - private Metamorph metamorph; - - @Test - public void shouldFireOnlyIfAtLeastOneElementFires() { - metamorph = InlineMorph.in(this) - .with("") - .with(" ") - .with(" ") - .with(" ") - .with(" ") - .with("") - .createConnectedTo(receiver); - - metamorph.startRecord("1"); - metamorph.literal("data1", "A"); - metamorph.endRecord(); - metamorph.startRecord("2"); - metamorph.literal("data2", "C"); - metamorph.endRecord(); - metamorph.startRecord("3"); - metamorph.literal("data3", "C"); - metamorph.endRecord(); - - final InOrder ordered = inOrder(receiver); - ordered.verify(receiver).startRecord("1"); - ordered.verify(receiver).literal("", "true"); - ordered.verify(receiver).endRecord(); - ordered.verify(receiver).startRecord("2"); - ordered.verify(receiver).literal("", "true"); - ordered.verify(receiver).endRecord(); - ordered.verify(receiver).startRecord("3"); - ordered.verify(receiver).endRecord(); - ordered.verifyNoMoreInteractions(); - } - - @Test - public void shouldSupportUserdefinedNameAndValue() { - metamorph = InlineMorph.in(this) - .with("") - .with(" ") - .with(" ") - .with(" ") - .with(" ") - .with("") - .createConnectedTo(receiver); - - metamorph.startRecord("1"); - metamorph.literal("data1", "A"); - metamorph.endRecord(); - - final InOrder ordered = inOrder(receiver); - ordered.verify(receiver).startRecord("1"); - ordered.verify(receiver).literal("ANY", "found one"); - ordered.verify(receiver).endRecord(); - ordered.verifyNoMoreInteractions(); - } - - @Test - public void shouldNotFireAgainIfAdditionalValueIsReceivedAndResetIsFalse() { - metamorph = InlineMorph.in(this) - .with("") - .with(" ") - .with(" ") - .with(" ") - .with(" ") - .with("") - .createConnectedTo(receiver); - - metamorph.startRecord("1"); - metamorph.literal("data1", "A"); - metamorph.literal("data2", "B"); - metamorph.literal("data2", "C"); - metamorph.endRecord(); - - final InOrder ordered = inOrder(receiver); - ordered.verify(receiver).startRecord("1"); - ordered.verify(receiver).literal("", "true"); - ordered.verify(receiver).endRecord(); - ordered.verifyNoMoreInteractions(); - } - - @Test - public void shouldFireAgainIfAdditionalValueIsReceivedAndResetIsTrue() { - metamorph = InlineMorph.in(this) - .with("") - .with(" ") - .with(" ") - .with(" ") - .with(" ") - .with("") - .createConnectedTo(receiver); - - metamorph.startRecord("1"); - metamorph.literal("data1", "A"); - metamorph.literal("data2", "B"); - metamorph.literal("data2", "C"); - metamorph.endRecord(); - - final InOrder ordered = inOrder(receiver); - ordered.verify(receiver).startRecord("1"); - ordered.verify(receiver, times(3)).literal("", "true"); - ordered.verify(receiver).endRecord(); - ordered.verifyNoMoreInteractions(); - } - - @Test - public void shouldFireAgainAfterFlushing() { - metamorph = InlineMorph.in(this) - .with("") - .with(" ") - .with(" ") - .with(" ") - .with(" ") - .with("") - .createConnectedTo(receiver); - - metamorph.startRecord("1"); - metamorph.startEntity("entity"); - metamorph.literal("data1", "A"); - metamorph.endEntity(); - metamorph.startEntity("entity"); - metamorph.literal("data2", "B"); - metamorph.endEntity(); - metamorph.endRecord(); - - final InOrder ordered = inOrder(receiver); - ordered.verify(receiver).startRecord("1"); - ordered.verify(receiver, times(2)).literal("", "true"); - ordered.verify(receiver).endRecord(); - ordered.verifyNoMoreInteractions(); - } - - @Test - public void shouldNotFireIfFlushingAnUntriggeredCollection() { - metamorph = InlineMorph.in(this) - .with("") - .with(" ") - .with(" ") - .with(" ") - .with(" ") - .with("") - .createConnectedTo(receiver); - - metamorph.startRecord("1"); - metamorph.startEntity("entity"); - metamorph.literal("data3", "A"); - metamorph.endEntity(); - metamorph.endRecord(); - - final InOrder ordered = inOrder(receiver); - ordered.verify(receiver).startRecord("1"); - ordered.verify(receiver).endRecord(); - ordered.verifyNoMoreInteractions(); - } + @Rule + public final MockitoRule mockitoRule = MockitoJUnit.rule(); + + @Mock + private StreamReceiver receiver; + + private Metamorph metamorph; + + @Test + public void shouldFireOnlyIfAtLeastOneElementFires() { + metamorph = InlineMorph.in(this) + .with("") + .with(" ") + .with(" ") + .with(" ") + .with(" ") + .with("") + .createConnectedTo(receiver); + + metamorph.startRecord("1"); + metamorph.literal("data1", "A"); + metamorph.endRecord(); + metamorph.startRecord("2"); + metamorph.literal("data2", "C"); + metamorph.endRecord(); + metamorph.startRecord("3"); + metamorph.literal("data3", "C"); + metamorph.endRecord(); + + final InOrder ordered = inOrder(receiver); + ordered.verify(receiver).startRecord("1"); + ordered.verify(receiver).literal("", "true"); + ordered.verify(receiver).endRecord(); + ordered.verify(receiver).startRecord("2"); + ordered.verify(receiver).literal("", "true"); + ordered.verify(receiver).endRecord(); + ordered.verify(receiver).startRecord("3"); + ordered.verify(receiver).endRecord(); + ordered.verifyNoMoreInteractions(); + } + + @Test + public void shouldSupportUserdefinedNameAndValue() { + metamorph = InlineMorph.in(this) + .with("") + .with(" ") + .with(" ") + .with(" ") + .with(" ") + .with("") + .createConnectedTo(receiver); + + metamorph.startRecord("1"); + metamorph.literal("data1", "A"); + metamorph.endRecord(); + + final InOrder ordered = inOrder(receiver); + ordered.verify(receiver).startRecord("1"); + ordered.verify(receiver).literal("ANY", "found one"); + ordered.verify(receiver).endRecord(); + ordered.verifyNoMoreInteractions(); + } + + @Test + public void shouldNotFireAgainIfAdditionalValueIsReceivedAndResetIsFalse() { + metamorph = InlineMorph.in(this) + .with("") + .with(" ") + .with(" ") + .with(" ") + .with(" ") + .with("") + .createConnectedTo(receiver); + + metamorph.startRecord("1"); + metamorph.literal("data1", "A"); + metamorph.literal("data2", "B"); + metamorph.literal("data2", "C"); + metamorph.endRecord(); + + final InOrder ordered = inOrder(receiver); + ordered.verify(receiver).startRecord("1"); + ordered.verify(receiver).literal("", "true"); + ordered.verify(receiver).endRecord(); + ordered.verifyNoMoreInteractions(); + } + + @Test + public void shouldFireAgainIfAdditionalValueIsReceivedAndResetIsTrue() { + metamorph = InlineMorph.in(this) + .with("") + .with(" ") + .with(" ") + .with(" ") + .with(" ") + .with("") + .createConnectedTo(receiver); + + metamorph.startRecord("1"); + metamorph.literal("data1", "A"); + metamorph.literal("data2", "B"); + metamorph.literal("data2", "C"); + metamorph.endRecord(); + + final InOrder ordered = inOrder(receiver); + ordered.verify(receiver).startRecord("1"); + ordered.verify(receiver, times(3)).literal("", "true"); + ordered.verify(receiver).endRecord(); + ordered.verifyNoMoreInteractions(); + } + + @Test + public void shouldFireAgainAfterFlushing() { + metamorph = InlineMorph.in(this) + .with("") + .with(" ") + .with(" ") + .with(" ") + .with(" ") + .with("") + .createConnectedTo(receiver); + + metamorph.startRecord("1"); + metamorph.startEntity("entity"); + metamorph.literal("data1", "A"); + metamorph.endEntity(); + metamorph.startEntity("entity"); + metamorph.literal("data2", "B"); + metamorph.endEntity(); + metamorph.endRecord(); + + final InOrder ordered = inOrder(receiver); + ordered.verify(receiver).startRecord("1"); + ordered.verify(receiver, times(2)).literal("", "true"); + ordered.verify(receiver).endRecord(); + ordered.verifyNoMoreInteractions(); + } + + @Test + public void shouldNotFireIfFlushingAnUntriggeredCollection() { + metamorph = InlineMorph.in(this) + .with("") + .with(" ") + .with(" ") + .with(" ") + .with(" ") + .with("") + .createConnectedTo(receiver); + + metamorph.startRecord("1"); + metamorph.startEntity("entity"); + metamorph.literal("data3", "A"); + metamorph.endEntity(); + metamorph.endRecord(); + + final InOrder ordered = inOrder(receiver); + ordered.verify(receiver).startRecord("1"); + ordered.verify(receiver).endRecord(); + ordered.verifyNoMoreInteractions(); + } } diff --git a/metamorph/src/test/java/org/metafacture/metamorph/collectors/ChooseTest.java b/metamorph/src/test/java/org/metafacture/metamorph/collectors/ChooseTest.java index 278066505..e1fa7c50c 100644 --- a/metamorph/src/test/java/org/metafacture/metamorph/collectors/ChooseTest.java +++ b/metamorph/src/test/java/org/metafacture/metamorph/collectors/ChooseTest.java @@ -37,257 +37,257 @@ */ public final class ChooseTest { - @Rule - public final MockitoRule mockitoRule = MockitoJUnit.rule(); - - @Mock - private StreamReceiver receiver; - - private Metamorph metamorph; - - @Test - public void shouldChooseValueOfTopMostFiringStatement() { - metamorph = InlineMorph.in(this) - .with("") - .with(" ") - .with(" ") - .with(" ") - .with(" ") - .with("") - .createConnectedTo(receiver); - - metamorph.startRecord("1"); - metamorph.literal("data1", "A"); - metamorph.literal("data2", "B"); - metamorph.endRecord(); - metamorph.startRecord("2"); - metamorph.literal("data1", "B"); - metamorph.literal("data2", "A"); - metamorph.endRecord(); - metamorph.startRecord("3"); - metamorph.literal("data2", "C"); - metamorph.endRecord(); - - final InOrder ordered = inOrder(receiver); - ordered.verify(receiver).startRecord("1"); - ordered.verify(receiver).literal("data1", "A"); - ordered.verify(receiver).endRecord(); - ordered.verify(receiver).startRecord("2"); - ordered.verify(receiver).literal("data1", "B"); - ordered.verify(receiver).endRecord(); - ordered.verify(receiver).startRecord("3"); - ordered.verify(receiver).literal("data2", "C"); - ordered.verify(receiver).endRecord(); - ordered.verifyNoMoreInteractions(); - } - - @Test - public void shouldMakeChooseDecisionOnFlushEvent() { - metamorph = InlineMorph.in(this) - .with("") - .with(" ") - .with(" ") - .with(" ") - .with(" ") - .with("") - .createConnectedTo(receiver); - - metamorph.startRecord("1"); - metamorph.startEntity("entity"); - metamorph.literal("data1", "A"); - metamorph.literal("data2", "B"); - metamorph.endEntity(); - metamorph.startEntity("entity"); - metamorph.literal("data1", "B"); - metamorph.literal("data2", "A"); - metamorph.endEntity(); - metamorph.startEntity("entity"); - metamorph.literal("data2", "C"); - metamorph.endEntity(); - metamorph.startEntity("entity"); - metamorph.literal("dataX", "X"); - metamorph.endEntity(); - metamorph.endRecord(); - - final InOrder ordered = inOrder(receiver); - ordered.verify(receiver).startRecord("1"); - ordered.verify(receiver).literal("entity.data1", "A"); - ordered.verify(receiver).literal("entity.data1", "B"); - ordered.verify(receiver).literal("entity.data2", "C"); - ordered.verify(receiver).endRecord(); - ordered.verifyNoMoreInteractions(); - } - - @Test - public void issue110_shouldOutputFallBackIfFlushedWithEntity() { - metamorph = InlineMorph.in(this) - .with("") - .with(" ") - .with(" ") - .with(" ") - .with(" ") - .with("") - .createConnectedTo(receiver); - - metamorph.startRecord("1"); - metamorph.literal("L", "V"); - metamorph.endRecord(); - - final InOrder ordered = inOrder(receiver); - ordered.verify(receiver).startRecord("1"); - ordered.verify(receiver).literal("chosen", "V"); - ordered.verify(receiver).endRecord(); - ordered.verifyNoMoreInteractions(); - } - - @Test - public void issue210_issue49_shouldRepeatedlyEmitNamedValueIfResetIsFalse() { - metamorph = InlineMorph.in(this) - .with("") - .with(" ") - .with(" ") - .with(" ") - .with("") - .createConnectedTo(receiver); - - metamorph.startRecord("1"); - metamorph.literal("lit1", "data1"); - metamorph.literal("flush", "first"); - metamorph.literal("flush", "second"); - metamorph.endRecord(); - - final InOrder ordered = inOrder(receiver); - ordered.verify(receiver).startRecord("1"); - ordered.verify(receiver, times(2)).literal("lit1", "data1"); - ordered.verify(receiver).endRecord(); - ordered.verifyNoMoreInteractions(); - } - - @Test - public void issue210_shouldResetAfterEmittingNamedValueIfResetIsTrue() { - metamorph = InlineMorph.in(this) - .with("") - .with(" ") - .with(" ") - .with(" ") - .with("") - .createConnectedTo(receiver); - - metamorph.startRecord("1"); - metamorph.literal("lit1", "data1"); - metamorph.literal("flush", "first"); - metamorph.literal("flush", "second"); - metamorph.endRecord(); - - final InOrder ordered = inOrder(receiver); - ordered.verify(receiver).startRecord("1"); - ordered.verify(receiver, times(1)).literal("lit1", "data1"); - ordered.verify(receiver).endRecord(); - ordered.verifyNoMoreInteractions(); - } - - @Test - public void issue210_shouldResetAfterEmittingNamedValueByDefault() { - metamorph = InlineMorph.in(this) - .with("") - .with(" ") - .with(" ") - .with(" ") - .with("") - .createConnectedTo(receiver); - - metamorph.startRecord("1"); - metamorph.literal("lit1", "data1"); - metamorph.literal("flush", "first"); - metamorph.literal("flush", "second"); - metamorph.endRecord(); - - final InOrder ordered = inOrder(receiver); - ordered.verify(receiver).startRecord("1"); - ordered.verify(receiver, times(1)).literal("lit1", "data1"); - ordered.verify(receiver).endRecord(); - ordered.verifyNoMoreInteractions(); - } - - @Test - public void issue250_shouldResetOnEntityChangeIfSameEntityIsTrue() { - metamorph = InlineMorph.in(this) - .with("") - .with(" ") - .with(" ") - .with(" ") - .with(" ") - .with("") - .createConnectedTo(receiver); - - metamorph.startRecord("1"); - metamorph.startEntity("entity"); - metamorph.literal("lit1", "data1"); - metamorph.endEntity(); - metamorph.startEntity("entity"); - metamorph.literal("lit2", "data2"); - metamorph.endEntity(); - metamorph.endRecord(); - - final InOrder ordered = inOrder(receiver); - ordered.verify(receiver).startRecord("1"); - ordered.verify(receiver).literal("entity.lit2", "data2"); - ordered.verify(receiver).endRecord(); - ordered.verifyNoMoreInteractions(); - } - - @Test - public void issue250_shouldNotResetOnEntityChangeIfSameEntityIsFalse() { - metamorph = InlineMorph.in(this) - .with("") - .with(" ") - .with(" ") - .with(" ") - .with(" ") - .with("") - .createConnectedTo(receiver); - - metamorph.startRecord("1"); - metamorph.startEntity("entity"); - metamorph.literal("lit1", "data1"); - metamorph.endEntity(); - metamorph.startEntity("entity"); - metamorph.literal("lit2", "data2"); - metamorph.endEntity(); - metamorph.endRecord(); - - final InOrder ordered = inOrder(receiver); - ordered.verify(receiver).startRecord("1"); - ordered.verify(receiver).literal("entity.lit1", "data1"); - ordered.verify(receiver).endRecord(); - ordered.verifyNoMoreInteractions(); - } - - @Test - public void issue250_shouldNotResetOnEntityChangeByDefault() { - metamorph = InlineMorph.in(this) - .with("") - .with(" ") - .with(" ") - .with(" ") - .with(" ") - .with("") - .createConnectedTo(receiver); - - metamorph.startRecord("1"); - metamorph.startEntity("entity"); - metamorph.literal("lit1", "data1"); - metamorph.endEntity(); - metamorph.startEntity("entity"); - metamorph.literal("lit2", "data2"); - metamorph.endEntity(); - metamorph.endRecord(); - - final InOrder ordered = inOrder(receiver); - ordered.verify(receiver).startRecord("1"); - ordered.verify(receiver).literal("entity.lit1", "data1"); - ordered.verify(receiver).endRecord(); - ordered.verifyNoMoreInteractions(); - } + @Rule + public final MockitoRule mockitoRule = MockitoJUnit.rule(); + + @Mock + private StreamReceiver receiver; + + private Metamorph metamorph; + + @Test + public void shouldChooseValueOfTopMostFiringStatement() { + metamorph = InlineMorph.in(this) + .with("") + .with(" ") + .with(" ") + .with(" ") + .with(" ") + .with("") + .createConnectedTo(receiver); + + metamorph.startRecord("1"); + metamorph.literal("data1", "A"); + metamorph.literal("data2", "B"); + metamorph.endRecord(); + metamorph.startRecord("2"); + metamorph.literal("data1", "B"); + metamorph.literal("data2", "A"); + metamorph.endRecord(); + metamorph.startRecord("3"); + metamorph.literal("data2", "C"); + metamorph.endRecord(); + + final InOrder ordered = inOrder(receiver); + ordered.verify(receiver).startRecord("1"); + ordered.verify(receiver).literal("data1", "A"); + ordered.verify(receiver).endRecord(); + ordered.verify(receiver).startRecord("2"); + ordered.verify(receiver).literal("data1", "B"); + ordered.verify(receiver).endRecord(); + ordered.verify(receiver).startRecord("3"); + ordered.verify(receiver).literal("data2", "C"); + ordered.verify(receiver).endRecord(); + ordered.verifyNoMoreInteractions(); + } + + @Test + public void shouldMakeChooseDecisionOnFlushEvent() { + metamorph = InlineMorph.in(this) + .with("") + .with(" ") + .with(" ") + .with(" ") + .with(" ") + .with("") + .createConnectedTo(receiver); + + metamorph.startRecord("1"); + metamorph.startEntity("entity"); + metamorph.literal("data1", "A"); + metamorph.literal("data2", "B"); + metamorph.endEntity(); + metamorph.startEntity("entity"); + metamorph.literal("data1", "B"); + metamorph.literal("data2", "A"); + metamorph.endEntity(); + metamorph.startEntity("entity"); + metamorph.literal("data2", "C"); + metamorph.endEntity(); + metamorph.startEntity("entity"); + metamorph.literal("dataX", "X"); + metamorph.endEntity(); + metamorph.endRecord(); + + final InOrder ordered = inOrder(receiver); + ordered.verify(receiver).startRecord("1"); + ordered.verify(receiver).literal("entity.data1", "A"); + ordered.verify(receiver).literal("entity.data1", "B"); + ordered.verify(receiver).literal("entity.data2", "C"); + ordered.verify(receiver).endRecord(); + ordered.verifyNoMoreInteractions(); + } + + @Test + public void issue110_shouldOutputFallBackIfFlushedWithEntity() { + metamorph = InlineMorph.in(this) + .with("") + .with(" ") + .with(" ") + .with(" ") + .with(" ") + .with("") + .createConnectedTo(receiver); + + metamorph.startRecord("1"); + metamorph.literal("L", "V"); + metamorph.endRecord(); + + final InOrder ordered = inOrder(receiver); + ordered.verify(receiver).startRecord("1"); + ordered.verify(receiver).literal("chosen", "V"); + ordered.verify(receiver).endRecord(); + ordered.verifyNoMoreInteractions(); + } + + @Test + public void issue210_issue49_shouldRepeatedlyEmitNamedValueIfResetIsFalse() { + metamorph = InlineMorph.in(this) + .with("") + .with(" ") + .with(" ") + .with(" ") + .with("") + .createConnectedTo(receiver); + + metamorph.startRecord("1"); + metamorph.literal("lit1", "data1"); + metamorph.literal("flush", "first"); + metamorph.literal("flush", "second"); + metamorph.endRecord(); + + final InOrder ordered = inOrder(receiver); + ordered.verify(receiver).startRecord("1"); + ordered.verify(receiver, times(2)).literal("lit1", "data1"); + ordered.verify(receiver).endRecord(); + ordered.verifyNoMoreInteractions(); + } + + @Test + public void issue210_shouldResetAfterEmittingNamedValueIfResetIsTrue() { + metamorph = InlineMorph.in(this) + .with("") + .with(" ") + .with(" ") + .with(" ") + .with("") + .createConnectedTo(receiver); + + metamorph.startRecord("1"); + metamorph.literal("lit1", "data1"); + metamorph.literal("flush", "first"); + metamorph.literal("flush", "second"); + metamorph.endRecord(); + + final InOrder ordered = inOrder(receiver); + ordered.verify(receiver).startRecord("1"); + ordered.verify(receiver, times(1)).literal("lit1", "data1"); + ordered.verify(receiver).endRecord(); + ordered.verifyNoMoreInteractions(); + } + + @Test + public void issue210_shouldResetAfterEmittingNamedValueByDefault() { + metamorph = InlineMorph.in(this) + .with("") + .with(" ") + .with(" ") + .with(" ") + .with("") + .createConnectedTo(receiver); + + metamorph.startRecord("1"); + metamorph.literal("lit1", "data1"); + metamorph.literal("flush", "first"); + metamorph.literal("flush", "second"); + metamorph.endRecord(); + + final InOrder ordered = inOrder(receiver); + ordered.verify(receiver).startRecord("1"); + ordered.verify(receiver, times(1)).literal("lit1", "data1"); + ordered.verify(receiver).endRecord(); + ordered.verifyNoMoreInteractions(); + } + + @Test + public void issue250_shouldResetOnEntityChangeIfSameEntityIsTrue() { + metamorph = InlineMorph.in(this) + .with("") + .with(" ") + .with(" ") + .with(" ") + .with(" ") + .with("") + .createConnectedTo(receiver); + + metamorph.startRecord("1"); + metamorph.startEntity("entity"); + metamorph.literal("lit1", "data1"); + metamorph.endEntity(); + metamorph.startEntity("entity"); + metamorph.literal("lit2", "data2"); + metamorph.endEntity(); + metamorph.endRecord(); + + final InOrder ordered = inOrder(receiver); + ordered.verify(receiver).startRecord("1"); + ordered.verify(receiver).literal("entity.lit2", "data2"); + ordered.verify(receiver).endRecord(); + ordered.verifyNoMoreInteractions(); + } + + @Test + public void issue250_shouldNotResetOnEntityChangeIfSameEntityIsFalse() { + metamorph = InlineMorph.in(this) + .with("") + .with(" ") + .with(" ") + .with(" ") + .with(" ") + .with("") + .createConnectedTo(receiver); + + metamorph.startRecord("1"); + metamorph.startEntity("entity"); + metamorph.literal("lit1", "data1"); + metamorph.endEntity(); + metamorph.startEntity("entity"); + metamorph.literal("lit2", "data2"); + metamorph.endEntity(); + metamorph.endRecord(); + + final InOrder ordered = inOrder(receiver); + ordered.verify(receiver).startRecord("1"); + ordered.verify(receiver).literal("entity.lit1", "data1"); + ordered.verify(receiver).endRecord(); + ordered.verifyNoMoreInteractions(); + } + + @Test + public void issue250_shouldNotResetOnEntityChangeByDefault() { + metamorph = InlineMorph.in(this) + .with("") + .with(" ") + .with(" ") + .with(" ") + .with(" ") + .with("") + .createConnectedTo(receiver); + + metamorph.startRecord("1"); + metamorph.startEntity("entity"); + metamorph.literal("lit1", "data1"); + metamorph.endEntity(); + metamorph.startEntity("entity"); + metamorph.literal("lit2", "data2"); + metamorph.endEntity(); + metamorph.endRecord(); + + final InOrder ordered = inOrder(receiver); + ordered.verify(receiver).startRecord("1"); + ordered.verify(receiver).literal("entity.lit1", "data1"); + ordered.verify(receiver).endRecord(); + ordered.verifyNoMoreInteractions(); + } } diff --git a/metamorph/src/test/java/org/metafacture/metamorph/collectors/CombineTest.java b/metamorph/src/test/java/org/metafacture/metamorph/collectors/CombineTest.java index 75d56ef87..9cbfc4593 100644 --- a/metamorph/src/test/java/org/metafacture/metamorph/collectors/CombineTest.java +++ b/metamorph/src/test/java/org/metafacture/metamorph/collectors/CombineTest.java @@ -37,190 +37,190 @@ */ public final class CombineTest { - @Rule - public final MockitoRule mockitoRule = MockitoJUnit.rule(); - - @Mock - private StreamReceiver receiver; - - private Metamorph metamorph; - - @Test - public void shouldCombineTwoValues() { - metamorph = InlineMorph.in(this) - .with("") - .with(" ") - .with(" ") - .with(" ") - .with(" ") - .with("") - .createConnectedTo(receiver); - - metamorph.startRecord("1"); - metamorph.literal("data1", "a"); - metamorph.literal("data2", "b"); - metamorph.literal("data2", "c"); - metamorph.endRecord(); - - final InOrder ordered = inOrder(receiver); - ordered.verify(receiver).startRecord("1"); - ordered.verify(receiver).literal("combination", "ba"); - ordered.verify(receiver).literal("combination", "ca"); - ordered.verify(receiver).endRecord(); - ordered.verifyNoMoreInteractions(); - } - - @Test - public void shouldOnlyCombineValuesFromTheSameEntityIfSet() { - metamorph = InlineMorph.in(this) - .with("") - .with(" ") - .with(" ") - .with(" ") - .with(" ") - .with("") - .createConnectedTo(receiver); - - metamorph.startRecord("1"); - metamorph.startEntity("entity"); - metamorph.literal("data1", "b"); - metamorph.literal("data2", "a"); - metamorph.endEntity(); - metamorph.startEntity("entity"); - metamorph.literal("data2", "c"); - metamorph.literal("data2", "d"); - metamorph.endEntity(); - metamorph.startEntity("entity"); - metamorph.literal("data1", "e"); - metamorph.endEntity(); - metamorph.startEntity("entity"); - metamorph.literal("data2", "f"); - metamorph.literal("data1", "g"); - metamorph.endEntity(); - metamorph.endRecord(); - - final InOrder ordered = inOrder(receiver); - ordered.verify(receiver).startRecord("1"); - ordered.verify(receiver).literal("combination", "ab"); - ordered.verify(receiver).literal("combination", "fg"); - ordered.verify(receiver).endRecord(); - ordered.verifyNoMoreInteractions(); - } - - @Test - public void shouldResetCombinedValueIfResetIsTrue() { - metamorph = InlineMorph.in(this) - .with("") - .with(" ") - .with(" ") - .with(" ") - .with(" ") - .with("") - .createConnectedTo(receiver); - - metamorph.startRecord("1"); - metamorph.literal("data1", "b"); - metamorph.literal("data2", "a"); - metamorph.literal("data2", "c"); - metamorph.literal("data2", "d"); - metamorph.literal("data1", "e"); - metamorph.endRecord(); - - final InOrder ordered = inOrder(receiver); - ordered.verify(receiver).startRecord("1"); - ordered.verify(receiver).literal("combination", "ab"); - ordered.verify(receiver).literal("combination", "de"); - ordered.verify(receiver).endRecord(); - ordered.verifyNoMoreInteractions(); - } - - @Test - public void shouldEmitCurrentValueOnFlushEvent() { - metamorph = InlineMorph.in(this) - .with("") - .with(" ") - .with(" ") - .with(" ") - .with(" ") - .with("") - .createConnectedTo(receiver); - - metamorph.startRecord("1"); - metamorph.startEntity("e"); - metamorph.literal("l", "1"); - metamorph.endEntity(); - metamorph.startEntity("e"); - metamorph.literal("l", "2"); - metamorph.literal("m", "2"); - metamorph.endEntity(); - metamorph.startEntity("e"); - metamorph.literal("l", "3"); - metamorph.endEntity(); - metamorph.endRecord(); - - final InOrder ordered = inOrder(receiver); - ordered.verify(receiver).startRecord("1"); - ordered.verify(receiver).literal("combi", "1"); - ordered.verify(receiver).literal("combi", "22"); - ordered.verify(receiver).literal("combi", "3"); - ordered.verify(receiver).endRecord(); - ordered.verifyNoMoreInteractions(); - } - - @Test - public void shouldNotEmitCurrentValueOnFlushEventIfIncomplete() { - metamorph = InlineMorph.in(this) - .with("") - .with(" ") - .with(" ") - .with(" ") - .with(" ") - .with("") - .createConnectedTo(receiver); - - metamorph.startRecord("1"); - metamorph.startEntity("e"); - metamorph.literal("l", "1"); - metamorph.endEntity(); - metamorph.startEntity("e"); - metamorph.literal("l", "2"); - metamorph.literal("m", "2"); - metamorph.endEntity(); - metamorph.startEntity("e"); - metamorph.literal("l", "3"); - metamorph.endEntity(); - metamorph.endRecord(); - - final InOrder ordered = inOrder(receiver); - ordered.verify(receiver).startRecord("1"); - ordered.verify(receiver).literal("combi", "22"); - ordered.verify(receiver).endRecord(); - ordered.verifyNoMoreInteractions(); - verifyNoMoreInteractions(receiver); - } - - @Test - public void shouldPostprocessCombinedValue() { - metamorph = InlineMorph.in(this) - .with("") - .with(" ") - .with(" ") - .with(" ") - .with(" ") - .with(" ") - .with(" ") - .with("") - .createConnectedTo(receiver); - - metamorph.startRecord("1"); - metamorph.literal("inLit", "value"); - metamorph.endRecord(); - - final InOrder ordered = inOrder(receiver); - ordered.verify(receiver).startRecord("1"); - ordered.verify(receiver).literal("outLit", "VALUE"); - ordered.verify(receiver).endRecord(); - ordered.verifyNoMoreInteractions(); - } + @Rule + public final MockitoRule mockitoRule = MockitoJUnit.rule(); + + @Mock + private StreamReceiver receiver; + + private Metamorph metamorph; + + @Test + public void shouldCombineTwoValues() { + metamorph = InlineMorph.in(this) + .with("") + .with(" ") + .with(" ") + .with(" ") + .with(" ") + .with("") + .createConnectedTo(receiver); + + metamorph.startRecord("1"); + metamorph.literal("data1", "a"); + metamorph.literal("data2", "b"); + metamorph.literal("data2", "c"); + metamorph.endRecord(); + + final InOrder ordered = inOrder(receiver); + ordered.verify(receiver).startRecord("1"); + ordered.verify(receiver).literal("combination", "ba"); + ordered.verify(receiver).literal("combination", "ca"); + ordered.verify(receiver).endRecord(); + ordered.verifyNoMoreInteractions(); + } + + @Test + public void shouldOnlyCombineValuesFromTheSameEntityIfSet() { + metamorph = InlineMorph.in(this) + .with("") + .with(" ") + .with(" ") + .with(" ") + .with(" ") + .with("") + .createConnectedTo(receiver); + + metamorph.startRecord("1"); + metamorph.startEntity("entity"); + metamorph.literal("data1", "b"); + metamorph.literal("data2", "a"); + metamorph.endEntity(); + metamorph.startEntity("entity"); + metamorph.literal("data2", "c"); + metamorph.literal("data2", "d"); + metamorph.endEntity(); + metamorph.startEntity("entity"); + metamorph.literal("data1", "e"); + metamorph.endEntity(); + metamorph.startEntity("entity"); + metamorph.literal("data2", "f"); + metamorph.literal("data1", "g"); + metamorph.endEntity(); + metamorph.endRecord(); + + final InOrder ordered = inOrder(receiver); + ordered.verify(receiver).startRecord("1"); + ordered.verify(receiver).literal("combination", "ab"); + ordered.verify(receiver).literal("combination", "fg"); + ordered.verify(receiver).endRecord(); + ordered.verifyNoMoreInteractions(); + } + + @Test + public void shouldResetCombinedValueIfResetIsTrue() { + metamorph = InlineMorph.in(this) + .with("") + .with(" ") + .with(" ") + .with(" ") + .with(" ") + .with("") + .createConnectedTo(receiver); + + metamorph.startRecord("1"); + metamorph.literal("data1", "b"); + metamorph.literal("data2", "a"); + metamorph.literal("data2", "c"); + metamorph.literal("data2", "d"); + metamorph.literal("data1", "e"); + metamorph.endRecord(); + + final InOrder ordered = inOrder(receiver); + ordered.verify(receiver).startRecord("1"); + ordered.verify(receiver).literal("combination", "ab"); + ordered.verify(receiver).literal("combination", "de"); + ordered.verify(receiver).endRecord(); + ordered.verifyNoMoreInteractions(); + } + + @Test + public void shouldEmitCurrentValueOnFlushEvent() { + metamorph = InlineMorph.in(this) + .with("") + .with(" ") + .with(" ") + .with(" ") + .with(" ") + .with("") + .createConnectedTo(receiver); + + metamorph.startRecord("1"); + metamorph.startEntity("e"); + metamorph.literal("l", "1"); + metamorph.endEntity(); + metamorph.startEntity("e"); + metamorph.literal("l", "2"); + metamorph.literal("m", "2"); + metamorph.endEntity(); + metamorph.startEntity("e"); + metamorph.literal("l", "3"); + metamorph.endEntity(); + metamorph.endRecord(); + + final InOrder ordered = inOrder(receiver); + ordered.verify(receiver).startRecord("1"); + ordered.verify(receiver).literal("combi", "1"); + ordered.verify(receiver).literal("combi", "22"); + ordered.verify(receiver).literal("combi", "3"); + ordered.verify(receiver).endRecord(); + ordered.verifyNoMoreInteractions(); + } + + @Test + public void shouldNotEmitCurrentValueOnFlushEventIfIncomplete() { + metamorph = InlineMorph.in(this) + .with("") + .with(" ") + .with(" ") + .with(" ") + .with(" ") + .with("") + .createConnectedTo(receiver); + + metamorph.startRecord("1"); + metamorph.startEntity("e"); + metamorph.literal("l", "1"); + metamorph.endEntity(); + metamorph.startEntity("e"); + metamorph.literal("l", "2"); + metamorph.literal("m", "2"); + metamorph.endEntity(); + metamorph.startEntity("e"); + metamorph.literal("l", "3"); + metamorph.endEntity(); + metamorph.endRecord(); + + final InOrder ordered = inOrder(receiver); + ordered.verify(receiver).startRecord("1"); + ordered.verify(receiver).literal("combi", "22"); + ordered.verify(receiver).endRecord(); + ordered.verifyNoMoreInteractions(); + verifyNoMoreInteractions(receiver); + } + + @Test + public void shouldPostprocessCombinedValue() { + metamorph = InlineMorph.in(this) + .with("") + .with(" ") + .with(" ") + .with(" ") + .with(" ") + .with(" ") + .with(" ") + .with("") + .createConnectedTo(receiver); + + metamorph.startRecord("1"); + metamorph.literal("inLit", "value"); + metamorph.endRecord(); + + final InOrder ordered = inOrder(receiver); + ordered.verify(receiver).startRecord("1"); + ordered.verify(receiver).literal("outLit", "VALUE"); + ordered.verify(receiver).endRecord(); + ordered.verifyNoMoreInteractions(); + } } diff --git a/metamorph/src/test/java/org/metafacture/metamorph/collectors/ConcatTest.java b/metamorph/src/test/java/org/metafacture/metamorph/collectors/ConcatTest.java index 83821782b..cfd9b52bb 100644 --- a/metamorph/src/test/java/org/metafacture/metamorph/collectors/ConcatTest.java +++ b/metamorph/src/test/java/org/metafacture/metamorph/collectors/ConcatTest.java @@ -36,170 +36,170 @@ */ public final class ConcatTest { - @Rule - public final MockitoRule mockitoRule = MockitoJUnit.rule(); - - @Mock - private StreamReceiver receiver; - - private Metamorph metamorph; - - @Test - public void shouldConcatenateValues() { - metamorph = InlineMorph.in(this) - .with("") - .with(" ") - .with(" ") - .with(" ") - .with(" ") - .with("") - .createConnectedTo(receiver); - - metamorph.startRecord("1"); - metamorph.literal("data1", "a"); - metamorph.literal("data1", "b"); - metamorph.literal("data2", "c"); - metamorph.endRecord(); - metamorph.startRecord("2"); - metamorph.literal("data1", "d"); - metamorph.literal("data1", "e"); - metamorph.literal("data2", "f"); - metamorph.endRecord(); - - final InOrder ordered = inOrder(receiver); - ordered.verify(receiver).startRecord("1"); - ordered.verify(receiver).literal("concat", "{a, b, c}"); - ordered.verify(receiver).endRecord(); - ordered.verify(receiver).startRecord("2"); - ordered.verify(receiver).literal("concat", "{d, e, f}"); - ordered.verify(receiver).endRecord(); - ordered.verifyNoMoreInteractions(); - } - - @Test - public void shouldEmitConcatenatedValueOnFlushEvent() { - metamorph = InlineMorph.in(this) - .with("") - .with(" ") - .with(" ") - .with(" ") - .with("") - .createConnectedTo(receiver); - - metamorph.startRecord("1"); - metamorph.startEntity("d"); - metamorph.literal("1", "a"); - metamorph.literal("1", "b"); - metamorph.endEntity(); - metamorph.startEntity("d"); - metamorph.literal("1", "e"); - metamorph.literal("1", "f"); - metamorph.endEntity(); - metamorph.startEntity("d"); - metamorph.literal("2", "e"); - metamorph.endEntity(); - metamorph.endRecord(); - - final InOrder ordered = inOrder(receiver); - ordered.verify(receiver).startRecord("1"); - ordered.verify(receiver).literal("concat", "{a, b}"); - ordered.verify(receiver).literal("concat", "{e, f}"); - ordered.verify(receiver).endRecord(); - ordered.verifyNoMoreInteractions(); - } - - @Test - public void shouldEmitEmptyValues() { - metamorph = InlineMorph.in(this) - .with("") - .with(" ") - .with(" ") - .with(" ") - .with(" ") - .with("") - .createConnectedTo(receiver); - - metamorph.startRecord("1"); - metamorph.literal("litA", ""); - metamorph.literal("litB", "a"); - metamorph.literal("litA", "b"); - metamorph.endRecord(); - - final InOrder ordered = inOrder(receiver); - ordered.verify(receiver).startRecord("1"); - ordered.verify(receiver).literal("concat", ", a, b"); - ordered.verify(receiver).endRecord(); - ordered.verifyNoMoreInteractions(); - } - - @Test - public void shouldReverseConcatenationIfReverseIsTrue() { - metamorph = InlineMorph.in(this) - .with("") - .with(" ") - .with(" ") - .with(" ") - .with(" ") - .with("") - .createConnectedTo(receiver); - - metamorph.startRecord("1"); - metamorph.literal("litA", "1"); - metamorph.literal("litB", "2"); - metamorph.literal("litA", "3"); - metamorph.endRecord(); - - final InOrder ordered = inOrder(receiver); - ordered.verify(receiver).startRecord("1"); - ordered.verify(receiver).literal("concat", "3, 2, 1"); - ordered.verify(receiver).endRecord(); - ordered.verifyNoMoreInteractions(); - } - - @Test - public void prefixAndPostfixShouldWorkAsNormalIfReverseIsTrue() { - metamorph = InlineMorph.in(this) - .with("") - .with(" ") - .with(" ") - .with(" ") - .with(" ") - .with("") - .createConnectedTo(receiver); - - metamorph.startRecord("1"); - metamorph.literal("litA", "1"); - metamorph.literal("litB", "2"); - metamorph.literal("litA", "3"); - metamorph.endRecord(); - - final InOrder ordered = inOrder(receiver); - ordered.verify(receiver).startRecord("1"); - ordered.verify(receiver).literal("concat", "(3, 2, 1)"); - ordered.verify(receiver).endRecord(); - ordered.verifyNoMoreInteractions(); - } - - @Test - public void issue187_shouldUseEmptyDelimiterAsDefault() { - metamorph = InlineMorph.in(this) - .with("") - .with(" ") - .with(" ") - .with(" ") - .with("") - .createConnectedTo(receiver); - - metamorph.startRecord("1"); - metamorph.literal("lit", "data1"); - metamorph.literal("lit", "data2"); - metamorph.endRecord(); - - final InOrder ordered = inOrder(receiver); - ordered.verify(receiver).startRecord("1"); - ordered.verify(receiver).literal("concat", "data1data2"); - ordered.verify(receiver).endRecord(); - ordered.verifyNoMoreInteractions(); - } + @Rule + public final MockitoRule mockitoRule = MockitoJUnit.rule(); + + @Mock + private StreamReceiver receiver; + + private Metamorph metamorph; + + @Test + public void shouldConcatenateValues() { + metamorph = InlineMorph.in(this) + .with("") + .with(" ") + .with(" ") + .with(" ") + .with(" ") + .with("") + .createConnectedTo(receiver); + + metamorph.startRecord("1"); + metamorph.literal("data1", "a"); + metamorph.literal("data1", "b"); + metamorph.literal("data2", "c"); + metamorph.endRecord(); + metamorph.startRecord("2"); + metamorph.literal("data1", "d"); + metamorph.literal("data1", "e"); + metamorph.literal("data2", "f"); + metamorph.endRecord(); + + final InOrder ordered = inOrder(receiver); + ordered.verify(receiver).startRecord("1"); + ordered.verify(receiver).literal("concat", "{a, b, c}"); + ordered.verify(receiver).endRecord(); + ordered.verify(receiver).startRecord("2"); + ordered.verify(receiver).literal("concat", "{d, e, f}"); + ordered.verify(receiver).endRecord(); + ordered.verifyNoMoreInteractions(); + } + + @Test + public void shouldEmitConcatenatedValueOnFlushEvent() { + metamorph = InlineMorph.in(this) + .with("") + .with(" ") + .with(" ") + .with(" ") + .with("") + .createConnectedTo(receiver); + + metamorph.startRecord("1"); + metamorph.startEntity("d"); + metamorph.literal("1", "a"); + metamorph.literal("1", "b"); + metamorph.endEntity(); + metamorph.startEntity("d"); + metamorph.literal("1", "e"); + metamorph.literal("1", "f"); + metamorph.endEntity(); + metamorph.startEntity("d"); + metamorph.literal("2", "e"); + metamorph.endEntity(); + metamorph.endRecord(); + + final InOrder ordered = inOrder(receiver); + ordered.verify(receiver).startRecord("1"); + ordered.verify(receiver).literal("concat", "{a, b}"); + ordered.verify(receiver).literal("concat", "{e, f}"); + ordered.verify(receiver).endRecord(); + ordered.verifyNoMoreInteractions(); + } + + @Test + public void shouldEmitEmptyValues() { + metamorph = InlineMorph.in(this) + .with("") + .with(" ") + .with(" ") + .with(" ") + .with(" ") + .with("") + .createConnectedTo(receiver); + + metamorph.startRecord("1"); + metamorph.literal("litA", ""); + metamorph.literal("litB", "a"); + metamorph.literal("litA", "b"); + metamorph.endRecord(); + + final InOrder ordered = inOrder(receiver); + ordered.verify(receiver).startRecord("1"); + ordered.verify(receiver).literal("concat", ", a, b"); + ordered.verify(receiver).endRecord(); + ordered.verifyNoMoreInteractions(); + } + + @Test + public void shouldReverseConcatenationIfReverseIsTrue() { + metamorph = InlineMorph.in(this) + .with("") + .with(" ") + .with(" ") + .with(" ") + .with(" ") + .with("") + .createConnectedTo(receiver); + + metamorph.startRecord("1"); + metamorph.literal("litA", "1"); + metamorph.literal("litB", "2"); + metamorph.literal("litA", "3"); + metamorph.endRecord(); + + final InOrder ordered = inOrder(receiver); + ordered.verify(receiver).startRecord("1"); + ordered.verify(receiver).literal("concat", "3, 2, 1"); + ordered.verify(receiver).endRecord(); + ordered.verifyNoMoreInteractions(); + } + + @Test + public void prefixAndPostfixShouldWorkAsNormalIfReverseIsTrue() { + metamorph = InlineMorph.in(this) + .with("") + .with(" ") + .with(" ") + .with(" ") + .with(" ") + .with("") + .createConnectedTo(receiver); + + metamorph.startRecord("1"); + metamorph.literal("litA", "1"); + metamorph.literal("litB", "2"); + metamorph.literal("litA", "3"); + metamorph.endRecord(); + + final InOrder ordered = inOrder(receiver); + ordered.verify(receiver).startRecord("1"); + ordered.verify(receiver).literal("concat", "(3, 2, 1)"); + ordered.verify(receiver).endRecord(); + ordered.verifyNoMoreInteractions(); + } + + @Test + public void issue187_shouldUseEmptyDelimiterAsDefault() { + metamorph = InlineMorph.in(this) + .with("") + .with(" ") + .with(" ") + .with(" ") + .with("") + .createConnectedTo(receiver); + + metamorph.startRecord("1"); + metamorph.literal("lit", "data1"); + metamorph.literal("lit", "data2"); + metamorph.endRecord(); + + final InOrder ordered = inOrder(receiver); + ordered.verify(receiver).startRecord("1"); + ordered.verify(receiver).literal("concat", "data1data2"); + ordered.verify(receiver).endRecord(); + ordered.verifyNoMoreInteractions(); + } } diff --git a/metamorph/src/test/java/org/metafacture/metamorph/collectors/EntityTest.java b/metamorph/src/test/java/org/metafacture/metamorph/collectors/EntityTest.java index 83a53ffc4..2b17df6a6 100644 --- a/metamorph/src/test/java/org/metafacture/metamorph/collectors/EntityTest.java +++ b/metamorph/src/test/java/org/metafacture/metamorph/collectors/EntityTest.java @@ -39,515 +39,515 @@ */ public final class EntityTest { - @Rule - public final MockitoRule mockitoRule = MockitoJUnit.rule(); - - @Mock - private StreamReceiver receiver; - - private Metamorph metamorph; - - @Test - public void shouldEmitEntities() { - metamorph = InlineMorph.in(this) - .with("") - .with(" ") - .with(" ") - .with(" ") - .with(" ") - .with("") - .createConnectedTo(receiver); - - metamorph.startRecord("1x"); - metamorph.literal("data1", "a1"); - metamorph.literal("data1", "a2"); - metamorph.literal("data2", "b"); - metamorph.endRecord(); - metamorph.startRecord("2x"); - metamorph.literal("data2", "c"); - metamorph.literal("data1", "d"); - metamorph.endRecord(); - - final InOrder ordered = inOrder(receiver); - ordered.verify(receiver).startRecord("1x"); - ordered.verify(receiver).startEntity("entity"); - ordered.verify(receiver).literal("l1", "a1"); - ordered.verify(receiver).literal("l1", "a2"); - ordered.verify(receiver).literal("l2", "b"); - ordered.verify(receiver).endEntity(); - ordered.verify(receiver).endRecord(); - ordered.verify(receiver).startRecord("2x"); - ordered.verify(receiver).startEntity("entity"); - ordered.verify(receiver).literal("l2", "c"); - ordered.verify(receiver).literal("l1", "d"); - ordered.verify(receiver).endEntity(); - ordered.verify(receiver).endRecord(); - ordered.verifyNoMoreInteractions(); - } - - @Test - public void shouldEmitEntityOnFlushEvent() { - metamorph = InlineMorph.in(this) - .with("") - .with(" ") - .with(" ") - .with(" ") - .with(" ") - .with("") - .createConnectedTo(receiver); - - metamorph.startRecord("1"); - metamorph.literal("d1", "a"); - metamorph.literal("d1", "b"); - metamorph.literal("d2", "c"); - metamorph.endRecord(); - metamorph.startRecord("2"); - metamorph.literal("d2", "c"); - metamorph.endRecord(); - - final InOrder ordered = inOrder(receiver); - ordered.verify(receiver).startRecord("1"); - ordered.verify(receiver).startEntity("entity"); - ordered.verify(receiver).literal("l1", "a"); - ordered.verify(receiver).literal("l1", "b"); - ordered.verify(receiver).literal("l2", "c"); - ordered.verify(receiver).endEntity(); - ordered.verify(receiver).endRecord(); - ordered.verify(receiver).startRecord("2"); - ordered.verify(receiver).startEntity("entity"); - ordered.verify(receiver).literal("l2", "c"); - ordered.verify(receiver).endEntity(); - ordered.verify(receiver).endRecord(); - ordered.verifyNoMoreInteractions(); - } - - @Test - public void shouldNotEmitEntityOnFlushEventIfIncomplete() { - metamorph = InlineMorph.in(this) - .with("") - .with(" ") - .with(" ") - .with(" ") - .with(" ") - .with("") - .createConnectedTo(receiver); - - metamorph.startRecord("1"); - metamorph.literal("d1", "a"); - metamorph.literal("d1", "b"); - metamorph.literal("d2", "c"); - metamorph.endRecord(); - metamorph.startRecord("2"); - metamorph.literal("d2", "c"); - metamorph.endRecord(); - - final InOrder ordered = inOrder(receiver); - ordered.verify(receiver).startRecord("1"); - ordered.verify(receiver).startEntity("entity"); - ordered.verify(receiver).literal("l1", "a"); - ordered.verify(receiver).literal("l1", "b"); - ordered.verify(receiver).literal("l2", "c"); - ordered.verify(receiver).endEntity(); - ordered.verify(receiver).endRecord(); - ordered.verify(receiver).startRecord("2"); - ordered.verify(receiver).endRecord(); - ordered.verifyNoMoreInteractions(); - verifyNoMoreInteractions(receiver); - } - - @Test - public void shouldEmitEntityOnEachFlushEvent() { - metamorph = InlineMorph.in(this) - .with("") - .with(" ") - .with(" ") - .with(" ") - .with(" ") - .with(" ") - .with(" ") - .with("") - .createConnectedTo(receiver); - - metamorph.startRecord("1"); - metamorph.startEntity("E"); - metamorph.literal("d1", "a"); - metamorph.literal("d2", "b"); - metamorph.endEntity(); - metamorph.startEntity("E"); - metamorph.literal("d1", "c"); - metamorph.literal("d2", "d"); - metamorph.endEntity(); - metamorph.endRecord(); - - final InOrder ordered = inOrder(receiver); - ordered.verify(receiver).startRecord("1"); - ordered.verify(receiver).startEntity("entity"); - ordered.verify(receiver).literal("l1", "a"); - ordered.verify(receiver).literal("l2", "b"); - ordered.verify(receiver).endEntity(); - ordered.verify(receiver).startEntity("entity"); - ordered.verify(receiver).literal("l1", "c"); - ordered.verify(receiver).literal("l2", "d"); - ordered.verify(receiver).endEntity(); - ordered.verify(receiver).endRecord(); - ordered.verifyNoMoreInteractions(); - } - - @Test - public void shouldSupportNestedEntities() { - metamorph = InlineMorph.in(this) - .with("") - .with(" ") - .with(" ") - .with(" ") - .with(" ") - .with(" ") - .with(" ") - .with(" ") - .with(" ") - .with("") - .createConnectedTo(receiver); - - metamorph.startRecord("1"); - metamorph.literal("d1", "a"); - metamorph.literal("d2", "b"); - metamorph.literal("d3", "c"); - metamorph.endRecord(); - metamorph.startRecord("2"); - metamorph.literal("d1", "d"); - metamorph.literal("d2", "e"); - metamorph.literal("d3", "f"); - metamorph.endRecord(); - metamorph.startRecord("3"); - metamorph.literal("d1", "a"); - metamorph.literal("d3", "c"); - metamorph.endRecord(); - - final InOrder ordered = inOrder(receiver); - ordered.verify(receiver).startRecord("1"); - ordered.verify(receiver).startEntity("e1"); - ordered.verify(receiver).literal("d1", "a"); - ordered.verify(receiver).literal("d2", "b"); - ordered.verify(receiver).startEntity("e2"); - ordered.verify(receiver).literal("d3", "c"); - ordered.verify(receiver, times(2)).endEntity(); - ordered.verify(receiver).endRecord(); - ordered.verify(receiver).startRecord("2"); - ordered.verify(receiver).startEntity("e1"); - ordered.verify(receiver).literal("d1", "d"); - ordered.verify(receiver).literal("d2", "e"); - ordered.verify(receiver).startEntity("e2"); - ordered.verify(receiver).literal("d3", "f"); - ordered.verify(receiver, times(2)).endEntity(); - ordered.verify(receiver).endRecord(); - ordered.verify(receiver).startRecord("3"); - ordered.verify(receiver).startEntity("e1"); - ordered.verify(receiver).literal("d1", "a"); - ordered.verify(receiver).startEntity("e2"); - ordered.verify(receiver).literal("d3", "c"); - ordered.verify(receiver, times(2)).endEntity(); - ordered.verify(receiver).endRecord(); - ordered.verifyNoMoreInteractions(); - } - - @Test - public void shouldSupportMultipleNestedEntities() { - metamorph = InlineMorph.in(this) - .with("") - .with(" ") - .with(" ") - .with(" ") - .with(" ") - .with(" ") - .with(" ") - .with(" ") - .with(" ") - .with(" ") - .with(" ") - .with("") - .createConnectedTo(receiver); - - metamorph.startRecord("1x"); - metamorph.startEntity("E"); - metamorph.literal("d1", "a"); - metamorph.literal("d2", "b"); - metamorph.endEntity(); - metamorph.startEntity("E"); - metamorph.literal("d1", "x"); - metamorph.endEntity(); - metamorph.startEntity("E"); - metamorph.literal("d1", "c"); - metamorph.literal("d2", "d"); - metamorph.endEntity(); - metamorph.literal("d", "c"); - metamorph.endRecord(); - metamorph.startRecord("2x"); - metamorph.literal("d", "c"); - metamorph.endRecord(); - - final InOrder ordered = inOrder(receiver); - ordered.verify(receiver).startRecord("1x"); - ordered.verify(receiver).startEntity("uber"); - ordered.verify(receiver).startEntity("unter"); - ordered.verify(receiver).literal("l", "a"); - ordered.verify(receiver).literal("l", "b"); - ordered.verify(receiver).endEntity(); - ordered.verify(receiver).startEntity("unter"); - ordered.verify(receiver).literal("l", "c"); - ordered.verify(receiver).literal("l", "d"); - ordered.verify(receiver).endEntity(); - ordered.verify(receiver).literal("l", "c"); - ordered.verify(receiver).endEntity(); - ordered.verify(receiver).endRecord(); - ordered.verify(receiver).startRecord("2x"); - ordered.verify(receiver).startEntity("uber"); - ordered.verify(receiver).literal("l", "c"); - ordered.verify(receiver).endEntity(); - ordered.verify(receiver).endRecord(); - ordered.verifyNoMoreInteractions(); - } - - @Test - public void shouldSupportDeeplyNestedEnities() { - metamorph = InlineMorph.in(this) - .with("") - .with(" ") - .with(" ") - .with(" ") - .with(" ") - .with(" ") - .with(" ") - .with(" ") - .with(" ") - .with(" ") - .with(" ") - .with(" ") - .with("") - .createConnectedTo(receiver); - - metamorph.startRecord("1x"); - metamorph.literal("1", "a"); - metamorph.literal("2", "b"); - metamorph.literal("4", "c"); - metamorph.endRecord(); - - final InOrder ordered = inOrder(receiver); - ordered.verify(receiver).startRecord("1x"); - ordered.verify(receiver).startEntity("1"); - ordered.verify(receiver).literal("1", "a"); - ordered.verify(receiver).startEntity("2"); - ordered.verify(receiver).literal("2", "b"); - ordered.verify(receiver).startEntity("3"); - ordered.verify(receiver).startEntity("4"); - ordered.verify(receiver).literal("4", "c"); - ordered.verify(receiver, times(4)).endEntity(); - ordered.verify(receiver).endRecord(); - ordered.verifyNoMoreInteractions(); - } - - @Test - public void shouldGetNameFromDataInEntityName() { - metamorph = InlineMorph.in(this) - .with("") - .with(" ") - .with(" ") - .with(" ") - .with(" ") - .with(" ") - .with(" ") - .with(" ") - .with(" ") - .with(" ") - .with("") - .createConnectedTo(receiver); - - metamorph.startRecord("1x"); - metamorph.literal("data1", "a1"); - metamorph.literal("data1", "a2"); - metamorph.literal("data2", "b"); - metamorph.endRecord(); - metamorph.startRecord("2x"); - metamorph.literal("data2", "c"); - metamorph.literal("data1", "d"); - metamorph.endRecord(); - - final InOrder ordered = inOrder(receiver); - ordered.verify(receiver).startRecord("1x"); - ordered.verify(receiver).startEntity("entity:a2"); - ordered.verify(receiver).literal("l1", "a1"); - ordered.verify(receiver).literal("l1", "a2"); - ordered.verify(receiver).literal("l2", "b"); - ordered.verify(receiver).endEntity(); - ordered.verify(receiver).endRecord(); - ordered.verify(receiver).startRecord("2x"); - ordered.verify(receiver).startEntity("entity:d"); - ordered.verify(receiver).literal("l2", "c"); - ordered.verify(receiver).literal("l1", "d"); - ordered.verify(receiver).endEntity(); - ordered.verify(receiver).endRecord(); - ordered.verifyNoMoreInteractions(); - } - - @Test - public void shouldGetNameFromCollectInEntityName() { - metamorph = InlineMorph.in(this) - .with("") - .with(" ") - .with(" ") - .with(" ") - .with(" ") - .with(" ") - .with(" ") - .with(" ") - .with(" ") - .with(" ") - .with(" ") - .with("") - .createConnectedTo(receiver); - - metamorph.startRecord("1x"); - metamorph.literal("data1", "a1"); - metamorph.literal("data1", "a2"); - metamorph.literal("data2", "b"); - metamorph.endRecord(); - metamorph.startRecord("2x"); - metamorph.literal("data2", "c"); - metamorph.literal("data1", "d"); - metamorph.endRecord(); - - final InOrder ordered = inOrder(receiver); - ordered.verify(receiver).startRecord("1x"); - ordered.verify(receiver).startEntity("entity:a2,b"); - ordered.verify(receiver).literal("l1", "a1"); - ordered.verify(receiver).literal("l1", "a2"); - ordered.verify(receiver).literal("l2", "b"); - ordered.verify(receiver).endEntity(); - ordered.verify(receiver).endRecord(); - ordered.verify(receiver).startRecord("2x"); - ordered.verify(receiver).startEntity("entity:d,c"); - ordered.verify(receiver).literal("l2", "c"); - ordered.verify(receiver).literal("l1", "d"); - ordered.verify(receiver).endEntity(); - ordered.verify(receiver).endRecord(); - ordered.verifyNoMoreInteractions(); - } - - @Test - public void shouldResetNameToNameAttribute() { - metamorph = InlineMorph.in(this) - .with("") - .with(" ") - .with(" ") - .with(" ") - .with(" ") - .with(" ") - .with(" ") - .with("") - .createConnectedTo(receiver); - - metamorph.startRecord("1x"); - metamorph.literal("data1", "a"); - metamorph.literal("data3", "dynamicName"); - metamorph.endRecord(); - metamorph.startRecord("2x"); - metamorph.literal("data1", "b"); - metamorph.endRecord(); - - final InOrder ordered = inOrder(receiver); - ordered.verify(receiver).startRecord("1x"); - ordered.verify(receiver).startEntity("dynamicName"); - ordered.verify(receiver).literal("l1", "a"); - ordered.verify(receiver).endEntity(); - ordered.verify(receiver).endRecord(); - ordered.verify(receiver).startRecord("2x"); - ordered.verify(receiver).startEntity("defaultName"); - ordered.verify(receiver).literal("l1", "b"); - ordered.verify(receiver).endEntity(); - ordered.verify(receiver).endRecord(); - ordered.verifyNoMoreInteractions(); - } - - @Test - public void shouldEmitEmptyStringIfEntityNameIsNotSet() { - metamorph = InlineMorph.in(this) - .with("") - .with(" ") - .with(" ") - .with(" ") - .with("") - .createConnectedTo(receiver); - - metamorph.startRecord("1"); - metamorph.literal("in", "a"); - metamorph.endRecord(); - - final InOrder ordered = inOrder(receiver); - ordered.verify(receiver).startRecord("1"); - ordered.verify(receiver).startEntity(""); - ordered.verify(receiver).literal("out", "a"); - ordered.verify(receiver).endEntity(); - ordered.verify(receiver).endRecord(); - ordered.verifyNoMoreInteractions(); - } - - @Test - public void shouldEmitEntityContentsAgainIfResetIsFalse() { - metamorph = InlineMorph.in(this) - .with("") - .with(" ") - .with(" ") - .with(" ") - .with(" ") - .with("") - .createConnectedTo(receiver); - - metamorph.startRecord("1"); - metamorph.literal("lit1", "const"); - metamorph.literal("lit2", "1"); - metamorph.literal("lit2", "2"); - metamorph.endRecord(); - - final InOrder ordered = inOrder(receiver); - ordered.verify(receiver).startRecord("1"); - ordered.verify(receiver).startEntity("entity"); - ordered.verify(receiver).literal("lit1", "const"); - ordered.verify(receiver).literal("lit2", "1"); - ordered.verify(receiver).endEntity(); - ordered.verify(receiver).startEntity("entity"); - ordered.verify(receiver).literal("lit1", "const"); - ordered.verify(receiver).literal("lit2", "1"); - ordered.verify(receiver).literal("lit2", "2"); - ordered.verify(receiver).endEntity(); - ordered.verify(receiver).endRecord(); - ordered.verifyNoMoreInteractions(); - } - - @Test - public void shouldNotEmitEntityContentsAgainIfResetIsTrue() { - metamorph = InlineMorph.in(this) - .with("") - .with(" ") - .with(" ") - .with(" ") - .with(" ") - .with("") - .createConnectedTo(receiver); - - metamorph.startRecord("1"); - metamorph.literal("lit1", "const"); - metamorph.literal("lit2", "1"); - metamorph.literal("lit2", "2"); - metamorph.endRecord(); - - final InOrder ordered = inOrder(receiver); - ordered.verify(receiver).startRecord("1"); - ordered.verify(receiver).startEntity("entity"); - ordered.verify(receiver).literal("lit1", "const"); - ordered.verify(receiver).literal("lit2", "1"); - ordered.verify(receiver).endEntity(); - ordered.verify(receiver).endRecord(); - ordered.verifyNoMoreInteractions(); - } + @Rule + public final MockitoRule mockitoRule = MockitoJUnit.rule(); + + @Mock + private StreamReceiver receiver; + + private Metamorph metamorph; + + @Test + public void shouldEmitEntities() { + metamorph = InlineMorph.in(this) + .with("") + .with(" ") + .with(" ") + .with(" ") + .with(" ") + .with("") + .createConnectedTo(receiver); + + metamorph.startRecord("1x"); + metamorph.literal("data1", "a1"); + metamorph.literal("data1", "a2"); + metamorph.literal("data2", "b"); + metamorph.endRecord(); + metamorph.startRecord("2x"); + metamorph.literal("data2", "c"); + metamorph.literal("data1", "d"); + metamorph.endRecord(); + + final InOrder ordered = inOrder(receiver); + ordered.verify(receiver).startRecord("1x"); + ordered.verify(receiver).startEntity("entity"); + ordered.verify(receiver).literal("l1", "a1"); + ordered.verify(receiver).literal("l1", "a2"); + ordered.verify(receiver).literal("l2", "b"); + ordered.verify(receiver).endEntity(); + ordered.verify(receiver).endRecord(); + ordered.verify(receiver).startRecord("2x"); + ordered.verify(receiver).startEntity("entity"); + ordered.verify(receiver).literal("l2", "c"); + ordered.verify(receiver).literal("l1", "d"); + ordered.verify(receiver).endEntity(); + ordered.verify(receiver).endRecord(); + ordered.verifyNoMoreInteractions(); + } + + @Test + public void shouldEmitEntityOnFlushEvent() { + metamorph = InlineMorph.in(this) + .with("") + .with(" ") + .with(" ") + .with(" ") + .with(" ") + .with("") + .createConnectedTo(receiver); + + metamorph.startRecord("1"); + metamorph.literal("d1", "a"); + metamorph.literal("d1", "b"); + metamorph.literal("d2", "c"); + metamorph.endRecord(); + metamorph.startRecord("2"); + metamorph.literal("d2", "c"); + metamorph.endRecord(); + + final InOrder ordered = inOrder(receiver); + ordered.verify(receiver).startRecord("1"); + ordered.verify(receiver).startEntity("entity"); + ordered.verify(receiver).literal("l1", "a"); + ordered.verify(receiver).literal("l1", "b"); + ordered.verify(receiver).literal("l2", "c"); + ordered.verify(receiver).endEntity(); + ordered.verify(receiver).endRecord(); + ordered.verify(receiver).startRecord("2"); + ordered.verify(receiver).startEntity("entity"); + ordered.verify(receiver).literal("l2", "c"); + ordered.verify(receiver).endEntity(); + ordered.verify(receiver).endRecord(); + ordered.verifyNoMoreInteractions(); + } + + @Test + public void shouldNotEmitEntityOnFlushEventIfIncomplete() { + metamorph = InlineMorph.in(this) + .with("") + .with(" ") + .with(" ") + .with(" ") + .with(" ") + .with("") + .createConnectedTo(receiver); + + metamorph.startRecord("1"); + metamorph.literal("d1", "a"); + metamorph.literal("d1", "b"); + metamorph.literal("d2", "c"); + metamorph.endRecord(); + metamorph.startRecord("2"); + metamorph.literal("d2", "c"); + metamorph.endRecord(); + + final InOrder ordered = inOrder(receiver); + ordered.verify(receiver).startRecord("1"); + ordered.verify(receiver).startEntity("entity"); + ordered.verify(receiver).literal("l1", "a"); + ordered.verify(receiver).literal("l1", "b"); + ordered.verify(receiver).literal("l2", "c"); + ordered.verify(receiver).endEntity(); + ordered.verify(receiver).endRecord(); + ordered.verify(receiver).startRecord("2"); + ordered.verify(receiver).endRecord(); + ordered.verifyNoMoreInteractions(); + verifyNoMoreInteractions(receiver); + } + + @Test + public void shouldEmitEntityOnEachFlushEvent() { + metamorph = InlineMorph.in(this) + .with("") + .with(" ") + .with(" ") + .with(" ") + .with(" ") + .with(" ") + .with(" ") + .with("") + .createConnectedTo(receiver); + + metamorph.startRecord("1"); + metamorph.startEntity("E"); + metamorph.literal("d1", "a"); + metamorph.literal("d2", "b"); + metamorph.endEntity(); + metamorph.startEntity("E"); + metamorph.literal("d1", "c"); + metamorph.literal("d2", "d"); + metamorph.endEntity(); + metamorph.endRecord(); + + final InOrder ordered = inOrder(receiver); + ordered.verify(receiver).startRecord("1"); + ordered.verify(receiver).startEntity("entity"); + ordered.verify(receiver).literal("l1", "a"); + ordered.verify(receiver).literal("l2", "b"); + ordered.verify(receiver).endEntity(); + ordered.verify(receiver).startEntity("entity"); + ordered.verify(receiver).literal("l1", "c"); + ordered.verify(receiver).literal("l2", "d"); + ordered.verify(receiver).endEntity(); + ordered.verify(receiver).endRecord(); + ordered.verifyNoMoreInteractions(); + } + + @Test + public void shouldSupportNestedEntities() { + metamorph = InlineMorph.in(this) + .with("") + .with(" ") + .with(" ") + .with(" ") + .with(" ") + .with(" ") + .with(" ") + .with(" ") + .with(" ") + .with("") + .createConnectedTo(receiver); + + metamorph.startRecord("1"); + metamorph.literal("d1", "a"); + metamorph.literal("d2", "b"); + metamorph.literal("d3", "c"); + metamorph.endRecord(); + metamorph.startRecord("2"); + metamorph.literal("d1", "d"); + metamorph.literal("d2", "e"); + metamorph.literal("d3", "f"); + metamorph.endRecord(); + metamorph.startRecord("3"); + metamorph.literal("d1", "a"); + metamorph.literal("d3", "c"); + metamorph.endRecord(); + + final InOrder ordered = inOrder(receiver); + ordered.verify(receiver).startRecord("1"); + ordered.verify(receiver).startEntity("e1"); + ordered.verify(receiver).literal("d1", "a"); + ordered.verify(receiver).literal("d2", "b"); + ordered.verify(receiver).startEntity("e2"); + ordered.verify(receiver).literal("d3", "c"); + ordered.verify(receiver, times(2)).endEntity(); + ordered.verify(receiver).endRecord(); + ordered.verify(receiver).startRecord("2"); + ordered.verify(receiver).startEntity("e1"); + ordered.verify(receiver).literal("d1", "d"); + ordered.verify(receiver).literal("d2", "e"); + ordered.verify(receiver).startEntity("e2"); + ordered.verify(receiver).literal("d3", "f"); + ordered.verify(receiver, times(2)).endEntity(); + ordered.verify(receiver).endRecord(); + ordered.verify(receiver).startRecord("3"); + ordered.verify(receiver).startEntity("e1"); + ordered.verify(receiver).literal("d1", "a"); + ordered.verify(receiver).startEntity("e2"); + ordered.verify(receiver).literal("d3", "c"); + ordered.verify(receiver, times(2)).endEntity(); + ordered.verify(receiver).endRecord(); + ordered.verifyNoMoreInteractions(); + } + + @Test + public void shouldSupportMultipleNestedEntities() { + metamorph = InlineMorph.in(this) + .with("") + .with(" ") + .with(" ") + .with(" ") + .with(" ") + .with(" ") + .with(" ") + .with(" ") + .with(" ") + .with(" ") + .with(" ") + .with("") + .createConnectedTo(receiver); + + metamorph.startRecord("1x"); + metamorph.startEntity("E"); + metamorph.literal("d1", "a"); + metamorph.literal("d2", "b"); + metamorph.endEntity(); + metamorph.startEntity("E"); + metamorph.literal("d1", "x"); + metamorph.endEntity(); + metamorph.startEntity("E"); + metamorph.literal("d1", "c"); + metamorph.literal("d2", "d"); + metamorph.endEntity(); + metamorph.literal("d", "c"); + metamorph.endRecord(); + metamorph.startRecord("2x"); + metamorph.literal("d", "c"); + metamorph.endRecord(); + + final InOrder ordered = inOrder(receiver); + ordered.verify(receiver).startRecord("1x"); + ordered.verify(receiver).startEntity("uber"); + ordered.verify(receiver).startEntity("unter"); + ordered.verify(receiver).literal("l", "a"); + ordered.verify(receiver).literal("l", "b"); + ordered.verify(receiver).endEntity(); + ordered.verify(receiver).startEntity("unter"); + ordered.verify(receiver).literal("l", "c"); + ordered.verify(receiver).literal("l", "d"); + ordered.verify(receiver).endEntity(); + ordered.verify(receiver).literal("l", "c"); + ordered.verify(receiver).endEntity(); + ordered.verify(receiver).endRecord(); + ordered.verify(receiver).startRecord("2x"); + ordered.verify(receiver).startEntity("uber"); + ordered.verify(receiver).literal("l", "c"); + ordered.verify(receiver).endEntity(); + ordered.verify(receiver).endRecord(); + ordered.verifyNoMoreInteractions(); + } + + @Test + public void shouldSupportDeeplyNestedEnities() { + metamorph = InlineMorph.in(this) + .with("") + .with(" ") + .with(" ") + .with(" ") + .with(" ") + .with(" ") + .with(" ") + .with(" ") + .with(" ") + .with(" ") + .with(" ") + .with(" ") + .with("") + .createConnectedTo(receiver); + + metamorph.startRecord("1x"); + metamorph.literal("1", "a"); + metamorph.literal("2", "b"); + metamorph.literal("4", "c"); + metamorph.endRecord(); + + final InOrder ordered = inOrder(receiver); + ordered.verify(receiver).startRecord("1x"); + ordered.verify(receiver).startEntity("1"); + ordered.verify(receiver).literal("1", "a"); + ordered.verify(receiver).startEntity("2"); + ordered.verify(receiver).literal("2", "b"); + ordered.verify(receiver).startEntity("3"); + ordered.verify(receiver).startEntity("4"); + ordered.verify(receiver).literal("4", "c"); + ordered.verify(receiver, times(4)).endEntity(); + ordered.verify(receiver).endRecord(); + ordered.verifyNoMoreInteractions(); + } + + @Test + public void shouldGetNameFromDataInEntityName() { + metamorph = InlineMorph.in(this) + .with("") + .with(" ") + .with(" ") + .with(" ") + .with(" ") + .with(" ") + .with(" ") + .with(" ") + .with(" ") + .with(" ") + .with("") + .createConnectedTo(receiver); + + metamorph.startRecord("1x"); + metamorph.literal("data1", "a1"); + metamorph.literal("data1", "a2"); + metamorph.literal("data2", "b"); + metamorph.endRecord(); + metamorph.startRecord("2x"); + metamorph.literal("data2", "c"); + metamorph.literal("data1", "d"); + metamorph.endRecord(); + + final InOrder ordered = inOrder(receiver); + ordered.verify(receiver).startRecord("1x"); + ordered.verify(receiver).startEntity("entity:a2"); + ordered.verify(receiver).literal("l1", "a1"); + ordered.verify(receiver).literal("l1", "a2"); + ordered.verify(receiver).literal("l2", "b"); + ordered.verify(receiver).endEntity(); + ordered.verify(receiver).endRecord(); + ordered.verify(receiver).startRecord("2x"); + ordered.verify(receiver).startEntity("entity:d"); + ordered.verify(receiver).literal("l2", "c"); + ordered.verify(receiver).literal("l1", "d"); + ordered.verify(receiver).endEntity(); + ordered.verify(receiver).endRecord(); + ordered.verifyNoMoreInteractions(); + } + + @Test + public void shouldGetNameFromCollectInEntityName() { + metamorph = InlineMorph.in(this) + .with("") + .with(" ") + .with(" ") + .with(" ") + .with(" ") + .with(" ") + .with(" ") + .with(" ") + .with(" ") + .with(" ") + .with(" ") + .with("") + .createConnectedTo(receiver); + + metamorph.startRecord("1x"); + metamorph.literal("data1", "a1"); + metamorph.literal("data1", "a2"); + metamorph.literal("data2", "b"); + metamorph.endRecord(); + metamorph.startRecord("2x"); + metamorph.literal("data2", "c"); + metamorph.literal("data1", "d"); + metamorph.endRecord(); + + final InOrder ordered = inOrder(receiver); + ordered.verify(receiver).startRecord("1x"); + ordered.verify(receiver).startEntity("entity:a2,b"); + ordered.verify(receiver).literal("l1", "a1"); + ordered.verify(receiver).literal("l1", "a2"); + ordered.verify(receiver).literal("l2", "b"); + ordered.verify(receiver).endEntity(); + ordered.verify(receiver).endRecord(); + ordered.verify(receiver).startRecord("2x"); + ordered.verify(receiver).startEntity("entity:d,c"); + ordered.verify(receiver).literal("l2", "c"); + ordered.verify(receiver).literal("l1", "d"); + ordered.verify(receiver).endEntity(); + ordered.verify(receiver).endRecord(); + ordered.verifyNoMoreInteractions(); + } + + @Test + public void shouldResetNameToNameAttribute() { + metamorph = InlineMorph.in(this) + .with("") + .with(" ") + .with(" ") + .with(" ") + .with(" ") + .with(" ") + .with(" ") + .with("") + .createConnectedTo(receiver); + + metamorph.startRecord("1x"); + metamorph.literal("data1", "a"); + metamorph.literal("data3", "dynamicName"); + metamorph.endRecord(); + metamorph.startRecord("2x"); + metamorph.literal("data1", "b"); + metamorph.endRecord(); + + final InOrder ordered = inOrder(receiver); + ordered.verify(receiver).startRecord("1x"); + ordered.verify(receiver).startEntity("dynamicName"); + ordered.verify(receiver).literal("l1", "a"); + ordered.verify(receiver).endEntity(); + ordered.verify(receiver).endRecord(); + ordered.verify(receiver).startRecord("2x"); + ordered.verify(receiver).startEntity("defaultName"); + ordered.verify(receiver).literal("l1", "b"); + ordered.verify(receiver).endEntity(); + ordered.verify(receiver).endRecord(); + ordered.verifyNoMoreInteractions(); + } + + @Test + public void shouldEmitEmptyStringIfEntityNameIsNotSet() { + metamorph = InlineMorph.in(this) + .with("") + .with(" ") + .with(" ") + .with(" ") + .with("") + .createConnectedTo(receiver); + + metamorph.startRecord("1"); + metamorph.literal("in", "a"); + metamorph.endRecord(); + + final InOrder ordered = inOrder(receiver); + ordered.verify(receiver).startRecord("1"); + ordered.verify(receiver).startEntity(""); + ordered.verify(receiver).literal("out", "a"); + ordered.verify(receiver).endEntity(); + ordered.verify(receiver).endRecord(); + ordered.verifyNoMoreInteractions(); + } + + @Test + public void shouldEmitEntityContentsAgainIfResetIsFalse() { + metamorph = InlineMorph.in(this) + .with("") + .with(" ") + .with(" ") + .with(" ") + .with(" ") + .with("") + .createConnectedTo(receiver); + + metamorph.startRecord("1"); + metamorph.literal("lit1", "const"); + metamorph.literal("lit2", "1"); + metamorph.literal("lit2", "2"); + metamorph.endRecord(); + + final InOrder ordered = inOrder(receiver); + ordered.verify(receiver).startRecord("1"); + ordered.verify(receiver).startEntity("entity"); + ordered.verify(receiver).literal("lit1", "const"); + ordered.verify(receiver).literal("lit2", "1"); + ordered.verify(receiver).endEntity(); + ordered.verify(receiver).startEntity("entity"); + ordered.verify(receiver).literal("lit1", "const"); + ordered.verify(receiver).literal("lit2", "1"); + ordered.verify(receiver).literal("lit2", "2"); + ordered.verify(receiver).endEntity(); + ordered.verify(receiver).endRecord(); + ordered.verifyNoMoreInteractions(); + } + + @Test + public void shouldNotEmitEntityContentsAgainIfResetIsTrue() { + metamorph = InlineMorph.in(this) + .with("") + .with(" ") + .with(" ") + .with(" ") + .with(" ") + .with("") + .createConnectedTo(receiver); + + metamorph.startRecord("1"); + metamorph.literal("lit1", "const"); + metamorph.literal("lit2", "1"); + metamorph.literal("lit2", "2"); + metamorph.endRecord(); + + final InOrder ordered = inOrder(receiver); + ordered.verify(receiver).startRecord("1"); + ordered.verify(receiver).startEntity("entity"); + ordered.verify(receiver).literal("lit1", "const"); + ordered.verify(receiver).literal("lit2", "1"); + ordered.verify(receiver).endEntity(); + ordered.verify(receiver).endRecord(); + ordered.verifyNoMoreInteractions(); + } } diff --git a/metamorph/src/test/java/org/metafacture/metamorph/collectors/EqualsFilterTest.java b/metamorph/src/test/java/org/metafacture/metamorph/collectors/EqualsFilterTest.java index 998aada7e..5d366ffb1 100644 --- a/metamorph/src/test/java/org/metafacture/metamorph/collectors/EqualsFilterTest.java +++ b/metamorph/src/test/java/org/metafacture/metamorph/collectors/EqualsFilterTest.java @@ -40,280 +40,280 @@ */ public final class EqualsFilterTest { - @Rule - public final MockitoRule mockitoRule = MockitoJUnit.rule(); - - @Mock - private StreamReceiver receiver; - - private Metamorph metamorph; - - @Test - public void shouldEmitValueIfAllReceivedValuesAreEqual() { - metamorph = InlineMorph.in(this) - .with("") - .with(" ") - .with(" ") - .with(" ") - .with(" ") - .with(" ") - .with("") - .createConnectedTo(receiver); - - metamorph.startRecord("1"); - metamorph.literal("data1", "a"); - metamorph.literal("data2", "a"); - metamorph.literal("data3", "a"); - metamorph.endRecord(); - - final InOrder ordered = inOrder(receiver); - ordered.verify(receiver).startRecord("1"); - ordered.verify(receiver).literal("equalsFiltered", "a"); - ordered.verify(receiver).endRecord(); - ordered.verifyNoMoreInteractions(); - } - - @Test - public void shouldEmitNothingIfReceivedValuesDiffer() { - metamorph = InlineMorph.in(this) - .with("") - .with(" ") - .with(" ") - .with(" ") - .with(" ") - .with(" ") - .with("") - .createConnectedTo(receiver); - - metamorph.startRecord("1"); - metamorph.literal("data1", "a"); - metamorph.literal("data2", "a"); - metamorph.literal("data3", "b"); - metamorph.endRecord(); - - final InOrder ordered = inOrder(receiver); - ordered.verify(receiver).startRecord("1"); - ordered.verify(receiver, never()).literal(eq("equalsFiltered"), any()); - ordered.verify(receiver).endRecord(); - ordered.verifyNoMoreInteractions(); - } - - @Test - public void shouldFireIfOnlyASingleValueIsReceived() { - metamorph = InlineMorph.in(this) - .with("") - .with(" ") - .with(" ") - .with(" ") - .with("") - .createConnectedTo(receiver); - - metamorph.startRecord("1"); - metamorph.literal("data1", "a"); - metamorph.endRecord(); - - final InOrder ordered = inOrder(receiver); - ordered.verify(receiver).startRecord("1"); - ordered.verify(receiver).literal("equalsFiltered", "a"); - ordered.verify(receiver).endRecord(); - ordered.verifyNoMoreInteractions(); - } - - @Test - public void shouldIgnoreLiteralsNotListedInStatements() { - metamorph = InlineMorph.in(this) - .with("") - .with(" ") - .with(" ") - .with(" ") - .with(" ") - .with("") - .createConnectedTo(receiver); - - metamorph.startRecord("1"); - metamorph.literal("data1", "a"); - metamorph.literal("data2", "a"); - metamorph.literal("data3", "b"); - metamorph.endRecord(); - - final InOrder ordered = inOrder(receiver); - ordered.verify(receiver).startRecord("1"); - ordered.verify(receiver).literal("equalsFiltered", "a"); - ordered.verify(receiver).endRecord(); - ordered.verifyNoMoreInteractions(); - } - - @Test - public void shouldFireIfValuesInEntityAreEqual() { - metamorph = InlineMorph.in(this) - .with("") - .with(" ") - .with(" ") - .with(" ") - .with(" ") - .with(" ") - .with("") - .createConnectedTo(receiver); - - metamorph.startRecord("1"); - metamorph.startEntity("field"); - metamorph.literal("data1", "a"); - metamorph.literal("data2", "a"); - metamorph.literal("data3", "a"); - metamorph.endEntity(); - metamorph.endRecord(); - - final InOrder ordered = inOrder(receiver); - ordered.verify(receiver).startRecord("1"); - ordered.verify(receiver).literal("equalsFiltered", "a"); - ordered.verify(receiver).endRecord(); - ordered.verifyNoMoreInteractions(); - } - - @Test - public void shouldNotFireIfValuesInEntityAreNotEqual() { - metamorph = InlineMorph.in(this) - .with("") - .with(" ") - .with(" ") - .with(" ") - .with(" ") - .with(" ") - .with("") - .createConnectedTo(receiver); - - metamorph.startRecord("1"); - metamorph.startEntity("field"); - metamorph.literal("data1", "a"); - metamorph.literal("data2", "a"); - metamorph.literal("data3", "b"); - metamorph.endEntity(); - metamorph.endRecord(); - - final InOrder ordered = inOrder(receiver); - ordered.verify(receiver).startRecord("1"); - ordered.verify(receiver).endRecord(); - ordered.verifyNoMoreInteractions(); - } - - @Test - public void shouldFireIfLiteralsInEntitiesAreReceivedThatAreNotListedInStatements() { - metamorph = InlineMorph.in(this) - .with("") - .with(" ") - .with(" ") - .with(" ") - .with(" ") - .with("") - .createConnectedTo(receiver); - - metamorph.startRecord("1"); - metamorph.startEntity("field1"); - metamorph.literal("data1", "a"); - metamorph.endEntity(); - metamorph.endRecord(); - metamorph.startRecord("2"); - metamorph.startEntity("field1"); - metamorph.literal("data2", "a"); - metamorph.endEntity(); - metamorph.endRecord(); - metamorph.startRecord("3"); - metamorph.startEntity("field1"); - metamorph.literal("data1", "a"); - metamorph.literal("data2", "a"); - metamorph.endEntity(); - metamorph.endRecord(); - - final InOrder ordered = inOrder(receiver); - ordered.verify(receiver).startRecord("1"); - ordered.verify(receiver).endRecord(); - ordered.verify(receiver).startRecord("2"); - ordered.verify(receiver).endRecord(); - ordered.verify(receiver).startRecord("3"); - ordered.verify(receiver).literal("equalsFiltered", "a"); - ordered.verify(receiver).endRecord(); - ordered.verifyNoMoreInteractions(); - } - - @Test - public void shouldFireOnFlush() { - metamorph = InlineMorph.in(this) - .with("") - .with(" ") - .with(" ") - .with(" ") - .with(" ") - .with("") - .createConnectedTo(receiver); - - metamorph.startRecord("1"); - metamorph.startEntity("field1"); - metamorph.literal("data1", "a"); - metamorph.endEntity(); - metamorph.endRecord(); - metamorph.startRecord("2"); - metamorph.startEntity("field1"); - metamorph.literal("data2", "a"); - metamorph.endEntity(); - metamorph.endRecord(); - metamorph.startRecord("3"); - metamorph.startEntity("field1"); - metamorph.literal("data1", "a"); - metamorph.literal("data2", "a"); - metamorph.endEntity(); - metamorph.endRecord(); - - final InOrder ordered = inOrder(receiver); - ordered.verify(receiver).startRecord("1"); - ordered.verify(receiver).endRecord(); - ordered.verify(receiver).startRecord("2"); - ordered.verify(receiver).literal("equalsFiltered", ""); - ordered.verify(receiver).endRecord(); - ordered.verify(receiver).startRecord("3"); - ordered.verify(receiver).literal("equalsFiltered", "a"); - ordered.verify(receiver).endRecord(); - ordered.verifyNoMoreInteractions(); - verifyNoMoreInteractions(receiver); - } - - @Test - public void shouldNotFireOnFlushIfIncomplete() { - metamorph = InlineMorph.in(this) - .with("") - .with(" ") - .with(" ") - .with(" ") - .with(" ") - .with("") - .createConnectedTo(receiver); - - metamorph.startRecord("1"); - metamorph.startEntity("field1"); - metamorph.literal("data1", "a"); - metamorph.endEntity(); - metamorph.endRecord(); - metamorph.startRecord("2"); - metamorph.startEntity("field1"); - metamorph.literal("data2", "a"); - metamorph.endEntity(); - metamorph.endRecord(); - metamorph.startRecord("3"); - metamorph.startEntity("field1"); - metamorph.literal("data1", "a"); - metamorph.literal("data2", "a"); - metamorph.endEntity(); - metamorph.endRecord(); - - final InOrder ordered = inOrder(receiver); - ordered.verify(receiver).startRecord("1"); - ordered.verify(receiver).endRecord(); - ordered.verify(receiver).startRecord("2"); - ordered.verify(receiver).endRecord(); - ordered.verify(receiver).startRecord("3"); - ordered.verify(receiver).literal("equalsFiltered", "a"); - ordered.verify(receiver).endRecord(); - ordered.verifyNoMoreInteractions(); - verifyNoMoreInteractions(receiver); - } + @Rule + public final MockitoRule mockitoRule = MockitoJUnit.rule(); + + @Mock + private StreamReceiver receiver; + + private Metamorph metamorph; + + @Test + public void shouldEmitValueIfAllReceivedValuesAreEqual() { + metamorph = InlineMorph.in(this) + .with("") + .with(" ") + .with(" ") + .with(" ") + .with(" ") + .with(" ") + .with("") + .createConnectedTo(receiver); + + metamorph.startRecord("1"); + metamorph.literal("data1", "a"); + metamorph.literal("data2", "a"); + metamorph.literal("data3", "a"); + metamorph.endRecord(); + + final InOrder ordered = inOrder(receiver); + ordered.verify(receiver).startRecord("1"); + ordered.verify(receiver).literal("equalsFiltered", "a"); + ordered.verify(receiver).endRecord(); + ordered.verifyNoMoreInteractions(); + } + + @Test + public void shouldEmitNothingIfReceivedValuesDiffer() { + metamorph = InlineMorph.in(this) + .with("") + .with(" ") + .with(" ") + .with(" ") + .with(" ") + .with(" ") + .with("") + .createConnectedTo(receiver); + + metamorph.startRecord("1"); + metamorph.literal("data1", "a"); + metamorph.literal("data2", "a"); + metamorph.literal("data3", "b"); + metamorph.endRecord(); + + final InOrder ordered = inOrder(receiver); + ordered.verify(receiver).startRecord("1"); + ordered.verify(receiver, never()).literal(eq("equalsFiltered"), any()); + ordered.verify(receiver).endRecord(); + ordered.verifyNoMoreInteractions(); + } + + @Test + public void shouldFireIfOnlyASingleValueIsReceived() { + metamorph = InlineMorph.in(this) + .with("") + .with(" ") + .with(" ") + .with(" ") + .with("") + .createConnectedTo(receiver); + + metamorph.startRecord("1"); + metamorph.literal("data1", "a"); + metamorph.endRecord(); + + final InOrder ordered = inOrder(receiver); + ordered.verify(receiver).startRecord("1"); + ordered.verify(receiver).literal("equalsFiltered", "a"); + ordered.verify(receiver).endRecord(); + ordered.verifyNoMoreInteractions(); + } + + @Test + public void shouldIgnoreLiteralsNotListedInStatements() { + metamorph = InlineMorph.in(this) + .with("") + .with(" ") + .with(" ") + .with(" ") + .with(" ") + .with("") + .createConnectedTo(receiver); + + metamorph.startRecord("1"); + metamorph.literal("data1", "a"); + metamorph.literal("data2", "a"); + metamorph.literal("data3", "b"); + metamorph.endRecord(); + + final InOrder ordered = inOrder(receiver); + ordered.verify(receiver).startRecord("1"); + ordered.verify(receiver).literal("equalsFiltered", "a"); + ordered.verify(receiver).endRecord(); + ordered.verifyNoMoreInteractions(); + } + + @Test + public void shouldFireIfValuesInEntityAreEqual() { + metamorph = InlineMorph.in(this) + .with("") + .with(" ") + .with(" ") + .with(" ") + .with(" ") + .with(" ") + .with("") + .createConnectedTo(receiver); + + metamorph.startRecord("1"); + metamorph.startEntity("field"); + metamorph.literal("data1", "a"); + metamorph.literal("data2", "a"); + metamorph.literal("data3", "a"); + metamorph.endEntity(); + metamorph.endRecord(); + + final InOrder ordered = inOrder(receiver); + ordered.verify(receiver).startRecord("1"); + ordered.verify(receiver).literal("equalsFiltered", "a"); + ordered.verify(receiver).endRecord(); + ordered.verifyNoMoreInteractions(); + } + + @Test + public void shouldNotFireIfValuesInEntityAreNotEqual() { + metamorph = InlineMorph.in(this) + .with("") + .with(" ") + .with(" ") + .with(" ") + .with(" ") + .with(" ") + .with("") + .createConnectedTo(receiver); + + metamorph.startRecord("1"); + metamorph.startEntity("field"); + metamorph.literal("data1", "a"); + metamorph.literal("data2", "a"); + metamorph.literal("data3", "b"); + metamorph.endEntity(); + metamorph.endRecord(); + + final InOrder ordered = inOrder(receiver); + ordered.verify(receiver).startRecord("1"); + ordered.verify(receiver).endRecord(); + ordered.verifyNoMoreInteractions(); + } + + @Test + public void shouldFireIfLiteralsInEntitiesAreReceivedThatAreNotListedInStatements() { + metamorph = InlineMorph.in(this) + .with("") + .with(" ") + .with(" ") + .with(" ") + .with(" ") + .with("") + .createConnectedTo(receiver); + + metamorph.startRecord("1"); + metamorph.startEntity("field1"); + metamorph.literal("data1", "a"); + metamorph.endEntity(); + metamorph.endRecord(); + metamorph.startRecord("2"); + metamorph.startEntity("field1"); + metamorph.literal("data2", "a"); + metamorph.endEntity(); + metamorph.endRecord(); + metamorph.startRecord("3"); + metamorph.startEntity("field1"); + metamorph.literal("data1", "a"); + metamorph.literal("data2", "a"); + metamorph.endEntity(); + metamorph.endRecord(); + + final InOrder ordered = inOrder(receiver); + ordered.verify(receiver).startRecord("1"); + ordered.verify(receiver).endRecord(); + ordered.verify(receiver).startRecord("2"); + ordered.verify(receiver).endRecord(); + ordered.verify(receiver).startRecord("3"); + ordered.verify(receiver).literal("equalsFiltered", "a"); + ordered.verify(receiver).endRecord(); + ordered.verifyNoMoreInteractions(); + } + + @Test + public void shouldFireOnFlush() { + metamorph = InlineMorph.in(this) + .with("") + .with(" ") + .with(" ") + .with(" ") + .with(" ") + .with("") + .createConnectedTo(receiver); + + metamorph.startRecord("1"); + metamorph.startEntity("field1"); + metamorph.literal("data1", "a"); + metamorph.endEntity(); + metamorph.endRecord(); + metamorph.startRecord("2"); + metamorph.startEntity("field1"); + metamorph.literal("data2", "a"); + metamorph.endEntity(); + metamorph.endRecord(); + metamorph.startRecord("3"); + metamorph.startEntity("field1"); + metamorph.literal("data1", "a"); + metamorph.literal("data2", "a"); + metamorph.endEntity(); + metamorph.endRecord(); + + final InOrder ordered = inOrder(receiver); + ordered.verify(receiver).startRecord("1"); + ordered.verify(receiver).endRecord(); + ordered.verify(receiver).startRecord("2"); + ordered.verify(receiver).literal("equalsFiltered", ""); + ordered.verify(receiver).endRecord(); + ordered.verify(receiver).startRecord("3"); + ordered.verify(receiver).literal("equalsFiltered", "a"); + ordered.verify(receiver).endRecord(); + ordered.verifyNoMoreInteractions(); + verifyNoMoreInteractions(receiver); + } + + @Test + public void shouldNotFireOnFlushIfIncomplete() { + metamorph = InlineMorph.in(this) + .with("") + .with(" ") + .with(" ") + .with(" ") + .with(" ") + .with("") + .createConnectedTo(receiver); + + metamorph.startRecord("1"); + metamorph.startEntity("field1"); + metamorph.literal("data1", "a"); + metamorph.endEntity(); + metamorph.endRecord(); + metamorph.startRecord("2"); + metamorph.startEntity("field1"); + metamorph.literal("data2", "a"); + metamorph.endEntity(); + metamorph.endRecord(); + metamorph.startRecord("3"); + metamorph.startEntity("field1"); + metamorph.literal("data1", "a"); + metamorph.literal("data2", "a"); + metamorph.endEntity(); + metamorph.endRecord(); + + final InOrder ordered = inOrder(receiver); + ordered.verify(receiver).startRecord("1"); + ordered.verify(receiver).endRecord(); + ordered.verify(receiver).startRecord("2"); + ordered.verify(receiver).endRecord(); + ordered.verify(receiver).startRecord("3"); + ordered.verify(receiver).literal("equalsFiltered", "a"); + ordered.verify(receiver).endRecord(); + ordered.verifyNoMoreInteractions(); + verifyNoMoreInteractions(receiver); + } } diff --git a/metamorph/src/test/java/org/metafacture/metamorph/collectors/GroupTest.java b/metamorph/src/test/java/org/metafacture/metamorph/collectors/GroupTest.java index c983b258b..15034673a 100644 --- a/metamorph/src/test/java/org/metafacture/metamorph/collectors/GroupTest.java +++ b/metamorph/src/test/java/org/metafacture/metamorph/collectors/GroupTest.java @@ -37,38 +37,38 @@ */ public final class GroupTest { - @Rule - public final MockitoRule mockitoRule = MockitoJUnit.rule(); + @Rule + public final MockitoRule mockitoRule = MockitoJUnit.rule(); - @Mock - private StreamReceiver receiver; + @Mock + private StreamReceiver receiver; - private Metamorph metamorph; + private Metamorph metamorph; - @Test - public void shouldGroupToOverwriteNameAndValueOfContaintStatements() { - metamorph = InlineMorph.in(this) - .with("") - .with(" ") - .with(" ") - .with(" ") - .with(" ") - .with(" ") - .with("") - .createConnectedTo(receiver); + @Test + public void shouldGroupToOverwriteNameAndValueOfContaintStatements() { + metamorph = InlineMorph.in(this) + .with("") + .with(" ") + .with(" ") + .with(" ") + .with(" ") + .with(" ") + .with("") + .createConnectedTo(receiver); - metamorph.startRecord("1"); - metamorph.literal("data1", "skjdfh"); - metamorph.literal("data2", "slkdjf"); - metamorph.literal("data3", "A"); - metamorph.endRecord(); + metamorph.startRecord("1"); + metamorph.literal("data1", "skjdfh"); + metamorph.literal("data2", "slkdjf"); + metamorph.literal("data3", "A"); + metamorph.endRecord(); - final InOrder ordered = inOrder(receiver); - ordered.verify(receiver).startRecord("1"); - ordered.verify(receiver, times(2)).literal("group", "constant"); - ordered.verify(receiver).literal("data3", "A"); - ordered.verify(receiver).endRecord(); - ordered.verifyNoMoreInteractions(); - } + final InOrder ordered = inOrder(receiver); + ordered.verify(receiver).startRecord("1"); + ordered.verify(receiver, times(2)).literal("group", "constant"); + ordered.verify(receiver).literal("data3", "A"); + ordered.verify(receiver).endRecord(); + ordered.verifyNoMoreInteractions(); + } } diff --git a/metamorph/src/test/java/org/metafacture/metamorph/collectors/NoneTest.java b/metamorph/src/test/java/org/metafacture/metamorph/collectors/NoneTest.java index 4953222be..acac24740 100644 --- a/metamorph/src/test/java/org/metafacture/metamorph/collectors/NoneTest.java +++ b/metamorph/src/test/java/org/metafacture/metamorph/collectors/NoneTest.java @@ -36,144 +36,144 @@ */ public final class NoneTest { - @Rule - public final MockitoRule mockitoRule = MockitoJUnit.rule(); - - @Mock - private StreamReceiver receiver; - - private Metamorph metamorph; - - @Test - public void shouldFireOnlyifNoElementFired() { - metamorph = InlineMorph.in(this) - .with("") - .with(" ") - .with(" ") - .with(" ") - .with(" ") - .with("") - .createConnectedTo(receiver); - - metamorph.startRecord("1"); - metamorph.literal("data1", "A"); - metamorph.endRecord(); - metamorph.startRecord("2"); - metamorph.literal("data2", "C"); - metamorph.endRecord(); - metamorph.startRecord("3"); - metamorph.literal("data3", "C"); - metamorph.endRecord(); - - final InOrder ordered = inOrder(receiver); - ordered.verify(receiver).startRecord("1"); - ordered.verify(receiver).endRecord(); - ordered.verify(receiver).startRecord("2"); - ordered.verify(receiver).endRecord(); - ordered.verify(receiver).startRecord("3"); - ordered.verify(receiver).literal("", "true"); - ordered.verify(receiver).endRecord(); - ordered.verifyNoMoreInteractions(); - } - - @Test - public void shouldSupportUserdefinedNameAndValue() { - metamorph = InlineMorph.in(this) - .with("") - .with(" ") - .with(" ") - .with(" ") - .with(" ") - .with("") - .createConnectedTo(receiver); - - metamorph.startRecord("1"); - metamorph.literal("data3", "A"); - metamorph.endRecord(); - - final InOrder ordered = inOrder(receiver); - ordered.verify(receiver).startRecord("1"); - ordered.verify(receiver).literal("NONE", "found none"); - ordered.verify(receiver).endRecord(); - ordered.verifyNoMoreInteractions(); - } - - @Test - public void shouldNotFireAgainIfFlushedTwoTimesAndResetIsFalse() { - metamorph = InlineMorph.in(this) - .with("") - .with(" ") - .with(" ") - .with(" ") - .with("") - .createConnectedTo(receiver); - - metamorph.startRecord("1"); - metamorph.startEntity("entity"); - metamorph.literal("data1", "A"); - metamorph.endEntity(); - metamorph.startEntity("entity"); - metamorph.literal("data1", "A"); - metamorph.endEntity(); - metamorph.endRecord(); - - final InOrder ordered = inOrder(receiver); - ordered.verify(receiver).startRecord("1"); - ordered.verify(receiver).literal("", "true"); - ordered.verify(receiver).endRecord(); - ordered.verifyNoMoreInteractions(); - } - - @Test - public void shouldFireAgainIfFlushedTwoTimesAndTesetIsTrue() { - metamorph = InlineMorph.in(this) - .with("") - .with(" ") - .with(" ") - .with(" ") - .with("") - .createConnectedTo(receiver); - - metamorph.startRecord("1"); - metamorph.startEntity("entity"); - metamorph.literal("data1", "A"); - metamorph.endEntity(); - metamorph.startEntity("entity"); - metamorph.literal("data1", "A"); - metamorph.endEntity(); - metamorph.endRecord(); - - final InOrder ordered = inOrder(receiver); - ordered.verify(receiver).startRecord("1"); - ordered.verify(receiver, times(2)).literal("", "true"); - ordered.verify(receiver).endRecord(); - ordered.verifyNoMoreInteractions(); - } - - @Test - public void shouldResetWhenEntityChangesIfSameEntity() { - metamorph = InlineMorph.in(this) - .with("") - .with(" ") - .with(" ") - .with(" ") - .with("") - .createConnectedTo(receiver); - - metamorph.startRecord("1"); - metamorph.startEntity("entity"); - metamorph.literal("data2", "A"); - metamorph.endEntity(); - metamorph.startEntity("entity"); - metamorph.literal("data1", "A"); - metamorph.endEntity(); - metamorph.endRecord(); - - final InOrder ordered = inOrder(receiver); - ordered.verify(receiver).startRecord("1"); - ordered.verify(receiver).literal("", "true"); - ordered.verify(receiver).endRecord(); - ordered.verifyNoMoreInteractions(); - } + @Rule + public final MockitoRule mockitoRule = MockitoJUnit.rule(); + + @Mock + private StreamReceiver receiver; + + private Metamorph metamorph; + + @Test + public void shouldFireOnlyifNoElementFired() { + metamorph = InlineMorph.in(this) + .with("") + .with(" ") + .with(" ") + .with(" ") + .with(" ") + .with("") + .createConnectedTo(receiver); + + metamorph.startRecord("1"); + metamorph.literal("data1", "A"); + metamorph.endRecord(); + metamorph.startRecord("2"); + metamorph.literal("data2", "C"); + metamorph.endRecord(); + metamorph.startRecord("3"); + metamorph.literal("data3", "C"); + metamorph.endRecord(); + + final InOrder ordered = inOrder(receiver); + ordered.verify(receiver).startRecord("1"); + ordered.verify(receiver).endRecord(); + ordered.verify(receiver).startRecord("2"); + ordered.verify(receiver).endRecord(); + ordered.verify(receiver).startRecord("3"); + ordered.verify(receiver).literal("", "true"); + ordered.verify(receiver).endRecord(); + ordered.verifyNoMoreInteractions(); + } + + @Test + public void shouldSupportUserdefinedNameAndValue() { + metamorph = InlineMorph.in(this) + .with("") + .with(" ") + .with(" ") + .with(" ") + .with(" ") + .with("") + .createConnectedTo(receiver); + + metamorph.startRecord("1"); + metamorph.literal("data3", "A"); + metamorph.endRecord(); + + final InOrder ordered = inOrder(receiver); + ordered.verify(receiver).startRecord("1"); + ordered.verify(receiver).literal("NONE", "found none"); + ordered.verify(receiver).endRecord(); + ordered.verifyNoMoreInteractions(); + } + + @Test + public void shouldNotFireAgainIfFlushedTwoTimesAndResetIsFalse() { + metamorph = InlineMorph.in(this) + .with("") + .with(" ") + .with(" ") + .with(" ") + .with("") + .createConnectedTo(receiver); + + metamorph.startRecord("1"); + metamorph.startEntity("entity"); + metamorph.literal("data1", "A"); + metamorph.endEntity(); + metamorph.startEntity("entity"); + metamorph.literal("data1", "A"); + metamorph.endEntity(); + metamorph.endRecord(); + + final InOrder ordered = inOrder(receiver); + ordered.verify(receiver).startRecord("1"); + ordered.verify(receiver).literal("", "true"); + ordered.verify(receiver).endRecord(); + ordered.verifyNoMoreInteractions(); + } + + @Test + public void shouldFireAgainIfFlushedTwoTimesAndTesetIsTrue() { + metamorph = InlineMorph.in(this) + .with("") + .with(" ") + .with(" ") + .with(" ") + .with("") + .createConnectedTo(receiver); + + metamorph.startRecord("1"); + metamorph.startEntity("entity"); + metamorph.literal("data1", "A"); + metamorph.endEntity(); + metamorph.startEntity("entity"); + metamorph.literal("data1", "A"); + metamorph.endEntity(); + metamorph.endRecord(); + + final InOrder ordered = inOrder(receiver); + ordered.verify(receiver).startRecord("1"); + ordered.verify(receiver, times(2)).literal("", "true"); + ordered.verify(receiver).endRecord(); + ordered.verifyNoMoreInteractions(); + } + + @Test + public void shouldResetWhenEntityChangesIfSameEntity() { + metamorph = InlineMorph.in(this) + .with("") + .with(" ") + .with(" ") + .with(" ") + .with("") + .createConnectedTo(receiver); + + metamorph.startRecord("1"); + metamorph.startEntity("entity"); + metamorph.literal("data2", "A"); + metamorph.endEntity(); + metamorph.startEntity("entity"); + metamorph.literal("data1", "A"); + metamorph.endEntity(); + metamorph.endRecord(); + + final InOrder ordered = inOrder(receiver); + ordered.verify(receiver).startRecord("1"); + ordered.verify(receiver).literal("", "true"); + ordered.verify(receiver).endRecord(); + ordered.verifyNoMoreInteractions(); + } } diff --git a/metamorph/src/test/java/org/metafacture/metamorph/collectors/RangeTest.java b/metamorph/src/test/java/org/metafacture/metamorph/collectors/RangeTest.java index 8294d12b9..b17381ca8 100644 --- a/metamorph/src/test/java/org/metafacture/metamorph/collectors/RangeTest.java +++ b/metamorph/src/test/java/org/metafacture/metamorph/collectors/RangeTest.java @@ -35,177 +35,177 @@ */ public final class RangeTest { - @Rule - public final MockitoRule mockitoRule = MockitoJUnit.rule(); - - @Mock - private StreamReceiver receiver; - - private Metamorph metamorph; - - @Test - public void shouldOutputAllnNmbersbBetweenFirstAndLastInclusive() { - metamorph = InlineMorph.in(this) - .with("") - .with(" ") - .with(" ") - .with(" ") - .with(" ") - .with("") - .createConnectedTo(receiver); - - metamorph.startRecord("1"); - metamorph.literal("first", "1789"); - metamorph.literal("last", "1794"); - metamorph.endRecord(); - - final InOrder ordered = inOrder(receiver); - ordered.verify(receiver).startRecord("1"); - ordered.verify(receiver).literal("range", "1789"); - ordered.verify(receiver).literal("range", "1790"); - ordered.verify(receiver).literal("range", "1791"); - ordered.verify(receiver).literal("range", "1792"); - ordered.verify(receiver).literal("range", "1793"); - ordered.verify(receiver).literal("range", "1794"); - ordered.verify(receiver).endRecord(); - ordered.verifyNoMoreInteractions(); - } - - @Test - public void shouldOutputFirstIfLastEqualsFirst() { - metamorph = InlineMorph.in(this) - .with("") - .with(" ") - .with(" ") - .with(" ") - .with(" ") - .with("") - .createConnectedTo(receiver); - - metamorph.startRecord("1"); - metamorph.literal("first", "1989"); - metamorph.literal("last", "1989"); - metamorph.endRecord(); - - final InOrder ordered = inOrder(receiver); - ordered.verify(receiver).startRecord("1"); - ordered.verify(receiver).literal("range", "1989"); - ordered.verify(receiver).endRecord(); - ordered.verifyNoMoreInteractions(); - } - - @Test - public void shouldOutputMultipleRanges() { - metamorph = InlineMorph.in(this) - .with("") - .with(" ") - .with(" ") - .with(" ") - .with(" ") - .with("") - .createConnectedTo(receiver); - - metamorph.startRecord("1"); - metamorph.literal("first", "1789"); - metamorph.literal("last", "1792"); - metamorph.literal("first", "1794"); - metamorph.literal("last", "1799"); - metamorph.endRecord(); - - final InOrder ordered = inOrder(receiver); - ordered.verify(receiver).startRecord("1"); - ordered.verify(receiver).literal("range", "1789"); - ordered.verify(receiver).literal("range", "1790"); - ordered.verify(receiver).literal("range", "1791"); - ordered.verify(receiver).literal("range", "1792"); - ordered.verify(receiver).literal("range", "1794"); - ordered.verify(receiver).literal("range", "1795"); - ordered.verify(receiver).literal("range", "1796"); - ordered.verify(receiver).literal("range", "1797"); - ordered.verify(receiver).literal("range", "1798"); - ordered.verify(receiver).literal("range", "1799"); - ordered.verify(receiver).endRecord(); - ordered.verifyNoMoreInteractions(); - } - - @Test - public void shouldRemoveDuplicateNumbersFromOverlappingRanges() { - metamorph = InlineMorph.in(this) - .with("") - .with(" ") - .with(" ") - .with(" ") - .with(" ") - .with("") - .createConnectedTo(receiver); - - metamorph.startRecord("1"); - metamorph.literal("first", "1789"); - metamorph.literal("last", "1792"); - metamorph.literal("first", "1790"); - metamorph.literal("last", "1791"); - metamorph.endRecord(); - - final InOrder ordered = inOrder(receiver); - ordered.verify(receiver).startRecord("1"); - ordered.verify(receiver).literal("range", "1789"); - ordered.verify(receiver).literal("range", "1790"); - ordered.verify(receiver).literal("range", "1791"); - ordered.verify(receiver).literal("range", "1792"); - ordered.verify(receiver).endRecord(); - ordered.verifyNoMoreInteractions(); - } - - @Test - public void shouldUseUserdefinedIncrement() { - metamorph = InlineMorph.in(this) - .with("") - .with(" ") - .with(" ") - .with(" ") - .with(" ") - .with("") - .createConnectedTo(receiver); - - metamorph.startRecord("1"); - metamorph.literal("first", "1789"); - metamorph.literal("last", "1799"); - metamorph.endRecord(); - - final InOrder ordered = inOrder(receiver); - ordered.verify(receiver).startRecord("1"); - ordered.verify(receiver).literal("range", "1789"); - ordered.verify(receiver).literal("range", "1792"); - ordered.verify(receiver).literal("range", "1795"); - ordered.verify(receiver).literal("range", "1798"); - ordered.verify(receiver).endRecord(); - ordered.verifyNoMoreInteractions(); - } - - @Test - public void shouldAllowNegativeIncrements() { - metamorph = InlineMorph.in(this) - .with("") - .with(" ") - .with(" ") - .with(" ") - .with(" ") - .with("") - .createConnectedTo(receiver); - - metamorph.startRecord("1"); - metamorph.literal("first", "1799"); - metamorph.literal("last", "1789"); - metamorph.endRecord(); - - final InOrder ordered = inOrder(receiver); - ordered.verify(receiver).startRecord("1"); - ordered.verify(receiver).literal("range", "1799"); - ordered.verify(receiver).literal("range", "1796"); - ordered.verify(receiver).literal("range", "1793"); - ordered.verify(receiver).literal("range", "1790"); - ordered.verify(receiver).endRecord(); - ordered.verifyNoMoreInteractions(); - } + @Rule + public final MockitoRule mockitoRule = MockitoJUnit.rule(); + + @Mock + private StreamReceiver receiver; + + private Metamorph metamorph; + + @Test + public void shouldOutputAllnNmbersbBetweenFirstAndLastInclusive() { + metamorph = InlineMorph.in(this) + .with("") + .with(" ") + .with(" ") + .with(" ") + .with(" ") + .with("") + .createConnectedTo(receiver); + + metamorph.startRecord("1"); + metamorph.literal("first", "1789"); + metamorph.literal("last", "1794"); + metamorph.endRecord(); + + final InOrder ordered = inOrder(receiver); + ordered.verify(receiver).startRecord("1"); + ordered.verify(receiver).literal("range", "1789"); + ordered.verify(receiver).literal("range", "1790"); + ordered.verify(receiver).literal("range", "1791"); + ordered.verify(receiver).literal("range", "1792"); + ordered.verify(receiver).literal("range", "1793"); + ordered.verify(receiver).literal("range", "1794"); + ordered.verify(receiver).endRecord(); + ordered.verifyNoMoreInteractions(); + } + + @Test + public void shouldOutputFirstIfLastEqualsFirst() { + metamorph = InlineMorph.in(this) + .with("") + .with(" ") + .with(" ") + .with(" ") + .with(" ") + .with("") + .createConnectedTo(receiver); + + metamorph.startRecord("1"); + metamorph.literal("first", "1989"); + metamorph.literal("last", "1989"); + metamorph.endRecord(); + + final InOrder ordered = inOrder(receiver); + ordered.verify(receiver).startRecord("1"); + ordered.verify(receiver).literal("range", "1989"); + ordered.verify(receiver).endRecord(); + ordered.verifyNoMoreInteractions(); + } + + @Test + public void shouldOutputMultipleRanges() { + metamorph = InlineMorph.in(this) + .with("") + .with(" ") + .with(" ") + .with(" ") + .with(" ") + .with("") + .createConnectedTo(receiver); + + metamorph.startRecord("1"); + metamorph.literal("first", "1789"); + metamorph.literal("last", "1792"); + metamorph.literal("first", "1794"); + metamorph.literal("last", "1799"); + metamorph.endRecord(); + + final InOrder ordered = inOrder(receiver); + ordered.verify(receiver).startRecord("1"); + ordered.verify(receiver).literal("range", "1789"); + ordered.verify(receiver).literal("range", "1790"); + ordered.verify(receiver).literal("range", "1791"); + ordered.verify(receiver).literal("range", "1792"); + ordered.verify(receiver).literal("range", "1794"); + ordered.verify(receiver).literal("range", "1795"); + ordered.verify(receiver).literal("range", "1796"); + ordered.verify(receiver).literal("range", "1797"); + ordered.verify(receiver).literal("range", "1798"); + ordered.verify(receiver).literal("range", "1799"); + ordered.verify(receiver).endRecord(); + ordered.verifyNoMoreInteractions(); + } + + @Test + public void shouldRemoveDuplicateNumbersFromOverlappingRanges() { + metamorph = InlineMorph.in(this) + .with("") + .with(" ") + .with(" ") + .with(" ") + .with(" ") + .with("") + .createConnectedTo(receiver); + + metamorph.startRecord("1"); + metamorph.literal("first", "1789"); + metamorph.literal("last", "1792"); + metamorph.literal("first", "1790"); + metamorph.literal("last", "1791"); + metamorph.endRecord(); + + final InOrder ordered = inOrder(receiver); + ordered.verify(receiver).startRecord("1"); + ordered.verify(receiver).literal("range", "1789"); + ordered.verify(receiver).literal("range", "1790"); + ordered.verify(receiver).literal("range", "1791"); + ordered.verify(receiver).literal("range", "1792"); + ordered.verify(receiver).endRecord(); + ordered.verifyNoMoreInteractions(); + } + + @Test + public void shouldUseUserdefinedIncrement() { + metamorph = InlineMorph.in(this) + .with("") + .with(" ") + .with(" ") + .with(" ") + .with(" ") + .with("") + .createConnectedTo(receiver); + + metamorph.startRecord("1"); + metamorph.literal("first", "1789"); + metamorph.literal("last", "1799"); + metamorph.endRecord(); + + final InOrder ordered = inOrder(receiver); + ordered.verify(receiver).startRecord("1"); + ordered.verify(receiver).literal("range", "1789"); + ordered.verify(receiver).literal("range", "1792"); + ordered.verify(receiver).literal("range", "1795"); + ordered.verify(receiver).literal("range", "1798"); + ordered.verify(receiver).endRecord(); + ordered.verifyNoMoreInteractions(); + } + + @Test + public void shouldAllowNegativeIncrements() { + metamorph = InlineMorph.in(this) + .with("") + .with(" ") + .with(" ") + .with(" ") + .with(" ") + .with("") + .createConnectedTo(receiver); + + metamorph.startRecord("1"); + metamorph.literal("first", "1799"); + metamorph.literal("last", "1789"); + metamorph.endRecord(); + + final InOrder ordered = inOrder(receiver); + ordered.verify(receiver).startRecord("1"); + ordered.verify(receiver).literal("range", "1799"); + ordered.verify(receiver).literal("range", "1796"); + ordered.verify(receiver).literal("range", "1793"); + ordered.verify(receiver).literal("range", "1790"); + ordered.verify(receiver).endRecord(); + ordered.verifyNoMoreInteractions(); + } } diff --git a/metamorph/src/test/java/org/metafacture/metamorph/collectors/SquareTest.java b/metamorph/src/test/java/org/metafacture/metamorph/collectors/SquareTest.java index e5c022335..de72ad29c 100644 --- a/metamorph/src/test/java/org/metafacture/metamorph/collectors/SquareTest.java +++ b/metamorph/src/test/java/org/metafacture/metamorph/collectors/SquareTest.java @@ -36,102 +36,102 @@ */ public final class SquareTest { - @Rule - public final MockitoRule mockitoRule = MockitoJUnit.rule(); + @Rule + public final MockitoRule mockitoRule = MockitoJUnit.rule(); - @Mock - private StreamReceiver receiver; + @Mock + private StreamReceiver receiver; - private Metamorph metamorph; + private Metamorph metamorph; - @Test - public void shouldEmitSquaresOfInputValues() { - metamorph = InlineMorph.in(this) - .with("") - .with(" ") - .with(" ") - .with(" ") - .with(" ") - .with("") - .createConnectedTo(receiver); + @Test + public void shouldEmitSquaresOfInputValues() { + metamorph = InlineMorph.in(this) + .with("") + .with(" ") + .with(" ") + .with(" ") + .with(" ") + .with("") + .createConnectedTo(receiver); - metamorph.startRecord("1"); - metamorph.literal("data1", "b"); - metamorph.literal("data1", "a"); - metamorph.literal("data2", "c"); - metamorph.endRecord(); - metamorph.startRecord("2"); - metamorph.literal("data1", "1"); - metamorph.literal("data1", "2"); - metamorph.literal("data2", "3"); - metamorph.literal("data2", "4"); - metamorph.literal("data2", "5"); - metamorph.literal("data2", "6"); - metamorph.literal("data2", "7"); - metamorph.endRecord(); + metamorph.startRecord("1"); + metamorph.literal("data1", "b"); + metamorph.literal("data1", "a"); + metamorph.literal("data2", "c"); + metamorph.endRecord(); + metamorph.startRecord("2"); + metamorph.literal("data1", "1"); + metamorph.literal("data1", "2"); + metamorph.literal("data2", "3"); + metamorph.literal("data2", "4"); + metamorph.literal("data2", "5"); + metamorph.literal("data2", "6"); + metamorph.literal("data2", "7"); + metamorph.endRecord(); - final InOrder ordered = inOrder(receiver); - ordered.verify(receiver).startRecord("1"); - ordered.verify(receiver).literal("square", "{a,c}"); - ordered.verify(receiver).literal("square", "{b,c}"); - ordered.verify(receiver).literal("square", "{a,b}"); - ordered.verify(receiver).endRecord(); - ordered.verify(receiver).startRecord("2"); - ordered.verify(receiver).literal("square", "{1,7}"); - ordered.verify(receiver).literal("square", "{2,7}"); - ordered.verify(receiver).literal("square", "{3,7}"); - ordered.verify(receiver).literal("square", "{4,7}"); - ordered.verify(receiver).literal("square", "{5,7}"); - ordered.verify(receiver).literal("square", "{6,7}"); - ordered.verify(receiver).literal("square", "{1,6}"); - ordered.verify(receiver).literal("square", "{2,6}"); - ordered.verify(receiver).literal("square", "{3,6}"); - ordered.verify(receiver).literal("square", "{4,6}"); - ordered.verify(receiver).literal("square", "{5,6}"); - ordered.verify(receiver).literal("square", "{1,5}"); - ordered.verify(receiver).literal("square", "{2,5}"); - ordered.verify(receiver).literal("square", "{3,5}"); - ordered.verify(receiver).literal("square", "{4,5}"); - ordered.verify(receiver).literal("square", "{1,4}"); - ordered.verify(receiver).literal("square", "{2,4}"); - ordered.verify(receiver).literal("square", "{3,4}"); - ordered.verify(receiver).literal("square", "{1,3}"); - ordered.verify(receiver).literal("square", "{2,3}"); - ordered.verify(receiver).literal("square", "{1,2}"); - ordered.verify(receiver).endRecord(); - ordered.verifyNoMoreInteractions(); - } + final InOrder ordered = inOrder(receiver); + ordered.verify(receiver).startRecord("1"); + ordered.verify(receiver).literal("square", "{a,c}"); + ordered.verify(receiver).literal("square", "{b,c}"); + ordered.verify(receiver).literal("square", "{a,b}"); + ordered.verify(receiver).endRecord(); + ordered.verify(receiver).startRecord("2"); + ordered.verify(receiver).literal("square", "{1,7}"); + ordered.verify(receiver).literal("square", "{2,7}"); + ordered.verify(receiver).literal("square", "{3,7}"); + ordered.verify(receiver).literal("square", "{4,7}"); + ordered.verify(receiver).literal("square", "{5,7}"); + ordered.verify(receiver).literal("square", "{6,7}"); + ordered.verify(receiver).literal("square", "{1,6}"); + ordered.verify(receiver).literal("square", "{2,6}"); + ordered.verify(receiver).literal("square", "{3,6}"); + ordered.verify(receiver).literal("square", "{4,6}"); + ordered.verify(receiver).literal("square", "{5,6}"); + ordered.verify(receiver).literal("square", "{1,5}"); + ordered.verify(receiver).literal("square", "{2,5}"); + ordered.verify(receiver).literal("square", "{3,5}"); + ordered.verify(receiver).literal("square", "{4,5}"); + ordered.verify(receiver).literal("square", "{1,4}"); + ordered.verify(receiver).literal("square", "{2,4}"); + ordered.verify(receiver).literal("square", "{3,4}"); + ordered.verify(receiver).literal("square", "{1,3}"); + ordered.verify(receiver).literal("square", "{2,3}"); + ordered.verify(receiver).literal("square", "{1,2}"); + ordered.verify(receiver).endRecord(); + ordered.verifyNoMoreInteractions(); + } - @Test - public void shouldEmitSquaresOnFlushEvent() { - metamorph = InlineMorph.in(this) - .with("") - .with(" ") - .with(" ") - .with(" ") - .with("") - .createConnectedTo(receiver); + @Test + public void shouldEmitSquaresOnFlushEvent() { + metamorph = InlineMorph.in(this) + .with("") + .with(" ") + .with(" ") + .with(" ") + .with("") + .createConnectedTo(receiver); - metamorph.startRecord("1"); - metamorph.startEntity("d"); - metamorph.literal("1", "a"); - metamorph.literal("1", "b"); - metamorph.endEntity(); - metamorph.startEntity("d"); - metamorph.literal("1", "e"); - metamorph.literal("1", "f"); - metamorph.endEntity(); - metamorph.startEntity("d"); - metamorph.literal("2", "e"); - metamorph.endEntity(); - metamorph.endRecord(); + metamorph.startRecord("1"); + metamorph.startEntity("d"); + metamorph.literal("1", "a"); + metamorph.literal("1", "b"); + metamorph.endEntity(); + metamorph.startEntity("d"); + metamorph.literal("1", "e"); + metamorph.literal("1", "f"); + metamorph.endEntity(); + metamorph.startEntity("d"); + metamorph.literal("2", "e"); + metamorph.endEntity(); + metamorph.endRecord(); - final InOrder ordered = inOrder(receiver); - ordered.verify(receiver).startRecord("1"); - ordered.verify(receiver).literal("square", "{a,b}"); - ordered.verify(receiver).literal("square", "{e,f}"); - ordered.verify(receiver).endRecord(); - ordered.verifyNoMoreInteractions(); - } + final InOrder ordered = inOrder(receiver); + ordered.verify(receiver).startRecord("1"); + ordered.verify(receiver).literal("square", "{a,b}"); + ordered.verify(receiver).literal("square", "{e,f}"); + ordered.verify(receiver).endRecord(); + ordered.verifyNoMoreInteractions(); + } } diff --git a/metamorph/src/test/java/org/metafacture/metamorph/collectors/TestCollectorBasics.java b/metamorph/src/test/java/org/metafacture/metamorph/collectors/TestCollectorBasics.java index 7cf2cbd3c..8b00ec08c 100644 --- a/metamorph/src/test/java/org/metafacture/metamorph/collectors/TestCollectorBasics.java +++ b/metamorph/src/test/java/org/metafacture/metamorph/collectors/TestCollectorBasics.java @@ -36,141 +36,141 @@ */ public final class TestCollectorBasics { - // TODO: Can this be changed into a JUnit test for AbstractCollect? - - @Rule - public final MockitoRule mockitoRule = MockitoJUnit.rule(); - - @Mock - private StreamReceiver receiver; - - private Metamorph metamorph; - - @Test - public void shouldSupportNestedCollectors() { - metamorph = InlineMorph.in(this) - .with("") - .with(" ") - .with(" ") - .with(" ") - .with(" ") - .with(" ") - .with(" ") - .with(" ") - .with(" ") - .with(" ") - .with(" ") - .with("") - .createConnectedTo(receiver); - - metamorph.startRecord("1"); - metamorph.literal("d1", "a"); - metamorph.literal("d2", "b"); - metamorph.literal("d3", "c "); - metamorph.endRecord(); - - final InOrder ordered = inOrder(receiver); - ordered.verify(receiver).startRecord("1"); - ordered.verify(receiver).literal("d", "abc"); - ordered.verify(receiver).endRecord(); - ordered.verifyNoMoreInteractions(); } - - @Test - public void shouldSupportNestedSameEntity() { - metamorph = InlineMorph.in(this) - .with("") - .with(" ") - .with(" ") - .with(" ") - .with(" ") - .with(" ") - .with(" ") - .with(" ") - .with(" ") - .with(" ") - .with("") - .createConnectedTo(receiver); - - metamorph.startRecord("1"); - metamorph.startEntity("rel"); - metamorph.literal("ch", "b"); - metamorph.literal("value", "a"); - metamorph.endEntity(); - metamorph.startEntity("rel"); - metamorph.literal("value", "B"); - metamorph.endEntity(); - metamorph.startEntity("rel"); - metamorph.literal("ch", "e"); - metamorph.literal("value", "d"); - metamorph.endEntity(); - metamorph.startEntity("rel"); - metamorph.literal("ch", "X"); - metamorph.endEntity(); - metamorph.endRecord(); - - final InOrder ordered = inOrder(receiver); - ordered.verify(receiver).startRecord("1"); - ordered.verify(receiver).literal("result", "ab"); - ordered.verify(receiver).literal("result", "BM"); - ordered.verify(receiver).literal("result", "de"); - ordered.verify(receiver).endRecord(); - ordered.verifyNoMoreInteractions(); - } - - @Test - public void shouldAllowUsingAnArbitraryLiteralForFlush() { - metamorph = InlineMorph.in(this) - .with("") - .with(" ") - .with(" ") - .with(" ") - .with("") - .createConnectedTo(receiver); - - metamorph.startRecord("1"); - metamorph.literal("d", "1"); - metamorph.literal("d", "2"); - metamorph.literal("f", ""); - metamorph.literal("d", "3"); - metamorph.literal("d", "4"); - metamorph.literal("d", "5"); - metamorph.literal("f", ""); - metamorph.literal("d", "6"); - metamorph.endRecord(); - - final InOrder ordered = inOrder(receiver); - ordered.verify(receiver).startRecord("1"); - ordered.verify(receiver).literal("d", "12"); - ordered.verify(receiver).literal("d", "345"); - ordered.verify(receiver).endRecord(); - ordered.verifyNoMoreInteractions(); - } - - @Test - public void shouldReceiveFlushingLiteralBeforeFlushEvent() { - metamorph = InlineMorph.in(this) - .with("") - .with(" ") - .with(" ") - .with(" ") - .with(" ") - .with("") - .createConnectedTo(receiver); - - metamorph.startRecord("1"); - metamorph.literal("f", "1"); - metamorph.literal("f", "2"); - metamorph.literal("d", "a"); - metamorph.literal("f", "3"); - metamorph.endRecord(); - - final InOrder ordered = inOrder(receiver); - ordered.verify(receiver).startRecord("1"); - ordered.verify(receiver).literal("d", "1"); - ordered.verify(receiver).literal("d", "2"); - ordered.verify(receiver).literal("d", "a3"); - ordered.verify(receiver).endRecord(); - ordered.verifyNoMoreInteractions(); - } + // TODO: Can this be changed into a JUnit test for AbstractCollect? + + @Rule + public final MockitoRule mockitoRule = MockitoJUnit.rule(); + + @Mock + private StreamReceiver receiver; + + private Metamorph metamorph; + + @Test + public void shouldSupportNestedCollectors() { + metamorph = InlineMorph.in(this) + .with("") + .with(" ") + .with(" ") + .with(" ") + .with(" ") + .with(" ") + .with(" ") + .with(" ") + .with(" ") + .with(" ") + .with(" ") + .with("") + .createConnectedTo(receiver); + + metamorph.startRecord("1"); + metamorph.literal("d1", "a"); + metamorph.literal("d2", "b"); + metamorph.literal("d3", "c "); + metamorph.endRecord(); + + final InOrder ordered = inOrder(receiver); + ordered.verify(receiver).startRecord("1"); + ordered.verify(receiver).literal("d", "abc"); + ordered.verify(receiver).endRecord(); + ordered.verifyNoMoreInteractions(); } + + @Test + public void shouldSupportNestedSameEntity() { + metamorph = InlineMorph.in(this) + .with("") + .with(" ") + .with(" ") + .with(" ") + .with(" ") + .with(" ") + .with(" ") + .with(" ") + .with(" ") + .with(" ") + .with("") + .createConnectedTo(receiver); + + metamorph.startRecord("1"); + metamorph.startEntity("rel"); + metamorph.literal("ch", "b"); + metamorph.literal("value", "a"); + metamorph.endEntity(); + metamorph.startEntity("rel"); + metamorph.literal("value", "B"); + metamorph.endEntity(); + metamorph.startEntity("rel"); + metamorph.literal("ch", "e"); + metamorph.literal("value", "d"); + metamorph.endEntity(); + metamorph.startEntity("rel"); + metamorph.literal("ch", "X"); + metamorph.endEntity(); + metamorph.endRecord(); + + final InOrder ordered = inOrder(receiver); + ordered.verify(receiver).startRecord("1"); + ordered.verify(receiver).literal("result", "ab"); + ordered.verify(receiver).literal("result", "BM"); + ordered.verify(receiver).literal("result", "de"); + ordered.verify(receiver).endRecord(); + ordered.verifyNoMoreInteractions(); + } + + @Test + public void shouldAllowUsingAnArbitraryLiteralForFlush() { + metamorph = InlineMorph.in(this) + .with("") + .with(" ") + .with(" ") + .with(" ") + .with("") + .createConnectedTo(receiver); + + metamorph.startRecord("1"); + metamorph.literal("d", "1"); + metamorph.literal("d", "2"); + metamorph.literal("f", ""); + metamorph.literal("d", "3"); + metamorph.literal("d", "4"); + metamorph.literal("d", "5"); + metamorph.literal("f", ""); + metamorph.literal("d", "6"); + metamorph.endRecord(); + + final InOrder ordered = inOrder(receiver); + ordered.verify(receiver).startRecord("1"); + ordered.verify(receiver).literal("d", "12"); + ordered.verify(receiver).literal("d", "345"); + ordered.verify(receiver).endRecord(); + ordered.verifyNoMoreInteractions(); + } + + @Test + public void shouldReceiveFlushingLiteralBeforeFlushEvent() { + metamorph = InlineMorph.in(this) + .with("") + .with(" ") + .with(" ") + .with(" ") + .with(" ") + .with("") + .createConnectedTo(receiver); + + metamorph.startRecord("1"); + metamorph.literal("f", "1"); + metamorph.literal("f", "2"); + metamorph.literal("d", "a"); + metamorph.literal("f", "3"); + metamorph.endRecord(); + + final InOrder ordered = inOrder(receiver); + ordered.verify(receiver).startRecord("1"); + ordered.verify(receiver).literal("d", "1"); + ordered.verify(receiver).literal("d", "2"); + ordered.verify(receiver).literal("d", "a3"); + ordered.verify(receiver).endRecord(); + ordered.verifyNoMoreInteractions(); + } } diff --git a/metamorph/src/test/java/org/metafacture/metamorph/collectors/TestCollectorIf.java b/metamorph/src/test/java/org/metafacture/metamorph/collectors/TestCollectorIf.java index ea8378eb2..fd6f16d61 100644 --- a/metamorph/src/test/java/org/metafacture/metamorph/collectors/TestCollectorIf.java +++ b/metamorph/src/test/java/org/metafacture/metamorph/collectors/TestCollectorIf.java @@ -35,256 +35,256 @@ */ public final class TestCollectorIf { - // TODO: Can this be changed into a JUnit test for AbstractCollect? + // TODO: Can this be changed into a JUnit test for AbstractCollect? - @Rule - public final MockitoRule mockitoRule = MockitoJUnit.rule(); + @Rule + public final MockitoRule mockitoRule = MockitoJUnit.rule(); - @Mock - private StreamReceiver receiver; + @Mock + private StreamReceiver receiver; - private Metamorph metamorph; + private Metamorph metamorph; - @Test - public void shouldOnlyFireIfConditionIsMet() { - metamorph = InlineMorph.in(this) - .with("") - .with(" ") - .with(" ") - .with(" ") - .with(" ") - .with(" ") - .with(" ") - .with(" ") - .with("") - .createConnectedTo(receiver); + @Test + public void shouldOnlyFireIfConditionIsMet() { + metamorph = InlineMorph.in(this) + .with("") + .with(" ") + .with(" ") + .with(" ") + .with(" ") + .with(" ") + .with(" ") + .with(" ") + .with("") + .createConnectedTo(receiver); - metamorph.startRecord("1"); - metamorph.literal("data1", "a"); - metamorph.literal("data2", "b"); - metamorph.literal("data3", "c"); - metamorph.endRecord(); - metamorph.startRecord("2"); - metamorph.literal("data1", "a"); - metamorph.literal("data2", "b"); - metamorph.literal("data4", "c"); - metamorph.endRecord(); + metamorph.startRecord("1"); + metamorph.literal("data1", "a"); + metamorph.literal("data2", "b"); + metamorph.literal("data3", "c"); + metamorph.endRecord(); + metamorph.startRecord("2"); + metamorph.literal("data1", "a"); + metamorph.literal("data2", "b"); + metamorph.literal("data4", "c"); + metamorph.endRecord(); - final InOrder ordered = inOrder(receiver); - ordered.verify(receiver).startRecord("1"); - ordered.verify(receiver).literal("combined", "a-b"); - ordered.verify(receiver).endRecord(); - ordered.verify(receiver).startRecord("2"); - ordered.verify(receiver).endRecord(); - ordered.verifyNoMoreInteractions(); - } + final InOrder ordered = inOrder(receiver); + ordered.verify(receiver).startRecord("1"); + ordered.verify(receiver).literal("combined", "a-b"); + ordered.verify(receiver).endRecord(); + ordered.verify(receiver).startRecord("2"); + ordered.verify(receiver).endRecord(); + ordered.verifyNoMoreInteractions(); + } - @Test - public void shouldAllowToUseSameSourceInbodyAndCondition() { - metamorph = InlineMorph.in(this) - .with("") - .with(" ") - .with(" ") - .with(" ") - .with(" ") - .with(" ") - .with(" ") - .with(" ") - .with(" ") - .with(" ") - .with("") - .createConnectedTo(receiver); + @Test + public void shouldAllowToUseSameSourceInbodyAndCondition() { + metamorph = InlineMorph.in(this) + .with("") + .with(" ") + .with(" ") + .with(" ") + .with(" ") + .with(" ") + .with(" ") + .with(" ") + .with(" ") + .with(" ") + .with("") + .createConnectedTo(receiver); - metamorph.startRecord("1"); - metamorph.literal("data1", "a"); - metamorph.literal("data2", "b"); - metamorph.endRecord(); - metamorph.startRecord("2"); - metamorph.literal("data1", "a"); - metamorph.literal("data2", "c"); - metamorph.endRecord(); + metamorph.startRecord("1"); + metamorph.literal("data1", "a"); + metamorph.literal("data2", "b"); + metamorph.endRecord(); + metamorph.startRecord("2"); + metamorph.literal("data1", "a"); + metamorph.literal("data2", "c"); + metamorph.endRecord(); - final InOrder ordered = inOrder(receiver); - ordered.verify(receiver).startRecord("1"); - ordered.verify(receiver).literal("combined", "a-b"); - ordered.verify(receiver).endRecord(); - ordered.verify(receiver).startRecord("2"); - ordered.verify(receiver).endRecord(); - ordered.verifyNoMoreInteractions(); - } + final InOrder ordered = inOrder(receiver); + ordered.verify(receiver).startRecord("1"); + ordered.verify(receiver).literal("combined", "a-b"); + ordered.verify(receiver).endRecord(); + ordered.verify(receiver).startRecord("2"); + ordered.verify(receiver).endRecord(); + ordered.verifyNoMoreInteractions(); + } - @Test - public void shouldAllowQuantorsInIfStatements() { - metamorph = InlineMorph.in(this) - .with("") - .with(" ") - .with(" ") - .with(" ") - .with(" ") - .with(" ") - .with(" ") - .with(" ") - .with(" ") - .with(" ") - .with(" ") - .with("") - .createConnectedTo(receiver); + @Test + public void shouldAllowQuantorsInIfStatements() { + metamorph = InlineMorph.in(this) + .with("") + .with(" ") + .with(" ") + .with(" ") + .with(" ") + .with(" ") + .with(" ") + .with(" ") + .with(" ") + .with(" ") + .with(" ") + .with("") + .createConnectedTo(receiver); - metamorph.startRecord("1"); - metamorph.literal("data1", "a"); - metamorph.literal("data2", "b"); - metamorph.literal("data3", "c"); - metamorph.endRecord(); - metamorph.startRecord("2"); - metamorph.literal("data1", "a"); - metamorph.literal("data2", "d"); - metamorph.literal("data4", "c"); - metamorph.endRecord(); - metamorph.startRecord("3"); - metamorph.literal("data1", "a"); - metamorph.literal("data2", "b"); - metamorph.literal("data5", "c"); - metamorph.endRecord(); + metamorph.startRecord("1"); + metamorph.literal("data1", "a"); + metamorph.literal("data2", "b"); + metamorph.literal("data3", "c"); + metamorph.endRecord(); + metamorph.startRecord("2"); + metamorph.literal("data1", "a"); + metamorph.literal("data2", "d"); + metamorph.literal("data4", "c"); + metamorph.endRecord(); + metamorph.startRecord("3"); + metamorph.literal("data1", "a"); + metamorph.literal("data2", "b"); + metamorph.literal("data5", "c"); + metamorph.endRecord(); - final InOrder ordered = inOrder(receiver); - ordered.verify(receiver).startRecord("1"); - ordered.verify(receiver).literal("combined", "a-b"); - ordered.verify(receiver).endRecord(); - ordered.verify(receiver).startRecord("2"); - ordered.verify(receiver).literal("combined", "a-d"); - ordered.verify(receiver).endRecord(); - ordered.verify(receiver).startRecord("3"); - ordered.verify(receiver).endRecord(); - ordered.verifyNoMoreInteractions(); - } + final InOrder ordered = inOrder(receiver); + ordered.verify(receiver).startRecord("1"); + ordered.verify(receiver).literal("combined", "a-b"); + ordered.verify(receiver).endRecord(); + ordered.verify(receiver).startRecord("2"); + ordered.verify(receiver).literal("combined", "a-d"); + ordered.verify(receiver).endRecord(); + ordered.verify(receiver).startRecord("3"); + ordered.verify(receiver).endRecord(); + ordered.verifyNoMoreInteractions(); + } - @Test - public void shouldResetConditionWithCollector() { - metamorph = InlineMorph.in(this) - .with("") - .with(" ") - .with(" ") - .with(" ") - .with(" ") - .with(" ") - .with(" ") - .with("") - .createConnectedTo(receiver); + @Test + public void shouldResetConditionWithCollector() { + metamorph = InlineMorph.in(this) + .with("") + .with(" ") + .with(" ") + .with(" ") + .with(" ") + .with(" ") + .with(" ") + .with("") + .createConnectedTo(receiver); - metamorph.startRecord("1"); - metamorph.startEntity("entity"); - metamorph.literal("data1", "output"); - metamorph.literal("data2", "X"); - metamorph.endEntity(); - metamorph.startEntity("entity"); - metamorph.literal("data1", "no-output"); - metamorph.literal("data3", "X"); - metamorph.endEntity(); - metamorph.endRecord(); + metamorph.startRecord("1"); + metamorph.startEntity("entity"); + metamorph.literal("data1", "output"); + metamorph.literal("data2", "X"); + metamorph.endEntity(); + metamorph.startEntity("entity"); + metamorph.literal("data1", "no-output"); + metamorph.literal("data3", "X"); + metamorph.endEntity(); + metamorph.endRecord(); - final InOrder ordered = inOrder(receiver); - ordered.verify(receiver).startRecord("1"); - ordered.verify(receiver).literal("result", "output"); - ordered.verify(receiver).endRecord(); - ordered.verifyNoMoreInteractions(); - } + final InOrder ordered = inOrder(receiver); + ordered.verify(receiver).startRecord("1"); + ordered.verify(receiver).literal("result", "output"); + ordered.verify(receiver).endRecord(); + ordered.verifyNoMoreInteractions(); + } - @Test - public void shouldResetConditionWithCollectorOnFlushWith() { - metamorph = InlineMorph.in(this) - .with("") - .with(" ") - .with(" ") - .with(" ") - .with(" ") - .with(" ") - .with(" ") - .with(" ") - .with("") - .createConnectedTo(receiver); + @Test + public void shouldResetConditionWithCollectorOnFlushWith() { + metamorph = InlineMorph.in(this) + .with("") + .with(" ") + .with(" ") + .with(" ") + .with(" ") + .with(" ") + .with(" ") + .with(" ") + .with("") + .createConnectedTo(receiver); - metamorph.startRecord("1"); - metamorph.startEntity("entity"); - metamorph.literal("data1", "output"); - metamorph.literal("data2", "X"); - metamorph.endEntity(); - metamorph.startEntity("entity"); - metamorph.literal("data1", "no-output"); - metamorph.literal("data3", "X"); - metamorph.endEntity(); - metamorph.endRecord(); + metamorph.startRecord("1"); + metamorph.startEntity("entity"); + metamorph.literal("data1", "output"); + metamorph.literal("data2", "X"); + metamorph.endEntity(); + metamorph.startEntity("entity"); + metamorph.literal("data1", "no-output"); + metamorph.literal("data3", "X"); + metamorph.endEntity(); + metamorph.endRecord(); - final InOrder ordered = inOrder(receiver); - ordered.verify(receiver).startRecord("1"); - ordered.verify(receiver).literal("result", "output"); - ordered.verify(receiver).endRecord(); - ordered.verifyNoMoreInteractions(); - } + final InOrder ordered = inOrder(receiver); + ordered.verify(receiver).startRecord("1"); + ordered.verify(receiver).literal("result", "output"); + ordered.verify(receiver).endRecord(); + ordered.verifyNoMoreInteractions(); + } - @Test - public void shouldResetConditionWithCollectorOnSameEntity() { - metamorph = InlineMorph.in(this) - .with("") - .with(" ") - .with(" ") - .with(" ") - .with(" ") - .with(" ") - .with(" ") - .with(" ") - .with("") - .createConnectedTo(receiver); + @Test + public void shouldResetConditionWithCollectorOnSameEntity() { + metamorph = InlineMorph.in(this) + .with("") + .with(" ") + .with(" ") + .with(" ") + .with(" ") + .with(" ") + .with(" ") + .with(" ") + .with("") + .createConnectedTo(receiver); - metamorph.startRecord("1"); - metamorph.startEntity("entity"); - metamorph.literal("data1", "output"); - metamorph.literal("data2", "X"); - metamorph.endEntity(); - metamorph.startEntity("entity"); - metamorph.literal("data1", "no-output"); - metamorph.literal("data3", "X"); - metamorph.literal("data4", "extra-output"); - metamorph.endEntity(); - metamorph.endRecord(); + metamorph.startRecord("1"); + metamorph.startEntity("entity"); + metamorph.literal("data1", "output"); + metamorph.literal("data2", "X"); + metamorph.endEntity(); + metamorph.startEntity("entity"); + metamorph.literal("data1", "no-output"); + metamorph.literal("data3", "X"); + metamorph.literal("data4", "extra-output"); + metamorph.endEntity(); + metamorph.endRecord(); - final InOrder ordered = inOrder(receiver); - ordered.verify(receiver).startRecord("1"); - ordered.verify(receiver).endRecord(); - ordered.verifyNoMoreInteractions(); - } + final InOrder ordered = inOrder(receiver); + ordered.verify(receiver).startRecord("1"); + ordered.verify(receiver).endRecord(); + ordered.verifyNoMoreInteractions(); + } - @Test - public void shouldResetOnFlushWithIfConditionWasNotMet() { - metamorph = InlineMorph.in(this) - .with("") - .with(" ") - .with(" ") - .with(" ") - .with(" ") - .with(" ") - .with(" ") - .with(" ") - .with(" ") - .with(" ") - .with("") - .createConnectedTo(receiver); + @Test + public void shouldResetOnFlushWithIfConditionWasNotMet() { + metamorph = InlineMorph.in(this) + .with("") + .with(" ") + .with(" ") + .with(" ") + .with(" ") + .with(" ") + .with(" ") + .with(" ") + .with(" ") + .with(" ") + .with("") + .createConnectedTo(receiver); - metamorph.startRecord("1"); - metamorph.startEntity("entity"); - metamorph.literal("condition", "false"); - metamorph.literal("literal1", "value1"); - metamorph.endEntity(); - metamorph.startEntity("entity"); - metamorph.literal("condition", "true"); - metamorph.literal("literal2", "value2"); - metamorph.endEntity(); - metamorph.endRecord(); + metamorph.startRecord("1"); + metamorph.startEntity("entity"); + metamorph.literal("condition", "false"); + metamorph.literal("literal1", "value1"); + metamorph.endEntity(); + metamorph.startEntity("entity"); + metamorph.literal("condition", "true"); + metamorph.literal("literal2", "value2"); + metamorph.endEntity(); + metamorph.endRecord(); - final InOrder ordered = inOrder(receiver); - ordered.verify(receiver).startRecord("1"); - ordered.verify(receiver).literal("result", "value2"); - ordered.verify(receiver).endRecord(); - ordered.verifyNoMoreInteractions(); - } + final InOrder ordered = inOrder(receiver); + ordered.verify(receiver).startRecord("1"); + ordered.verify(receiver).literal("result", "value2"); + ordered.verify(receiver).endRecord(); + ordered.verifyNoMoreInteractions(); + } } From 0362c5a82ed2190103ddb9b153d4561d9abc7d42 Mon Sep 17 00:00:00 2001 From: Jens Wille Date: Fri, 29 Oct 2021 21:34:49 +0200 Subject: [PATCH 2/6] Metamorph collector tests should verify that no unexpected interactions occurred. --- .../metamorph/collectors/AllTest.java | 272 +++--- .../metamorph/collectors/AnyTest.java | 266 +++-- .../metamorph/collectors/ChooseTest.java | 426 ++++---- .../metamorph/collectors/CombineTest.java | 315 +++--- .../metamorph/collectors/ConcatTest.java | 275 +++--- .../metamorph/collectors/EntityTest.java | 910 +++++++++--------- .../collectors/EqualsFilterTest.java | 474 +++++---- .../metamorph/collectors/GroupTest.java | 52 +- .../metamorph/collectors/NoneTest.java | 232 +++-- .../metamorph/collectors/RangeTest.java | 289 +++--- .../metamorph/collectors/SquareTest.java | 171 ++-- .../collectors/TestCollectorBasics.java | 231 +++-- .../metamorph/collectors/TestCollectorIf.java | 435 +++++---- 13 files changed, 2135 insertions(+), 2213 deletions(-) diff --git a/metamorph/src/test/java/org/metafacture/metamorph/collectors/AllTest.java b/metamorph/src/test/java/org/metafacture/metamorph/collectors/AllTest.java index 3bac168ae..8f4513abb 100644 --- a/metamorph/src/test/java/org/metafacture/metamorph/collectors/AllTest.java +++ b/metamorph/src/test/java/org/metafacture/metamorph/collectors/AllTest.java @@ -16,15 +16,11 @@ package org.metafacture.metamorph.collectors; -import static org.mockito.Mockito.inOrder; -import static org.mockito.Mockito.times; +import static org.metafacture.metamorph.TestHelpers.assertMorph; import org.junit.Rule; import org.junit.Test; import org.metafacture.framework.StreamReceiver; -import org.metafacture.metamorph.InlineMorph; -import org.metafacture.metamorph.Metamorph; -import org.mockito.InOrder; import org.mockito.Mock; import org.mockito.junit.MockitoJUnit; import org.mockito.junit.MockitoRule; @@ -42,162 +38,160 @@ public final class AllTest { @Mock private StreamReceiver receiver; - private Metamorph metamorph; - @Test public void shouldFireOnlyIfAllElementsFire() { - metamorph = InlineMorph.in(this) - .with("") - .with(" ") - .with(" ") - .with(" ") - .with(" ") - .with("") - .createConnectedTo(receiver); - - metamorph.startRecord("1"); - metamorph.literal("data1", "A"); - metamorph.literal("data2", "B"); - metamorph.endRecord(); - metamorph.startRecord("2"); - metamorph.literal("data2", "C"); - metamorph.endRecord(); - - final InOrder ordered = inOrder(receiver); - ordered.verify(receiver).startRecord("1"); - ordered.verify(receiver).literal("", "true"); - ordered.verify(receiver).endRecord(); - ordered.verify(receiver).startRecord("2"); - ordered.verify(receiver).endRecord(); - ordered.verifyNoMoreInteractions(); + assertMorph(receiver, + "" + + " " + + " " + + " " + + " " + + "", + i -> { + i.startRecord("1"); + i.literal("data1", "A"); + i.literal("data2", "B"); + i.endRecord(); + i.startRecord("2"); + i.literal("data2", "C"); + i.endRecord(); + }, + o -> { + o.get().startRecord("1"); + o.get().literal("", "true"); + o.get().endRecord(); + o.get().startRecord("2"); + o.get().endRecord(); + } + ); } @Test public void shouldSupportUserdefinedNameAndValue() { - metamorph = InlineMorph.in(this) - .with("") - .with(" ") - .with(" ") - .with(" ") - .with(" ") - .with("") - .createConnectedTo(receiver); - - metamorph.startRecord("1"); - metamorph.literal("data1", "A"); - metamorph.literal("data2", "B"); - metamorph.endRecord(); - - final InOrder ordered = inOrder(receiver); - ordered.verify(receiver).startRecord("1"); - ordered.verify(receiver).literal("ALL", "found all"); - ordered.verify(receiver).endRecord(); - ordered.verifyNoMoreInteractions(); + assertMorph(receiver, + "" + + " " + + " " + + " " + + " " + + "", + i -> { + i.startRecord("1"); + i.literal("data1", "A"); + i.literal("data2", "B"); + i.endRecord(); + }, + o -> { + o.get().startRecord("1"); + o.get().literal("ALL", "found all"); + o.get().endRecord(); + } + ); } @Test public void shouldFireAgainIfValueChangesAndResetIsFalse() { - metamorph = InlineMorph.in(this) - .with("") - .with(" ") - .with(" ") - .with(" ") - .with(" ") - .with("") - .createConnectedTo(receiver); - - metamorph.startRecord("1"); - metamorph.startEntity("entity"); - metamorph.literal("data1", "A"); - metamorph.literal("data2", "B"); - metamorph.endEntity(); - metamorph.startEntity("entity"); - metamorph.literal("data2", "C"); - metamorph.endEntity(); - metamorph.endRecord(); - - final InOrder ordered = inOrder(receiver); - ordered.verify(receiver).startRecord("1"); - ordered.verify(receiver, times(2)).literal("", "true"); - ordered.verify(receiver).endRecord(); - ordered.verifyNoMoreInteractions(); + assertMorph(receiver, + "" + + " " + + " " + + " " + + " " + + "", + i -> { + i.startRecord("1"); + i.startEntity("entity"); + i.literal("data1", "A"); + i.literal("data2", "B"); + i.endEntity(); + i.startEntity("entity"); + i.literal("data2", "C"); + i.endEntity(); + i.endRecord(); + }, + (o, f) -> { + o.get().startRecord("1"); + f.apply(2).literal("", "true"); + o.get().endRecord(); + } + ); } @Test public void shouldNotFireAgainIfOnlyOneValueChangesAndResetIsTrue() { - metamorph = InlineMorph.in(this) - .with("") - .with(" ") - .with(" ") - .with(" ") - .with(" ") - .with("") - .createConnectedTo(receiver); - - metamorph.startRecord("1"); - metamorph.startEntity("entity"); - metamorph.literal("data1", "A"); - metamorph.literal("data2", "B"); - metamorph.endEntity(); - metamorph.startEntity("entity"); - metamorph.literal("data2", "B"); - metamorph.endEntity(); - metamorph.endRecord(); - - final InOrder ordered = inOrder(receiver); - ordered.verify(receiver).startRecord("1"); - ordered.verify(receiver).literal("", "true"); - ordered.verify(receiver).endRecord(); - ordered.verifyNoMoreInteractions(); + assertMorph(receiver, + "" + + " " + + " " + + " " + + " " + + "", + i -> { + i.startRecord("1"); + i.startEntity("entity"); + i.literal("data1", "A"); + i.literal("data2", "B"); + i.endEntity(); + i.startEntity("entity"); + i.literal("data2", "B"); + i.endEntity(); + i.endRecord(); + }, + o -> { + o.get().startRecord("1"); + o.get().literal("", "true"); + o.get().endRecord(); + } + ); } @Test public void shouldNotFireIfFlushingAnIncompleteCollection() { - metamorph = InlineMorph.in(this) - .with("") - .with(" ") - .with(" ") - .with(" ") - .with(" ") - .with("") - .createConnectedTo(receiver); - - metamorph.startRecord("1"); - metamorph.startEntity("entity"); - metamorph.literal("data1", "A"); - metamorph.endEntity(); - metamorph.endRecord(); - - final InOrder ordered = inOrder(receiver); - ordered.verify(receiver).startRecord("1"); - ordered.verify(receiver).endRecord(); - ordered.verifyNoMoreInteractions(); + assertMorph(receiver, + "" + + " " + + " " + + " " + + " " + + "", + i -> { + i.startRecord("1"); + i.startEntity("entity"); + i.literal("data1", "A"); + i.endEntity(); + i.endRecord(); + }, + o -> { + o.get().startRecord("1"); + o.get().endRecord(); + } + ); } @Test public void shouldResetWhenEntityChangesIfSameEntity() { - metamorph = InlineMorph.in(this) - .with("") - .with(" ") - .with(" ") - .with(" ") - .with(" ") - .with("") - .createConnectedTo(receiver); - - metamorph.startRecord("1"); - metamorph.startEntity("entity"); - metamorph.literal("data2", "A"); - metamorph.endEntity(); - metamorph.startEntity("entity"); - metamorph.literal("data1", "A"); - metamorph.endEntity(); - metamorph.endRecord(); - - final InOrder ordered = inOrder(receiver); - ordered.verify(receiver).startRecord("1"); - ordered.verify(receiver).endRecord(); - ordered.verifyNoMoreInteractions(); + assertMorph(receiver, + "" + + " " + + " " + + " " + + " " + + "", + i -> { + i.startRecord("1"); + i.startEntity("entity"); + i.literal("data2", "A"); + i.endEntity(); + i.startEntity("entity"); + i.literal("data1", "A"); + i.endEntity(); + i.endRecord(); + }, + o -> { + o.get().startRecord("1"); + o.get().endRecord(); + } + ); } } diff --git a/metamorph/src/test/java/org/metafacture/metamorph/collectors/AnyTest.java b/metamorph/src/test/java/org/metafacture/metamorph/collectors/AnyTest.java index df44b17b1..f76b64056 100644 --- a/metamorph/src/test/java/org/metafacture/metamorph/collectors/AnyTest.java +++ b/metamorph/src/test/java/org/metafacture/metamorph/collectors/AnyTest.java @@ -16,15 +16,11 @@ package org.metafacture.metamorph.collectors; -import static org.mockito.Mockito.inOrder; -import static org.mockito.Mockito.times; +import static org.metafacture.metamorph.TestHelpers.assertMorph; import org.junit.Rule; import org.junit.Test; import org.metafacture.framework.StreamReceiver; -import org.metafacture.metamorph.InlineMorph; -import org.metafacture.metamorph.Metamorph; -import org.mockito.InOrder; import org.mockito.Mock; import org.mockito.junit.MockitoJUnit; import org.mockito.junit.MockitoRule; @@ -42,159 +38,157 @@ public final class AnyTest { @Mock private StreamReceiver receiver; - private Metamorph metamorph; - @Test public void shouldFireOnlyIfAtLeastOneElementFires() { - metamorph = InlineMorph.in(this) - .with("") - .with(" ") - .with(" ") - .with(" ") - .with(" ") - .with("") - .createConnectedTo(receiver); - - metamorph.startRecord("1"); - metamorph.literal("data1", "A"); - metamorph.endRecord(); - metamorph.startRecord("2"); - metamorph.literal("data2", "C"); - metamorph.endRecord(); - metamorph.startRecord("3"); - metamorph.literal("data3", "C"); - metamorph.endRecord(); - - final InOrder ordered = inOrder(receiver); - ordered.verify(receiver).startRecord("1"); - ordered.verify(receiver).literal("", "true"); - ordered.verify(receiver).endRecord(); - ordered.verify(receiver).startRecord("2"); - ordered.verify(receiver).literal("", "true"); - ordered.verify(receiver).endRecord(); - ordered.verify(receiver).startRecord("3"); - ordered.verify(receiver).endRecord(); - ordered.verifyNoMoreInteractions(); + assertMorph(receiver, + "" + + " " + + " " + + " " + + " " + + "", + i -> { + i.startRecord("1"); + i.literal("data1", "A"); + i.endRecord(); + i.startRecord("2"); + i.literal("data2", "C"); + i.endRecord(); + i.startRecord("3"); + i.literal("data3", "C"); + i.endRecord(); + }, + o -> { + o.get().startRecord("1"); + o.get().literal("", "true"); + o.get().endRecord(); + o.get().startRecord("2"); + o.get().literal("", "true"); + o.get().endRecord(); + o.get().startRecord("3"); + o.get().endRecord(); + } + ); } @Test public void shouldSupportUserdefinedNameAndValue() { - metamorph = InlineMorph.in(this) - .with("") - .with(" ") - .with(" ") - .with(" ") - .with(" ") - .with("") - .createConnectedTo(receiver); - - metamorph.startRecord("1"); - metamorph.literal("data1", "A"); - metamorph.endRecord(); - - final InOrder ordered = inOrder(receiver); - ordered.verify(receiver).startRecord("1"); - ordered.verify(receiver).literal("ANY", "found one"); - ordered.verify(receiver).endRecord(); - ordered.verifyNoMoreInteractions(); + assertMorph(receiver, + "" + + " " + + " " + + " " + + " " + + "", + i -> { + i.startRecord("1"); + i.literal("data1", "A"); + i.endRecord(); + }, + o -> { + o.get().startRecord("1"); + o.get().literal("ANY", "found one"); + o.get().endRecord(); + } + ); } @Test public void shouldNotFireAgainIfAdditionalValueIsReceivedAndResetIsFalse() { - metamorph = InlineMorph.in(this) - .with("") - .with(" ") - .with(" ") - .with(" ") - .with(" ") - .with("") - .createConnectedTo(receiver); - - metamorph.startRecord("1"); - metamorph.literal("data1", "A"); - metamorph.literal("data2", "B"); - metamorph.literal("data2", "C"); - metamorph.endRecord(); - - final InOrder ordered = inOrder(receiver); - ordered.verify(receiver).startRecord("1"); - ordered.verify(receiver).literal("", "true"); - ordered.verify(receiver).endRecord(); - ordered.verifyNoMoreInteractions(); + assertMorph(receiver, + "" + + " " + + " " + + " " + + " " + + "", + i -> { + i.startRecord("1"); + i.literal("data1", "A"); + i.literal("data2", "B"); + i.literal("data2", "C"); + i.endRecord(); + }, + o -> { + o.get().startRecord("1"); + o.get().literal("", "true"); + o.get().endRecord(); + } + ); } @Test public void shouldFireAgainIfAdditionalValueIsReceivedAndResetIsTrue() { - metamorph = InlineMorph.in(this) - .with("") - .with(" ") - .with(" ") - .with(" ") - .with(" ") - .with("") - .createConnectedTo(receiver); - - metamorph.startRecord("1"); - metamorph.literal("data1", "A"); - metamorph.literal("data2", "B"); - metamorph.literal("data2", "C"); - metamorph.endRecord(); - - final InOrder ordered = inOrder(receiver); - ordered.verify(receiver).startRecord("1"); - ordered.verify(receiver, times(3)).literal("", "true"); - ordered.verify(receiver).endRecord(); - ordered.verifyNoMoreInteractions(); + assertMorph(receiver, + "" + + " " + + " " + + " " + + " " + + "", + i -> { + i.startRecord("1"); + i.literal("data1", "A"); + i.literal("data2", "B"); + i.literal("data2", "C"); + i.endRecord(); + }, + (o, f) -> { + o.get().startRecord("1"); + f.apply(3).literal("", "true"); + o.get().endRecord(); + } + ); } @Test public void shouldFireAgainAfterFlushing() { - metamorph = InlineMorph.in(this) - .with("") - .with(" ") - .with(" ") - .with(" ") - .with(" ") - .with("") - .createConnectedTo(receiver); - - metamorph.startRecord("1"); - metamorph.startEntity("entity"); - metamorph.literal("data1", "A"); - metamorph.endEntity(); - metamorph.startEntity("entity"); - metamorph.literal("data2", "B"); - metamorph.endEntity(); - metamorph.endRecord(); - - final InOrder ordered = inOrder(receiver); - ordered.verify(receiver).startRecord("1"); - ordered.verify(receiver, times(2)).literal("", "true"); - ordered.verify(receiver).endRecord(); - ordered.verifyNoMoreInteractions(); + assertMorph(receiver, + "" + + " " + + " " + + " " + + " " + + "", + i -> { + i.startRecord("1"); + i.startEntity("entity"); + i.literal("data1", "A"); + i.endEntity(); + i.startEntity("entity"); + i.literal("data2", "B"); + i.endEntity(); + i.endRecord(); + }, + (o, f) -> { + o.get().startRecord("1"); + f.apply(2).literal("", "true"); + o.get().endRecord(); + } + ); } @Test public void shouldNotFireIfFlushingAnUntriggeredCollection() { - metamorph = InlineMorph.in(this) - .with("") - .with(" ") - .with(" ") - .with(" ") - .with(" ") - .with("") - .createConnectedTo(receiver); - - metamorph.startRecord("1"); - metamorph.startEntity("entity"); - metamorph.literal("data3", "A"); - metamorph.endEntity(); - metamorph.endRecord(); - - final InOrder ordered = inOrder(receiver); - ordered.verify(receiver).startRecord("1"); - ordered.verify(receiver).endRecord(); - ordered.verifyNoMoreInteractions(); + assertMorph(receiver, + "" + + " " + + " " + + " " + + " " + + "", + i -> { + i.startRecord("1"); + i.startEntity("entity"); + i.literal("data3", "A"); + i.endEntity(); + i.endRecord(); + }, + o -> { + o.get().startRecord("1"); + o.get().endRecord(); + } + ); } } diff --git a/metamorph/src/test/java/org/metafacture/metamorph/collectors/ChooseTest.java b/metamorph/src/test/java/org/metafacture/metamorph/collectors/ChooseTest.java index e1fa7c50c..b3a9c068d 100644 --- a/metamorph/src/test/java/org/metafacture/metamorph/collectors/ChooseTest.java +++ b/metamorph/src/test/java/org/metafacture/metamorph/collectors/ChooseTest.java @@ -16,15 +16,11 @@ package org.metafacture.metamorph.collectors; -import static org.mockito.Mockito.inOrder; -import static org.mockito.Mockito.times; +import static org.metafacture.metamorph.TestHelpers.assertMorph; import org.junit.Rule; import org.junit.Test; import org.metafacture.framework.StreamReceiver; -import org.metafacture.metamorph.InlineMorph; -import org.metafacture.metamorph.Metamorph; -import org.mockito.InOrder; import org.mockito.Mock; import org.mockito.junit.MockitoJUnit; import org.mockito.junit.MockitoRule; @@ -43,251 +39,249 @@ public final class ChooseTest { @Mock private StreamReceiver receiver; - private Metamorph metamorph; - @Test public void shouldChooseValueOfTopMostFiringStatement() { - metamorph = InlineMorph.in(this) - .with("") - .with(" ") - .with(" ") - .with(" ") - .with(" ") - .with("") - .createConnectedTo(receiver); - - metamorph.startRecord("1"); - metamorph.literal("data1", "A"); - metamorph.literal("data2", "B"); - metamorph.endRecord(); - metamorph.startRecord("2"); - metamorph.literal("data1", "B"); - metamorph.literal("data2", "A"); - metamorph.endRecord(); - metamorph.startRecord("3"); - metamorph.literal("data2", "C"); - metamorph.endRecord(); - - final InOrder ordered = inOrder(receiver); - ordered.verify(receiver).startRecord("1"); - ordered.verify(receiver).literal("data1", "A"); - ordered.verify(receiver).endRecord(); - ordered.verify(receiver).startRecord("2"); - ordered.verify(receiver).literal("data1", "B"); - ordered.verify(receiver).endRecord(); - ordered.verify(receiver).startRecord("3"); - ordered.verify(receiver).literal("data2", "C"); - ordered.verify(receiver).endRecord(); - ordered.verifyNoMoreInteractions(); + assertMorph(receiver, + "" + + " " + + " " + + " " + + " " + + "", + i -> { + i.startRecord("1"); + i.literal("data1", "A"); + i.literal("data2", "B"); + i.endRecord(); + i.startRecord("2"); + i.literal("data1", "B"); + i.literal("data2", "A"); + i.endRecord(); + i.startRecord("3"); + i.literal("data2", "C"); + i.endRecord(); + }, + o -> { + o.get().startRecord("1"); + o.get().literal("data1", "A"); + o.get().endRecord(); + o.get().startRecord("2"); + o.get().literal("data1", "B"); + o.get().endRecord(); + o.get().startRecord("3"); + o.get().literal("data2", "C"); + o.get().endRecord(); + } + ); } @Test public void shouldMakeChooseDecisionOnFlushEvent() { - metamorph = InlineMorph.in(this) - .with("") - .with(" ") - .with(" ") - .with(" ") - .with(" ") - .with("") - .createConnectedTo(receiver); - - metamorph.startRecord("1"); - metamorph.startEntity("entity"); - metamorph.literal("data1", "A"); - metamorph.literal("data2", "B"); - metamorph.endEntity(); - metamorph.startEntity("entity"); - metamorph.literal("data1", "B"); - metamorph.literal("data2", "A"); - metamorph.endEntity(); - metamorph.startEntity("entity"); - metamorph.literal("data2", "C"); - metamorph.endEntity(); - metamorph.startEntity("entity"); - metamorph.literal("dataX", "X"); - metamorph.endEntity(); - metamorph.endRecord(); - - final InOrder ordered = inOrder(receiver); - ordered.verify(receiver).startRecord("1"); - ordered.verify(receiver).literal("entity.data1", "A"); - ordered.verify(receiver).literal("entity.data1", "B"); - ordered.verify(receiver).literal("entity.data2", "C"); - ordered.verify(receiver).endRecord(); - ordered.verifyNoMoreInteractions(); + assertMorph(receiver, + "" + + " " + + " " + + " " + + " " + + "", + i -> { + i.startRecord("1"); + i.startEntity("entity"); + i.literal("data1", "A"); + i.literal("data2", "B"); + i.endEntity(); + i.startEntity("entity"); + i.literal("data1", "B"); + i.literal("data2", "A"); + i.endEntity(); + i.startEntity("entity"); + i.literal("data2", "C"); + i.endEntity(); + i.startEntity("entity"); + i.literal("dataX", "X"); + i.endEntity(); + i.endRecord(); + }, + o -> { + o.get().startRecord("1"); + o.get().literal("entity.data1", "A"); + o.get().literal("entity.data1", "B"); + o.get().literal("entity.data2", "C"); + o.get().endRecord(); + } + ); } @Test public void issue110_shouldOutputFallBackIfFlushedWithEntity() { - metamorph = InlineMorph.in(this) - .with("") - .with(" ") - .with(" ") - .with(" ") - .with(" ") - .with("") - .createConnectedTo(receiver); - - metamorph.startRecord("1"); - metamorph.literal("L", "V"); - metamorph.endRecord(); - - final InOrder ordered = inOrder(receiver); - ordered.verify(receiver).startRecord("1"); - ordered.verify(receiver).literal("chosen", "V"); - ordered.verify(receiver).endRecord(); - ordered.verifyNoMoreInteractions(); + assertMorph(receiver, + "" + + " " + + " " + + " " + + " " + + "", + i -> { + i.startRecord("1"); + i.literal("L", "V"); + i.endRecord(); + }, + o -> { + o.get().startRecord("1"); + o.get().literal("chosen", "V"); + o.get().endRecord(); + } + ); } @Test public void issue210_issue49_shouldRepeatedlyEmitNamedValueIfResetIsFalse() { - metamorph = InlineMorph.in(this) - .with("") - .with(" ") - .with(" ") - .with(" ") - .with("") - .createConnectedTo(receiver); - - metamorph.startRecord("1"); - metamorph.literal("lit1", "data1"); - metamorph.literal("flush", "first"); - metamorph.literal("flush", "second"); - metamorph.endRecord(); - - final InOrder ordered = inOrder(receiver); - ordered.verify(receiver).startRecord("1"); - ordered.verify(receiver, times(2)).literal("lit1", "data1"); - ordered.verify(receiver).endRecord(); - ordered.verifyNoMoreInteractions(); + assertMorph(receiver, + "" + + " " + + " " + + " " + + "", + i -> { + i.startRecord("1"); + i.literal("lit1", "data1"); + i.literal("flush", "first"); + i.literal("flush", "second"); + i.endRecord(); + }, + (o, f) -> { + o.get().startRecord("1"); + f.apply(2).literal("lit1", "data1"); + o.get().endRecord(); + } + ); } @Test public void issue210_shouldResetAfterEmittingNamedValueIfResetIsTrue() { - metamorph = InlineMorph.in(this) - .with("") - .with(" ") - .with(" ") - .with(" ") - .with("") - .createConnectedTo(receiver); - - metamorph.startRecord("1"); - metamorph.literal("lit1", "data1"); - metamorph.literal("flush", "first"); - metamorph.literal("flush", "second"); - metamorph.endRecord(); - - final InOrder ordered = inOrder(receiver); - ordered.verify(receiver).startRecord("1"); - ordered.verify(receiver, times(1)).literal("lit1", "data1"); - ordered.verify(receiver).endRecord(); - ordered.verifyNoMoreInteractions(); + assertMorph(receiver, + "" + + " " + + " " + + " " + + "", + i -> { + i.startRecord("1"); + i.literal("lit1", "data1"); + i.literal("flush", "first"); + i.literal("flush", "second"); + i.endRecord(); + }, + (o, f) -> { + o.get().startRecord("1"); + f.apply(1).literal("lit1", "data1"); + o.get().endRecord(); + } + ); } @Test public void issue210_shouldResetAfterEmittingNamedValueByDefault() { - metamorph = InlineMorph.in(this) - .with("") - .with(" ") - .with(" ") - .with(" ") - .with("") - .createConnectedTo(receiver); - - metamorph.startRecord("1"); - metamorph.literal("lit1", "data1"); - metamorph.literal("flush", "first"); - metamorph.literal("flush", "second"); - metamorph.endRecord(); - - final InOrder ordered = inOrder(receiver); - ordered.verify(receiver).startRecord("1"); - ordered.verify(receiver, times(1)).literal("lit1", "data1"); - ordered.verify(receiver).endRecord(); - ordered.verifyNoMoreInteractions(); + assertMorph(receiver, + "" + + " " + + " " + + " " + + "", + i -> { + i.startRecord("1"); + i.literal("lit1", "data1"); + i.literal("flush", "first"); + i.literal("flush", "second"); + i.endRecord(); + }, + (o, f) -> { + o.get().startRecord("1"); + f.apply(1).literal("lit1", "data1"); + o.get().endRecord(); + } + ); } @Test public void issue250_shouldResetOnEntityChangeIfSameEntityIsTrue() { - metamorph = InlineMorph.in(this) - .with("") - .with(" ") - .with(" ") - .with(" ") - .with(" ") - .with("") - .createConnectedTo(receiver); - - metamorph.startRecord("1"); - metamorph.startEntity("entity"); - metamorph.literal("lit1", "data1"); - metamorph.endEntity(); - metamorph.startEntity("entity"); - metamorph.literal("lit2", "data2"); - metamorph.endEntity(); - metamorph.endRecord(); - - final InOrder ordered = inOrder(receiver); - ordered.verify(receiver).startRecord("1"); - ordered.verify(receiver).literal("entity.lit2", "data2"); - ordered.verify(receiver).endRecord(); - ordered.verifyNoMoreInteractions(); + assertMorph(receiver, + "" + + " " + + " " + + " " + + " " + + "", + i -> { + i.startRecord("1"); + i.startEntity("entity"); + i.literal("lit1", "data1"); + i.endEntity(); + i.startEntity("entity"); + i.literal("lit2", "data2"); + i.endEntity(); + i.endRecord(); + }, + o -> { + o.get().startRecord("1"); + o.get().literal("entity.lit2", "data2"); + o.get().endRecord(); + } + ); } @Test public void issue250_shouldNotResetOnEntityChangeIfSameEntityIsFalse() { - metamorph = InlineMorph.in(this) - .with("") - .with(" ") - .with(" ") - .with(" ") - .with(" ") - .with("") - .createConnectedTo(receiver); - - metamorph.startRecord("1"); - metamorph.startEntity("entity"); - metamorph.literal("lit1", "data1"); - metamorph.endEntity(); - metamorph.startEntity("entity"); - metamorph.literal("lit2", "data2"); - metamorph.endEntity(); - metamorph.endRecord(); - - final InOrder ordered = inOrder(receiver); - ordered.verify(receiver).startRecord("1"); - ordered.verify(receiver).literal("entity.lit1", "data1"); - ordered.verify(receiver).endRecord(); - ordered.verifyNoMoreInteractions(); + assertMorph(receiver, + "" + + " " + + " " + + " " + + " " + + "", + i -> { + i.startRecord("1"); + i.startEntity("entity"); + i.literal("lit1", "data1"); + i.endEntity(); + i.startEntity("entity"); + i.literal("lit2", "data2"); + i.endEntity(); + i.endRecord(); + }, + o -> { + o.get().startRecord("1"); + o.get().literal("entity.lit1", "data1"); + o.get().endRecord(); + } + ); } @Test public void issue250_shouldNotResetOnEntityChangeByDefault() { - metamorph = InlineMorph.in(this) - .with("") - .with(" ") - .with(" ") - .with(" ") - .with(" ") - .with("") - .createConnectedTo(receiver); - - metamorph.startRecord("1"); - metamorph.startEntity("entity"); - metamorph.literal("lit1", "data1"); - metamorph.endEntity(); - metamorph.startEntity("entity"); - metamorph.literal("lit2", "data2"); - metamorph.endEntity(); - metamorph.endRecord(); - - final InOrder ordered = inOrder(receiver); - ordered.verify(receiver).startRecord("1"); - ordered.verify(receiver).literal("entity.lit1", "data1"); - ordered.verify(receiver).endRecord(); - ordered.verifyNoMoreInteractions(); + assertMorph(receiver, + "" + + " " + + " " + + " " + + " " + + "", + i -> { + i.startRecord("1"); + i.startEntity("entity"); + i.literal("lit1", "data1"); + i.endEntity(); + i.startEntity("entity"); + i.literal("lit2", "data2"); + i.endEntity(); + i.endRecord(); + }, + o -> { + o.get().startRecord("1"); + o.get().literal("entity.lit1", "data1"); + o.get().endRecord(); + } + ); } } diff --git a/metamorph/src/test/java/org/metafacture/metamorph/collectors/CombineTest.java b/metamorph/src/test/java/org/metafacture/metamorph/collectors/CombineTest.java index 9cbfc4593..ce6b3e1ea 100644 --- a/metamorph/src/test/java/org/metafacture/metamorph/collectors/CombineTest.java +++ b/metamorph/src/test/java/org/metafacture/metamorph/collectors/CombineTest.java @@ -16,15 +16,11 @@ package org.metafacture.metamorph.collectors; -import static org.mockito.Mockito.inOrder; -import static org.mockito.Mockito.verifyNoMoreInteractions; +import static org.metafacture.metamorph.TestHelpers.assertMorph; import org.junit.Rule; import org.junit.Test; import org.metafacture.framework.StreamReceiver; -import org.metafacture.metamorph.InlineMorph; -import org.metafacture.metamorph.Metamorph; -import org.mockito.InOrder; import org.mockito.Mock; import org.mockito.junit.MockitoJUnit; import org.mockito.junit.MockitoRule; @@ -43,184 +39,181 @@ public final class CombineTest { @Mock private StreamReceiver receiver; - private Metamorph metamorph; - @Test public void shouldCombineTwoValues() { - metamorph = InlineMorph.in(this) - .with("") - .with(" ") - .with(" ") - .with(" ") - .with(" ") - .with("") - .createConnectedTo(receiver); - - metamorph.startRecord("1"); - metamorph.literal("data1", "a"); - metamorph.literal("data2", "b"); - metamorph.literal("data2", "c"); - metamorph.endRecord(); - - final InOrder ordered = inOrder(receiver); - ordered.verify(receiver).startRecord("1"); - ordered.verify(receiver).literal("combination", "ba"); - ordered.verify(receiver).literal("combination", "ca"); - ordered.verify(receiver).endRecord(); - ordered.verifyNoMoreInteractions(); + assertMorph(receiver, + "" + + " " + + " " + + " " + + " " + + "", + i -> { + i.startRecord("1"); + i.literal("data1", "a"); + i.literal("data2", "b"); + i.literal("data2", "c"); + i.endRecord(); + }, + o -> { + o.get().startRecord("1"); + o.get().literal("combination", "ba"); + o.get().literal("combination", "ca"); + o.get().endRecord(); + } + ); } @Test public void shouldOnlyCombineValuesFromTheSameEntityIfSet() { - metamorph = InlineMorph.in(this) - .with("") - .with(" ") - .with(" ") - .with(" ") - .with(" ") - .with("") - .createConnectedTo(receiver); - - metamorph.startRecord("1"); - metamorph.startEntity("entity"); - metamorph.literal("data1", "b"); - metamorph.literal("data2", "a"); - metamorph.endEntity(); - metamorph.startEntity("entity"); - metamorph.literal("data2", "c"); - metamorph.literal("data2", "d"); - metamorph.endEntity(); - metamorph.startEntity("entity"); - metamorph.literal("data1", "e"); - metamorph.endEntity(); - metamorph.startEntity("entity"); - metamorph.literal("data2", "f"); - metamorph.literal("data1", "g"); - metamorph.endEntity(); - metamorph.endRecord(); - - final InOrder ordered = inOrder(receiver); - ordered.verify(receiver).startRecord("1"); - ordered.verify(receiver).literal("combination", "ab"); - ordered.verify(receiver).literal("combination", "fg"); - ordered.verify(receiver).endRecord(); - ordered.verifyNoMoreInteractions(); + assertMorph(receiver, + "" + + " " + + " " + + " " + + " " + + "", + i -> { + i.startRecord("1"); + i.startEntity("entity"); + i.literal("data1", "b"); + i.literal("data2", "a"); + i.endEntity(); + i.startEntity("entity"); + i.literal("data2", "c"); + i.literal("data2", "d"); + i.endEntity(); + i.startEntity("entity"); + i.literal("data1", "e"); + i.endEntity(); + i.startEntity("entity"); + i.literal("data2", "f"); + i.literal("data1", "g"); + i.endEntity(); + i.endRecord(); + }, + o -> { + o.get().startRecord("1"); + o.get().literal("combination", "ab"); + o.get().literal("combination", "fg"); + o.get().endRecord(); + } + ); } @Test public void shouldResetCombinedValueIfResetIsTrue() { - metamorph = InlineMorph.in(this) - .with("") - .with(" ") - .with(" ") - .with(" ") - .with(" ") - .with("") - .createConnectedTo(receiver); - - metamorph.startRecord("1"); - metamorph.literal("data1", "b"); - metamorph.literal("data2", "a"); - metamorph.literal("data2", "c"); - metamorph.literal("data2", "d"); - metamorph.literal("data1", "e"); - metamorph.endRecord(); - - final InOrder ordered = inOrder(receiver); - ordered.verify(receiver).startRecord("1"); - ordered.verify(receiver).literal("combination", "ab"); - ordered.verify(receiver).literal("combination", "de"); - ordered.verify(receiver).endRecord(); - ordered.verifyNoMoreInteractions(); + assertMorph(receiver, + "" + + " " + + " " + + " " + + " " + + "", + i -> { + i.startRecord("1"); + i.literal("data1", "b"); + i.literal("data2", "a"); + i.literal("data2", "c"); + i.literal("data2", "d"); + i.literal("data1", "e"); + i.endRecord(); + }, + o -> { + o.get().startRecord("1"); + o.get().literal("combination", "ab"); + o.get().literal("combination", "de"); + o.get().endRecord(); + } + ); } @Test public void shouldEmitCurrentValueOnFlushEvent() { - metamorph = InlineMorph.in(this) - .with("") - .with(" ") - .with(" ") - .with(" ") - .with(" ") - .with("") - .createConnectedTo(receiver); - - metamorph.startRecord("1"); - metamorph.startEntity("e"); - metamorph.literal("l", "1"); - metamorph.endEntity(); - metamorph.startEntity("e"); - metamorph.literal("l", "2"); - metamorph.literal("m", "2"); - metamorph.endEntity(); - metamorph.startEntity("e"); - metamorph.literal("l", "3"); - metamorph.endEntity(); - metamorph.endRecord(); - - final InOrder ordered = inOrder(receiver); - ordered.verify(receiver).startRecord("1"); - ordered.verify(receiver).literal("combi", "1"); - ordered.verify(receiver).literal("combi", "22"); - ordered.verify(receiver).literal("combi", "3"); - ordered.verify(receiver).endRecord(); - ordered.verifyNoMoreInteractions(); + assertMorph(receiver, + "" + + " " + + " " + + " " + + " " + + "", + i -> { + i.startRecord("1"); + i.startEntity("e"); + i.literal("l", "1"); + i.endEntity(); + i.startEntity("e"); + i.literal("l", "2"); + i.literal("m", "2"); + i.endEntity(); + i.startEntity("e"); + i.literal("l", "3"); + i.endEntity(); + i.endRecord(); + }, + o -> { + o.get().startRecord("1"); + o.get().literal("combi", "1"); + o.get().literal("combi", "22"); + o.get().literal("combi", "3"); + o.get().endRecord(); + } + ); } @Test public void shouldNotEmitCurrentValueOnFlushEventIfIncomplete() { - metamorph = InlineMorph.in(this) - .with("") - .with(" ") - .with(" ") - .with(" ") - .with(" ") - .with("") - .createConnectedTo(receiver); - - metamorph.startRecord("1"); - metamorph.startEntity("e"); - metamorph.literal("l", "1"); - metamorph.endEntity(); - metamorph.startEntity("e"); - metamorph.literal("l", "2"); - metamorph.literal("m", "2"); - metamorph.endEntity(); - metamorph.startEntity("e"); - metamorph.literal("l", "3"); - metamorph.endEntity(); - metamorph.endRecord(); - - final InOrder ordered = inOrder(receiver); - ordered.verify(receiver).startRecord("1"); - ordered.verify(receiver).literal("combi", "22"); - ordered.verify(receiver).endRecord(); - ordered.verifyNoMoreInteractions(); - verifyNoMoreInteractions(receiver); + assertMorph(receiver, + "" + + " " + + " " + + " " + + " " + + "", + i -> { + i.startRecord("1"); + i.startEntity("e"); + i.literal("l", "1"); + i.endEntity(); + i.startEntity("e"); + i.literal("l", "2"); + i.literal("m", "2"); + i.endEntity(); + i.startEntity("e"); + i.literal("l", "3"); + i.endEntity(); + i.endRecord(); + }, + o -> { + o.get().startRecord("1"); + o.get().literal("combi", "22"); + o.get().endRecord(); + } + ); } @Test public void shouldPostprocessCombinedValue() { - metamorph = InlineMorph.in(this) - .with("") - .with(" ") - .with(" ") - .with(" ") - .with(" ") - .with(" ") - .with(" ") - .with("") - .createConnectedTo(receiver); - - metamorph.startRecord("1"); - metamorph.literal("inLit", "value"); - metamorph.endRecord(); - - final InOrder ordered = inOrder(receiver); - ordered.verify(receiver).startRecord("1"); - ordered.verify(receiver).literal("outLit", "VALUE"); - ordered.verify(receiver).endRecord(); - ordered.verifyNoMoreInteractions(); + assertMorph(receiver, + "" + + " " + + " " + + " " + + " " + + " " + + " " + + "", + i -> { + i.startRecord("1"); + i.literal("inLit", "value"); + i.endRecord(); + }, + o -> { + o.get().startRecord("1"); + o.get().literal("outLit", "VALUE"); + o.get().endRecord(); + } + ); } } diff --git a/metamorph/src/test/java/org/metafacture/metamorph/collectors/ConcatTest.java b/metamorph/src/test/java/org/metafacture/metamorph/collectors/ConcatTest.java index cfd9b52bb..c7036e3cb 100644 --- a/metamorph/src/test/java/org/metafacture/metamorph/collectors/ConcatTest.java +++ b/metamorph/src/test/java/org/metafacture/metamorph/collectors/ConcatTest.java @@ -16,14 +16,11 @@ package org.metafacture.metamorph.collectors; -import static org.mockito.Mockito.inOrder; +import static org.metafacture.metamorph.TestHelpers.assertMorph; import org.junit.Rule; import org.junit.Test; import org.metafacture.framework.StreamReceiver; -import org.metafacture.metamorph.InlineMorph; -import org.metafacture.metamorph.Metamorph; -import org.mockito.InOrder; import org.mockito.Mock; import org.mockito.junit.MockitoJUnit; import org.mockito.junit.MockitoRule; @@ -42,164 +39,162 @@ public final class ConcatTest { @Mock private StreamReceiver receiver; - private Metamorph metamorph; - @Test public void shouldConcatenateValues() { - metamorph = InlineMorph.in(this) - .with("") - .with(" ") - .with(" ") - .with(" ") - .with(" ") - .with("") - .createConnectedTo(receiver); - - metamorph.startRecord("1"); - metamorph.literal("data1", "a"); - metamorph.literal("data1", "b"); - metamorph.literal("data2", "c"); - metamorph.endRecord(); - metamorph.startRecord("2"); - metamorph.literal("data1", "d"); - metamorph.literal("data1", "e"); - metamorph.literal("data2", "f"); - metamorph.endRecord(); - - final InOrder ordered = inOrder(receiver); - ordered.verify(receiver).startRecord("1"); - ordered.verify(receiver).literal("concat", "{a, b, c}"); - ordered.verify(receiver).endRecord(); - ordered.verify(receiver).startRecord("2"); - ordered.verify(receiver).literal("concat", "{d, e, f}"); - ordered.verify(receiver).endRecord(); - ordered.verifyNoMoreInteractions(); + assertMorph(receiver, + "" + + " " + + " " + + " " + + " " + + "", + i -> { + i.startRecord("1"); + i.literal("data1", "a"); + i.literal("data1", "b"); + i.literal("data2", "c"); + i.endRecord(); + i.startRecord("2"); + i.literal("data1", "d"); + i.literal("data1", "e"); + i.literal("data2", "f"); + i.endRecord(); + }, + o -> { + o.get().startRecord("1"); + o.get().literal("concat", "{a, b, c}"); + o.get().endRecord(); + o.get().startRecord("2"); + o.get().literal("concat", "{d, e, f}"); + o.get().endRecord(); + } + ); } @Test public void shouldEmitConcatenatedValueOnFlushEvent() { - metamorph = InlineMorph.in(this) - .with("") - .with(" ") - .with(" ") - .with(" ") - .with("") - .createConnectedTo(receiver); - - metamorph.startRecord("1"); - metamorph.startEntity("d"); - metamorph.literal("1", "a"); - metamorph.literal("1", "b"); - metamorph.endEntity(); - metamorph.startEntity("d"); - metamorph.literal("1", "e"); - metamorph.literal("1", "f"); - metamorph.endEntity(); - metamorph.startEntity("d"); - metamorph.literal("2", "e"); - metamorph.endEntity(); - metamorph.endRecord(); - - final InOrder ordered = inOrder(receiver); - ordered.verify(receiver).startRecord("1"); - ordered.verify(receiver).literal("concat", "{a, b}"); - ordered.verify(receiver).literal("concat", "{e, f}"); - ordered.verify(receiver).endRecord(); - ordered.verifyNoMoreInteractions(); + assertMorph(receiver, + "" + + " " + + " " + + " " + + "", + i -> { + i.startRecord("1"); + i.startEntity("d"); + i.literal("1", "a"); + i.literal("1", "b"); + i.endEntity(); + i.startEntity("d"); + i.literal("1", "e"); + i.literal("1", "f"); + i.endEntity(); + i.startEntity("d"); + i.literal("2", "e"); + i.endEntity(); + i.endRecord(); + }, + o -> { + o.get().startRecord("1"); + o.get().literal("concat", "{a, b}"); + o.get().literal("concat", "{e, f}"); + o.get().endRecord(); + } + ); } @Test public void shouldEmitEmptyValues() { - metamorph = InlineMorph.in(this) - .with("") - .with(" ") - .with(" ") - .with(" ") - .with(" ") - .with("") - .createConnectedTo(receiver); - - metamorph.startRecord("1"); - metamorph.literal("litA", ""); - metamorph.literal("litB", "a"); - metamorph.literal("litA", "b"); - metamorph.endRecord(); - - final InOrder ordered = inOrder(receiver); - ordered.verify(receiver).startRecord("1"); - ordered.verify(receiver).literal("concat", ", a, b"); - ordered.verify(receiver).endRecord(); - ordered.verifyNoMoreInteractions(); + assertMorph(receiver, + "" + + " " + + " " + + " " + + " " + + "", + i -> { + i.startRecord("1"); + i.literal("litA", ""); + i.literal("litB", "a"); + i.literal("litA", "b"); + i.endRecord(); + }, + o -> { + o.get().startRecord("1"); + o.get().literal("concat", ", a, b"); + o.get().endRecord(); + } + ); } @Test public void shouldReverseConcatenationIfReverseIsTrue() { - metamorph = InlineMorph.in(this) - .with("") - .with(" ") - .with(" ") - .with(" ") - .with(" ") - .with("") - .createConnectedTo(receiver); - - metamorph.startRecord("1"); - metamorph.literal("litA", "1"); - metamorph.literal("litB", "2"); - metamorph.literal("litA", "3"); - metamorph.endRecord(); - - final InOrder ordered = inOrder(receiver); - ordered.verify(receiver).startRecord("1"); - ordered.verify(receiver).literal("concat", "3, 2, 1"); - ordered.verify(receiver).endRecord(); - ordered.verifyNoMoreInteractions(); + assertMorph(receiver, + "" + + " " + + " " + + " " + + " " + + "", + i -> { + i.startRecord("1"); + i.literal("litA", "1"); + i.literal("litB", "2"); + i.literal("litA", "3"); + i.endRecord(); + }, + o -> { + o.get().startRecord("1"); + o.get().literal("concat", "3, 2, 1"); + o.get().endRecord(); + } + ); } @Test public void prefixAndPostfixShouldWorkAsNormalIfReverseIsTrue() { - metamorph = InlineMorph.in(this) - .with("") - .with(" ") - .with(" ") - .with(" ") - .with(" ") - .with("") - .createConnectedTo(receiver); - - metamorph.startRecord("1"); - metamorph.literal("litA", "1"); - metamorph.literal("litB", "2"); - metamorph.literal("litA", "3"); - metamorph.endRecord(); - - final InOrder ordered = inOrder(receiver); - ordered.verify(receiver).startRecord("1"); - ordered.verify(receiver).literal("concat", "(3, 2, 1)"); - ordered.verify(receiver).endRecord(); - ordered.verifyNoMoreInteractions(); + assertMorph(receiver, + "" + + " " + + " " + + " " + + " " + + "", + i -> { + i.startRecord("1"); + i.literal("litA", "1"); + i.literal("litB", "2"); + i.literal("litA", "3"); + i.endRecord(); + }, + o -> { + o.get().startRecord("1"); + o.get().literal("concat", "(3, 2, 1)"); + o.get().endRecord(); + } + ); } @Test public void issue187_shouldUseEmptyDelimiterAsDefault() { - metamorph = InlineMorph.in(this) - .with("") - .with(" ") - .with(" ") - .with(" ") - .with("") - .createConnectedTo(receiver); - - metamorph.startRecord("1"); - metamorph.literal("lit", "data1"); - metamorph.literal("lit", "data2"); - metamorph.endRecord(); - - final InOrder ordered = inOrder(receiver); - ordered.verify(receiver).startRecord("1"); - ordered.verify(receiver).literal("concat", "data1data2"); - ordered.verify(receiver).endRecord(); - ordered.verifyNoMoreInteractions(); + assertMorph(receiver, + "" + + " " + + " " + + " " + + "", + i -> { + i.startRecord("1"); + i.literal("lit", "data1"); + i.literal("lit", "data2"); + i.endRecord(); + }, + o -> { + o.get().startRecord("1"); + o.get().literal("concat", "data1data2"); + o.get().endRecord(); + } + ); } } diff --git a/metamorph/src/test/java/org/metafacture/metamorph/collectors/EntityTest.java b/metamorph/src/test/java/org/metafacture/metamorph/collectors/EntityTest.java index 2b17df6a6..4556f7c22 100644 --- a/metamorph/src/test/java/org/metafacture/metamorph/collectors/EntityTest.java +++ b/metamorph/src/test/java/org/metafacture/metamorph/collectors/EntityTest.java @@ -16,17 +16,12 @@ package org.metafacture.metamorph.collectors; -import static org.mockito.Mockito.inOrder; -import static org.mockito.Mockito.times; -import static org.mockito.Mockito.verifyNoMoreInteractions; +import static org.metafacture.metamorph.TestHelpers.assertMorph; import org.junit.Rule; import org.junit.Test; import org.metafacture.framework.StreamReceiver; import org.metafacture.metamorph.Entity; -import org.metafacture.metamorph.InlineMorph; -import org.metafacture.metamorph.Metamorph; -import org.mockito.InOrder; import org.mockito.Mock; import org.mockito.junit.MockitoJUnit; import org.mockito.junit.MockitoRule; @@ -45,509 +40,506 @@ public final class EntityTest { @Mock private StreamReceiver receiver; - private Metamorph metamorph; - @Test public void shouldEmitEntities() { - metamorph = InlineMorph.in(this) - .with("") - .with(" ") - .with(" ") - .with(" ") - .with(" ") - .with("") - .createConnectedTo(receiver); - - metamorph.startRecord("1x"); - metamorph.literal("data1", "a1"); - metamorph.literal("data1", "a2"); - metamorph.literal("data2", "b"); - metamorph.endRecord(); - metamorph.startRecord("2x"); - metamorph.literal("data2", "c"); - metamorph.literal("data1", "d"); - metamorph.endRecord(); - - final InOrder ordered = inOrder(receiver); - ordered.verify(receiver).startRecord("1x"); - ordered.verify(receiver).startEntity("entity"); - ordered.verify(receiver).literal("l1", "a1"); - ordered.verify(receiver).literal("l1", "a2"); - ordered.verify(receiver).literal("l2", "b"); - ordered.verify(receiver).endEntity(); - ordered.verify(receiver).endRecord(); - ordered.verify(receiver).startRecord("2x"); - ordered.verify(receiver).startEntity("entity"); - ordered.verify(receiver).literal("l2", "c"); - ordered.verify(receiver).literal("l1", "d"); - ordered.verify(receiver).endEntity(); - ordered.verify(receiver).endRecord(); - ordered.verifyNoMoreInteractions(); + assertMorph(receiver, + "" + + " " + + " " + + " " + + " " + + "", + i -> { + i.startRecord("1x"); + i.literal("data1", "a1"); + i.literal("data1", "a2"); + i.literal("data2", "b"); + i.endRecord(); + i.startRecord("2x"); + i.literal("data2", "c"); + i.literal("data1", "d"); + i.endRecord(); + }, + o -> { + o.get().startRecord("1x"); + o.get().startEntity("entity"); + o.get().literal("l1", "a1"); + o.get().literal("l1", "a2"); + o.get().literal("l2", "b"); + o.get().endEntity(); + o.get().endRecord(); + o.get().startRecord("2x"); + o.get().startEntity("entity"); + o.get().literal("l2", "c"); + o.get().literal("l1", "d"); + o.get().endEntity(); + o.get().endRecord(); + } + ); } @Test public void shouldEmitEntityOnFlushEvent() { - metamorph = InlineMorph.in(this) - .with("") - .with(" ") - .with(" ") - .with(" ") - .with(" ") - .with("") - .createConnectedTo(receiver); - - metamorph.startRecord("1"); - metamorph.literal("d1", "a"); - metamorph.literal("d1", "b"); - metamorph.literal("d2", "c"); - metamorph.endRecord(); - metamorph.startRecord("2"); - metamorph.literal("d2", "c"); - metamorph.endRecord(); - - final InOrder ordered = inOrder(receiver); - ordered.verify(receiver).startRecord("1"); - ordered.verify(receiver).startEntity("entity"); - ordered.verify(receiver).literal("l1", "a"); - ordered.verify(receiver).literal("l1", "b"); - ordered.verify(receiver).literal("l2", "c"); - ordered.verify(receiver).endEntity(); - ordered.verify(receiver).endRecord(); - ordered.verify(receiver).startRecord("2"); - ordered.verify(receiver).startEntity("entity"); - ordered.verify(receiver).literal("l2", "c"); - ordered.verify(receiver).endEntity(); - ordered.verify(receiver).endRecord(); - ordered.verifyNoMoreInteractions(); + assertMorph(receiver, + "" + + " " + + " " + + " " + + " " + + "", + i -> { + i.startRecord("1"); + i.literal("d1", "a"); + i.literal("d1", "b"); + i.literal("d2", "c"); + i.endRecord(); + i.startRecord("2"); + i.literal("d2", "c"); + i.endRecord(); + }, + o -> { + o.get().startRecord("1"); + o.get().startEntity("entity"); + o.get().literal("l1", "a"); + o.get().literal("l1", "b"); + o.get().literal("l2", "c"); + o.get().endEntity(); + o.get().endRecord(); + o.get().startRecord("2"); + o.get().startEntity("entity"); + o.get().literal("l2", "c"); + o.get().endEntity(); + o.get().endRecord(); + } + ); } @Test public void shouldNotEmitEntityOnFlushEventIfIncomplete() { - metamorph = InlineMorph.in(this) - .with("") - .with(" ") - .with(" ") - .with(" ") - .with(" ") - .with("") - .createConnectedTo(receiver); - - metamorph.startRecord("1"); - metamorph.literal("d1", "a"); - metamorph.literal("d1", "b"); - metamorph.literal("d2", "c"); - metamorph.endRecord(); - metamorph.startRecord("2"); - metamorph.literal("d2", "c"); - metamorph.endRecord(); - - final InOrder ordered = inOrder(receiver); - ordered.verify(receiver).startRecord("1"); - ordered.verify(receiver).startEntity("entity"); - ordered.verify(receiver).literal("l1", "a"); - ordered.verify(receiver).literal("l1", "b"); - ordered.verify(receiver).literal("l2", "c"); - ordered.verify(receiver).endEntity(); - ordered.verify(receiver).endRecord(); - ordered.verify(receiver).startRecord("2"); - ordered.verify(receiver).endRecord(); - ordered.verifyNoMoreInteractions(); - verifyNoMoreInteractions(receiver); + assertMorph(receiver, + "" + + " " + + " " + + " " + + " " + + "", + i -> { + i.startRecord("1"); + i.literal("d1", "a"); + i.literal("d1", "b"); + i.literal("d2", "c"); + i.endRecord(); + i.startRecord("2"); + i.literal("d2", "c"); + i.endRecord(); + }, + o -> { + o.get().startRecord("1"); + o.get().startEntity("entity"); + o.get().literal("l1", "a"); + o.get().literal("l1", "b"); + o.get().literal("l2", "c"); + o.get().endEntity(); + o.get().endRecord(); + o.get().startRecord("2"); + o.get().endRecord(); + } + ); } @Test public void shouldEmitEntityOnEachFlushEvent() { - metamorph = InlineMorph.in(this) - .with("") - .with(" ") - .with(" ") - .with(" ") - .with(" ") - .with(" ") - .with(" ") - .with("") - .createConnectedTo(receiver); - - metamorph.startRecord("1"); - metamorph.startEntity("E"); - metamorph.literal("d1", "a"); - metamorph.literal("d2", "b"); - metamorph.endEntity(); - metamorph.startEntity("E"); - metamorph.literal("d1", "c"); - metamorph.literal("d2", "d"); - metamorph.endEntity(); - metamorph.endRecord(); - - final InOrder ordered = inOrder(receiver); - ordered.verify(receiver).startRecord("1"); - ordered.verify(receiver).startEntity("entity"); - ordered.verify(receiver).literal("l1", "a"); - ordered.verify(receiver).literal("l2", "b"); - ordered.verify(receiver).endEntity(); - ordered.verify(receiver).startEntity("entity"); - ordered.verify(receiver).literal("l1", "c"); - ordered.verify(receiver).literal("l2", "d"); - ordered.verify(receiver).endEntity(); - ordered.verify(receiver).endRecord(); - ordered.verifyNoMoreInteractions(); + assertMorph(receiver, + "" + + " " + + " " + + " " + + " " + + " " + + " " + + "", + i -> { + i.startRecord("1"); + i.startEntity("E"); + i.literal("d1", "a"); + i.literal("d2", "b"); + i.endEntity(); + i.startEntity("E"); + i.literal("d1", "c"); + i.literal("d2", "d"); + i.endEntity(); + i.endRecord(); + }, + o -> { + o.get().startRecord("1"); + o.get().startEntity("entity"); + o.get().literal("l1", "a"); + o.get().literal("l2", "b"); + o.get().endEntity(); + o.get().startEntity("entity"); + o.get().literal("l1", "c"); + o.get().literal("l2", "d"); + o.get().endEntity(); + o.get().endRecord(); + } + ); } @Test public void shouldSupportNestedEntities() { - metamorph = InlineMorph.in(this) - .with("") - .with(" ") - .with(" ") - .with(" ") - .with(" ") - .with(" ") - .with(" ") - .with(" ") - .with(" ") - .with("") - .createConnectedTo(receiver); - - metamorph.startRecord("1"); - metamorph.literal("d1", "a"); - metamorph.literal("d2", "b"); - metamorph.literal("d3", "c"); - metamorph.endRecord(); - metamorph.startRecord("2"); - metamorph.literal("d1", "d"); - metamorph.literal("d2", "e"); - metamorph.literal("d3", "f"); - metamorph.endRecord(); - metamorph.startRecord("3"); - metamorph.literal("d1", "a"); - metamorph.literal("d3", "c"); - metamorph.endRecord(); - - final InOrder ordered = inOrder(receiver); - ordered.verify(receiver).startRecord("1"); - ordered.verify(receiver).startEntity("e1"); - ordered.verify(receiver).literal("d1", "a"); - ordered.verify(receiver).literal("d2", "b"); - ordered.verify(receiver).startEntity("e2"); - ordered.verify(receiver).literal("d3", "c"); - ordered.verify(receiver, times(2)).endEntity(); - ordered.verify(receiver).endRecord(); - ordered.verify(receiver).startRecord("2"); - ordered.verify(receiver).startEntity("e1"); - ordered.verify(receiver).literal("d1", "d"); - ordered.verify(receiver).literal("d2", "e"); - ordered.verify(receiver).startEntity("e2"); - ordered.verify(receiver).literal("d3", "f"); - ordered.verify(receiver, times(2)).endEntity(); - ordered.verify(receiver).endRecord(); - ordered.verify(receiver).startRecord("3"); - ordered.verify(receiver).startEntity("e1"); - ordered.verify(receiver).literal("d1", "a"); - ordered.verify(receiver).startEntity("e2"); - ordered.verify(receiver).literal("d3", "c"); - ordered.verify(receiver, times(2)).endEntity(); - ordered.verify(receiver).endRecord(); - ordered.verifyNoMoreInteractions(); + assertMorph(receiver, + "" + + " " + + " " + + " " + + " " + + " " + + " " + + " " + + " " + + "", + i -> { + i.startRecord("1"); + i.literal("d1", "a"); + i.literal("d2", "b"); + i.literal("d3", "c"); + i.endRecord(); + i.startRecord("2"); + i.literal("d1", "d"); + i.literal("d2", "e"); + i.literal("d3", "f"); + i.endRecord(); + i.startRecord("3"); + i.literal("d1", "a"); + i.literal("d3", "c"); + i.endRecord(); + }, + (o, f) -> { + o.get().startRecord("1"); + o.get().startEntity("e1"); + o.get().literal("d1", "a"); + o.get().literal("d2", "b"); + o.get().startEntity("e2"); + o.get().literal("d3", "c"); + f.apply(2).endEntity(); + o.get().endRecord(); + o.get().startRecord("2"); + o.get().startEntity("e1"); + o.get().literal("d1", "d"); + o.get().literal("d2", "e"); + o.get().startEntity("e2"); + o.get().literal("d3", "f"); + f.apply(2).endEntity(); + o.get().endRecord(); + o.get().startRecord("3"); + o.get().startEntity("e1"); + o.get().literal("d1", "a"); + o.get().startEntity("e2"); + o.get().literal("d3", "c"); + f.apply(2).endEntity(); + o.get().endRecord(); + } + ); } @Test public void shouldSupportMultipleNestedEntities() { - metamorph = InlineMorph.in(this) - .with("") - .with(" ") - .with(" ") - .with(" ") - .with(" ") - .with(" ") - .with(" ") - .with(" ") - .with(" ") - .with(" ") - .with(" ") - .with("") - .createConnectedTo(receiver); - - metamorph.startRecord("1x"); - metamorph.startEntity("E"); - metamorph.literal("d1", "a"); - metamorph.literal("d2", "b"); - metamorph.endEntity(); - metamorph.startEntity("E"); - metamorph.literal("d1", "x"); - metamorph.endEntity(); - metamorph.startEntity("E"); - metamorph.literal("d1", "c"); - metamorph.literal("d2", "d"); - metamorph.endEntity(); - metamorph.literal("d", "c"); - metamorph.endRecord(); - metamorph.startRecord("2x"); - metamorph.literal("d", "c"); - metamorph.endRecord(); - - final InOrder ordered = inOrder(receiver); - ordered.verify(receiver).startRecord("1x"); - ordered.verify(receiver).startEntity("uber"); - ordered.verify(receiver).startEntity("unter"); - ordered.verify(receiver).literal("l", "a"); - ordered.verify(receiver).literal("l", "b"); - ordered.verify(receiver).endEntity(); - ordered.verify(receiver).startEntity("unter"); - ordered.verify(receiver).literal("l", "c"); - ordered.verify(receiver).literal("l", "d"); - ordered.verify(receiver).endEntity(); - ordered.verify(receiver).literal("l", "c"); - ordered.verify(receiver).endEntity(); - ordered.verify(receiver).endRecord(); - ordered.verify(receiver).startRecord("2x"); - ordered.verify(receiver).startEntity("uber"); - ordered.verify(receiver).literal("l", "c"); - ordered.verify(receiver).endEntity(); - ordered.verify(receiver).endRecord(); - ordered.verifyNoMoreInteractions(); + assertMorph(receiver, + "" + + " " + + " " + + " " + + " " + + " " + + " " + + " " + + " " + + " " + + " " + + "", + i -> { + i.startRecord("1x"); + i.startEntity("E"); + i.literal("d1", "a"); + i.literal("d2", "b"); + i.endEntity(); + i.startEntity("E"); + i.literal("d1", "x"); + i.endEntity(); + i.startEntity("E"); + i.literal("d1", "c"); + i.literal("d2", "d"); + i.endEntity(); + i.literal("d", "c"); + i.endRecord(); + i.startRecord("2x"); + i.literal("d", "c"); + i.endRecord(); + }, + o -> { + o.get().startRecord("1x"); + o.get().startEntity("uber"); + o.get().startEntity("unter"); + o.get().literal("l", "a"); + o.get().literal("l", "b"); + o.get().endEntity(); + o.get().startEntity("unter"); + o.get().literal("l", "c"); + o.get().literal("l", "d"); + o.get().endEntity(); + o.get().literal("l", "c"); + o.get().endEntity(); + o.get().endRecord(); + o.get().startRecord("2x"); + o.get().startEntity("uber"); + o.get().literal("l", "c"); + o.get().endEntity(); + o.get().endRecord(); + } + ); } @Test public void shouldSupportDeeplyNestedEnities() { - metamorph = InlineMorph.in(this) - .with("") - .with(" ") - .with(" ") - .with(" ") - .with(" ") - .with(" ") - .with(" ") - .with(" ") - .with(" ") - .with(" ") - .with(" ") - .with(" ") - .with("") - .createConnectedTo(receiver); - - metamorph.startRecord("1x"); - metamorph.literal("1", "a"); - metamorph.literal("2", "b"); - metamorph.literal("4", "c"); - metamorph.endRecord(); - - final InOrder ordered = inOrder(receiver); - ordered.verify(receiver).startRecord("1x"); - ordered.verify(receiver).startEntity("1"); - ordered.verify(receiver).literal("1", "a"); - ordered.verify(receiver).startEntity("2"); - ordered.verify(receiver).literal("2", "b"); - ordered.verify(receiver).startEntity("3"); - ordered.verify(receiver).startEntity("4"); - ordered.verify(receiver).literal("4", "c"); - ordered.verify(receiver, times(4)).endEntity(); - ordered.verify(receiver).endRecord(); - ordered.verifyNoMoreInteractions(); + assertMorph(receiver, + "" + + " " + + " " + + " " + + " " + + " " + + " " + + " " + + " " + + " " + + " " + + " " + + "", + i -> { + i.startRecord("1x"); + i.literal("1", "a"); + i.literal("2", "b"); + i.literal("4", "c"); + i.endRecord(); + }, + (o, f) -> { + o.get().startRecord("1x"); + o.get().startEntity("1"); + o.get().literal("1", "a"); + o.get().startEntity("2"); + o.get().literal("2", "b"); + o.get().startEntity("3"); + o.get().startEntity("4"); + o.get().literal("4", "c"); + f.apply(4).endEntity(); + o.get().endRecord(); + } + ); } @Test public void shouldGetNameFromDataInEntityName() { - metamorph = InlineMorph.in(this) - .with("") - .with(" ") - .with(" ") - .with(" ") - .with(" ") - .with(" ") - .with(" ") - .with(" ") - .with(" ") - .with(" ") - .with("") - .createConnectedTo(receiver); - - metamorph.startRecord("1x"); - metamorph.literal("data1", "a1"); - metamorph.literal("data1", "a2"); - metamorph.literal("data2", "b"); - metamorph.endRecord(); - metamorph.startRecord("2x"); - metamorph.literal("data2", "c"); - metamorph.literal("data1", "d"); - metamorph.endRecord(); - - final InOrder ordered = inOrder(receiver); - ordered.verify(receiver).startRecord("1x"); - ordered.verify(receiver).startEntity("entity:a2"); - ordered.verify(receiver).literal("l1", "a1"); - ordered.verify(receiver).literal("l1", "a2"); - ordered.verify(receiver).literal("l2", "b"); - ordered.verify(receiver).endEntity(); - ordered.verify(receiver).endRecord(); - ordered.verify(receiver).startRecord("2x"); - ordered.verify(receiver).startEntity("entity:d"); - ordered.verify(receiver).literal("l2", "c"); - ordered.verify(receiver).literal("l1", "d"); - ordered.verify(receiver).endEntity(); - ordered.verify(receiver).endRecord(); - ordered.verifyNoMoreInteractions(); + assertMorph(receiver, + "" + + " " + + " " + + " " + + " " + + " " + + " " + + " " + + " " + + " " + + "", + i -> { + i.startRecord("1x"); + i.literal("data1", "a1"); + i.literal("data1", "a2"); + i.literal("data2", "b"); + i.endRecord(); + i.startRecord("2x"); + i.literal("data2", "c"); + i.literal("data1", "d"); + i.endRecord(); + }, + o -> { + o.get().startRecord("1x"); + o.get().startEntity("entity:a2"); + o.get().literal("l1", "a1"); + o.get().literal("l1", "a2"); + o.get().literal("l2", "b"); + o.get().endEntity(); + o.get().endRecord(); + o.get().startRecord("2x"); + o.get().startEntity("entity:d"); + o.get().literal("l2", "c"); + o.get().literal("l1", "d"); + o.get().endEntity(); + o.get().endRecord(); + } + ); } @Test public void shouldGetNameFromCollectInEntityName() { - metamorph = InlineMorph.in(this) - .with("") - .with(" ") - .with(" ") - .with(" ") - .with(" ") - .with(" ") - .with(" ") - .with(" ") - .with(" ") - .with(" ") - .with(" ") - .with("") - .createConnectedTo(receiver); - - metamorph.startRecord("1x"); - metamorph.literal("data1", "a1"); - metamorph.literal("data1", "a2"); - metamorph.literal("data2", "b"); - metamorph.endRecord(); - metamorph.startRecord("2x"); - metamorph.literal("data2", "c"); - metamorph.literal("data1", "d"); - metamorph.endRecord(); - - final InOrder ordered = inOrder(receiver); - ordered.verify(receiver).startRecord("1x"); - ordered.verify(receiver).startEntity("entity:a2,b"); - ordered.verify(receiver).literal("l1", "a1"); - ordered.verify(receiver).literal("l1", "a2"); - ordered.verify(receiver).literal("l2", "b"); - ordered.verify(receiver).endEntity(); - ordered.verify(receiver).endRecord(); - ordered.verify(receiver).startRecord("2x"); - ordered.verify(receiver).startEntity("entity:d,c"); - ordered.verify(receiver).literal("l2", "c"); - ordered.verify(receiver).literal("l1", "d"); - ordered.verify(receiver).endEntity(); - ordered.verify(receiver).endRecord(); - ordered.verifyNoMoreInteractions(); + assertMorph(receiver, + "" + + " " + + " " + + " " + + " " + + " " + + " " + + " " + + " " + + " " + + " " + + "", + i -> { + i.startRecord("1x"); + i.literal("data1", "a1"); + i.literal("data1", "a2"); + i.literal("data2", "b"); + i.endRecord(); + i.startRecord("2x"); + i.literal("data2", "c"); + i.literal("data1", "d"); + i.endRecord(); + }, + o -> { + o.get().startRecord("1x"); + o.get().startEntity("entity:a2,b"); + o.get().literal("l1", "a1"); + o.get().literal("l1", "a2"); + o.get().literal("l2", "b"); + o.get().endEntity(); + o.get().endRecord(); + o.get().startRecord("2x"); + o.get().startEntity("entity:d,c"); + o.get().literal("l2", "c"); + o.get().literal("l1", "d"); + o.get().endEntity(); + o.get().endRecord(); + } + ); } @Test public void shouldResetNameToNameAttribute() { - metamorph = InlineMorph.in(this) - .with("") - .with(" ") - .with(" ") - .with(" ") - .with(" ") - .with(" ") - .with(" ") - .with("") - .createConnectedTo(receiver); - - metamorph.startRecord("1x"); - metamorph.literal("data1", "a"); - metamorph.literal("data3", "dynamicName"); - metamorph.endRecord(); - metamorph.startRecord("2x"); - metamorph.literal("data1", "b"); - metamorph.endRecord(); - - final InOrder ordered = inOrder(receiver); - ordered.verify(receiver).startRecord("1x"); - ordered.verify(receiver).startEntity("dynamicName"); - ordered.verify(receiver).literal("l1", "a"); - ordered.verify(receiver).endEntity(); - ordered.verify(receiver).endRecord(); - ordered.verify(receiver).startRecord("2x"); - ordered.verify(receiver).startEntity("defaultName"); - ordered.verify(receiver).literal("l1", "b"); - ordered.verify(receiver).endEntity(); - ordered.verify(receiver).endRecord(); - ordered.verifyNoMoreInteractions(); + assertMorph(receiver, + "" + + " " + + " " + + " " + + " " + + " " + + " " + + "", + i -> { + i.startRecord("1x"); + i.literal("data1", "a"); + i.literal("data3", "dynamicName"); + i.endRecord(); + i.startRecord("2x"); + i.literal("data1", "b"); + i.endRecord(); + }, + o -> { + o.get().startRecord("1x"); + o.get().startEntity("dynamicName"); + o.get().literal("l1", "a"); + o.get().endEntity(); + o.get().endRecord(); + o.get().startRecord("2x"); + o.get().startEntity("defaultName"); + o.get().literal("l1", "b"); + o.get().endEntity(); + o.get().endRecord(); + } + ); } @Test public void shouldEmitEmptyStringIfEntityNameIsNotSet() { - metamorph = InlineMorph.in(this) - .with("") - .with(" ") - .with(" ") - .with(" ") - .with("") - .createConnectedTo(receiver); - - metamorph.startRecord("1"); - metamorph.literal("in", "a"); - metamorph.endRecord(); - - final InOrder ordered = inOrder(receiver); - ordered.verify(receiver).startRecord("1"); - ordered.verify(receiver).startEntity(""); - ordered.verify(receiver).literal("out", "a"); - ordered.verify(receiver).endEntity(); - ordered.verify(receiver).endRecord(); - ordered.verifyNoMoreInteractions(); + assertMorph(receiver, + "" + + " " + + " " + + " " + + "", + i -> { + i.startRecord("1"); + i.literal("in", "a"); + i.endRecord(); + }, + o -> { + o.get().startRecord("1"); + o.get().startEntity(""); + o.get().literal("out", "a"); + o.get().endEntity(); + o.get().endRecord(); + } + ); } @Test public void shouldEmitEntityContentsAgainIfResetIsFalse() { - metamorph = InlineMorph.in(this) - .with("") - .with(" ") - .with(" ") - .with(" ") - .with(" ") - .with("") - .createConnectedTo(receiver); - - metamorph.startRecord("1"); - metamorph.literal("lit1", "const"); - metamorph.literal("lit2", "1"); - metamorph.literal("lit2", "2"); - metamorph.endRecord(); - - final InOrder ordered = inOrder(receiver); - ordered.verify(receiver).startRecord("1"); - ordered.verify(receiver).startEntity("entity"); - ordered.verify(receiver).literal("lit1", "const"); - ordered.verify(receiver).literal("lit2", "1"); - ordered.verify(receiver).endEntity(); - ordered.verify(receiver).startEntity("entity"); - ordered.verify(receiver).literal("lit1", "const"); - ordered.verify(receiver).literal("lit2", "1"); - ordered.verify(receiver).literal("lit2", "2"); - ordered.verify(receiver).endEntity(); - ordered.verify(receiver).endRecord(); - ordered.verifyNoMoreInteractions(); + assertMorph(receiver, + "" + + " " + + " " + + " " + + " " + + "", + i -> { + i.startRecord("1"); + i.literal("lit1", "const"); + i.literal("lit2", "1"); + i.literal("lit2", "2"); + i.endRecord(); + }, + o -> { + o.get().startRecord("1"); + o.get().startEntity("entity"); + o.get().literal("lit1", "const"); + o.get().literal("lit2", "1"); + o.get().endEntity(); + o.get().startEntity("entity"); + o.get().literal("lit1", "const"); + o.get().literal("lit2", "1"); + o.get().literal("lit2", "2"); + o.get().endEntity(); + o.get().endRecord(); + } + ); } @Test public void shouldNotEmitEntityContentsAgainIfResetIsTrue() { - metamorph = InlineMorph.in(this) - .with("") - .with(" ") - .with(" ") - .with(" ") - .with(" ") - .with("") - .createConnectedTo(receiver); - - metamorph.startRecord("1"); - metamorph.literal("lit1", "const"); - metamorph.literal("lit2", "1"); - metamorph.literal("lit2", "2"); - metamorph.endRecord(); - - final InOrder ordered = inOrder(receiver); - ordered.verify(receiver).startRecord("1"); - ordered.verify(receiver).startEntity("entity"); - ordered.verify(receiver).literal("lit1", "const"); - ordered.verify(receiver).literal("lit2", "1"); - ordered.verify(receiver).endEntity(); - ordered.verify(receiver).endRecord(); - ordered.verifyNoMoreInteractions(); + assertMorph(receiver, + "" + + " " + + " " + + " " + + " " + + "", + i -> { + i.startRecord("1"); + i.literal("lit1", "const"); + i.literal("lit2", "1"); + i.literal("lit2", "2"); + i.endRecord(); + }, + o -> { + o.get().startRecord("1"); + o.get().startEntity("entity"); + o.get().literal("lit1", "const"); + o.get().literal("lit2", "1"); + o.get().endEntity(); + o.get().endRecord(); + } + ); } } diff --git a/metamorph/src/test/java/org/metafacture/metamorph/collectors/EqualsFilterTest.java b/metamorph/src/test/java/org/metafacture/metamorph/collectors/EqualsFilterTest.java index 5d366ffb1..e92b33cf0 100644 --- a/metamorph/src/test/java/org/metafacture/metamorph/collectors/EqualsFilterTest.java +++ b/metamorph/src/test/java/org/metafacture/metamorph/collectors/EqualsFilterTest.java @@ -16,18 +16,12 @@ package org.metafacture.metamorph.collectors; -import static org.mockito.ArgumentMatchers.any; -import static org.mockito.ArgumentMatchers.eq; -import static org.mockito.Mockito.inOrder; -import static org.mockito.Mockito.never; -import static org.mockito.Mockito.verifyNoMoreInteractions; +import static org.metafacture.metamorph.TestHelpers.assertMorph; import org.junit.Rule; import org.junit.Test; import org.metafacture.framework.StreamReceiver; -import org.metafacture.metamorph.InlineMorph; -import org.metafacture.metamorph.Metamorph; -import org.mockito.InOrder; +import org.mockito.ArgumentMatchers; import org.mockito.Mock; import org.mockito.junit.MockitoJUnit; import org.mockito.junit.MockitoRule; @@ -46,274 +40,270 @@ public final class EqualsFilterTest { @Mock private StreamReceiver receiver; - private Metamorph metamorph; - @Test public void shouldEmitValueIfAllReceivedValuesAreEqual() { - metamorph = InlineMorph.in(this) - .with("") - .with(" ") - .with(" ") - .with(" ") - .with(" ") - .with(" ") - .with("") - .createConnectedTo(receiver); - - metamorph.startRecord("1"); - metamorph.literal("data1", "a"); - metamorph.literal("data2", "a"); - metamorph.literal("data3", "a"); - metamorph.endRecord(); - - final InOrder ordered = inOrder(receiver); - ordered.verify(receiver).startRecord("1"); - ordered.verify(receiver).literal("equalsFiltered", "a"); - ordered.verify(receiver).endRecord(); - ordered.verifyNoMoreInteractions(); + assertMorph(receiver, + "" + + " " + + " " + + " " + + " " + + " " + + "", + i -> { + i.startRecord("1"); + i.literal("data1", "a"); + i.literal("data2", "a"); + i.literal("data3", "a"); + i.endRecord(); + }, + o -> { + o.get().startRecord("1"); + o.get().literal("equalsFiltered", "a"); + o.get().endRecord(); + } + ); } @Test public void shouldEmitNothingIfReceivedValuesDiffer() { - metamorph = InlineMorph.in(this) - .with("") - .with(" ") - .with(" ") - .with(" ") - .with(" ") - .with(" ") - .with("") - .createConnectedTo(receiver); - - metamorph.startRecord("1"); - metamorph.literal("data1", "a"); - metamorph.literal("data2", "a"); - metamorph.literal("data3", "b"); - metamorph.endRecord(); - - final InOrder ordered = inOrder(receiver); - ordered.verify(receiver).startRecord("1"); - ordered.verify(receiver, never()).literal(eq("equalsFiltered"), any()); - ordered.verify(receiver).endRecord(); - ordered.verifyNoMoreInteractions(); + assertMorph(receiver, + "" + + " " + + " " + + " " + + " " + + " " + + "", + i -> { + i.startRecord("1"); + i.literal("data1", "a"); + i.literal("data2", "a"); + i.literal("data3", "b"); + i.endRecord(); + }, + (o, f) -> { + o.get().startRecord("1"); + f.apply(0).literal(ArgumentMatchers.eq("equalsFiltered"), ArgumentMatchers.any()); + o.get().endRecord(); + } + ); } @Test public void shouldFireIfOnlyASingleValueIsReceived() { - metamorph = InlineMorph.in(this) - .with("") - .with(" ") - .with(" ") - .with(" ") - .with("") - .createConnectedTo(receiver); - - metamorph.startRecord("1"); - metamorph.literal("data1", "a"); - metamorph.endRecord(); - - final InOrder ordered = inOrder(receiver); - ordered.verify(receiver).startRecord("1"); - ordered.verify(receiver).literal("equalsFiltered", "a"); - ordered.verify(receiver).endRecord(); - ordered.verifyNoMoreInteractions(); + assertMorph(receiver, + "" + + " " + + " " + + " " + + "", + i -> { + i.startRecord("1"); + i.literal("data1", "a"); + i.endRecord(); + }, + o -> { + o.get().startRecord("1"); + o.get().literal("equalsFiltered", "a"); + o.get().endRecord(); + } + ); } @Test public void shouldIgnoreLiteralsNotListedInStatements() { - metamorph = InlineMorph.in(this) - .with("") - .with(" ") - .with(" ") - .with(" ") - .with(" ") - .with("") - .createConnectedTo(receiver); - - metamorph.startRecord("1"); - metamorph.literal("data1", "a"); - metamorph.literal("data2", "a"); - metamorph.literal("data3", "b"); - metamorph.endRecord(); - - final InOrder ordered = inOrder(receiver); - ordered.verify(receiver).startRecord("1"); - ordered.verify(receiver).literal("equalsFiltered", "a"); - ordered.verify(receiver).endRecord(); - ordered.verifyNoMoreInteractions(); + assertMorph(receiver, + "" + + " " + + " " + + " " + + " " + + "", + i -> { + i.startRecord("1"); + i.literal("data1", "a"); + i.literal("data2", "a"); + i.literal("data3", "b"); + i.endRecord(); + }, + o -> { + o.get().startRecord("1"); + o.get().literal("equalsFiltered", "a"); + o.get().endRecord(); + } + ); } @Test public void shouldFireIfValuesInEntityAreEqual() { - metamorph = InlineMorph.in(this) - .with("") - .with(" ") - .with(" ") - .with(" ") - .with(" ") - .with(" ") - .with("") - .createConnectedTo(receiver); - - metamorph.startRecord("1"); - metamorph.startEntity("field"); - metamorph.literal("data1", "a"); - metamorph.literal("data2", "a"); - metamorph.literal("data3", "a"); - metamorph.endEntity(); - metamorph.endRecord(); - - final InOrder ordered = inOrder(receiver); - ordered.verify(receiver).startRecord("1"); - ordered.verify(receiver).literal("equalsFiltered", "a"); - ordered.verify(receiver).endRecord(); - ordered.verifyNoMoreInteractions(); + assertMorph(receiver, + "" + + " " + + " " + + " " + + " " + + " " + + "", + i -> { + i.startRecord("1"); + i.startEntity("field"); + i.literal("data1", "a"); + i.literal("data2", "a"); + i.literal("data3", "a"); + i.endEntity(); + i.endRecord(); + }, + o -> { + o.get().startRecord("1"); + o.get().literal("equalsFiltered", "a"); + o.get().endRecord(); + } + ); } @Test public void shouldNotFireIfValuesInEntityAreNotEqual() { - metamorph = InlineMorph.in(this) - .with("") - .with(" ") - .with(" ") - .with(" ") - .with(" ") - .with(" ") - .with("") - .createConnectedTo(receiver); - - metamorph.startRecord("1"); - metamorph.startEntity("field"); - metamorph.literal("data1", "a"); - metamorph.literal("data2", "a"); - metamorph.literal("data3", "b"); - metamorph.endEntity(); - metamorph.endRecord(); - - final InOrder ordered = inOrder(receiver); - ordered.verify(receiver).startRecord("1"); - ordered.verify(receiver).endRecord(); - ordered.verifyNoMoreInteractions(); + assertMorph(receiver, + "" + + " " + + " " + + " " + + " " + + " " + + "", + i -> { + i.startRecord("1"); + i.startEntity("field"); + i.literal("data1", "a"); + i.literal("data2", "a"); + i.literal("data3", "b"); + i.endEntity(); + i.endRecord(); + }, + o -> { + o.get().startRecord("1"); + o.get().endRecord(); + } + ); } @Test public void shouldFireIfLiteralsInEntitiesAreReceivedThatAreNotListedInStatements() { - metamorph = InlineMorph.in(this) - .with("") - .with(" ") - .with(" ") - .with(" ") - .with(" ") - .with("") - .createConnectedTo(receiver); - - metamorph.startRecord("1"); - metamorph.startEntity("field1"); - metamorph.literal("data1", "a"); - metamorph.endEntity(); - metamorph.endRecord(); - metamorph.startRecord("2"); - metamorph.startEntity("field1"); - metamorph.literal("data2", "a"); - metamorph.endEntity(); - metamorph.endRecord(); - metamorph.startRecord("3"); - metamorph.startEntity("field1"); - metamorph.literal("data1", "a"); - metamorph.literal("data2", "a"); - metamorph.endEntity(); - metamorph.endRecord(); - - final InOrder ordered = inOrder(receiver); - ordered.verify(receiver).startRecord("1"); - ordered.verify(receiver).endRecord(); - ordered.verify(receiver).startRecord("2"); - ordered.verify(receiver).endRecord(); - ordered.verify(receiver).startRecord("3"); - ordered.verify(receiver).literal("equalsFiltered", "a"); - ordered.verify(receiver).endRecord(); - ordered.verifyNoMoreInteractions(); + assertMorph(receiver, + "" + + " " + + " " + + " " + + " " + + "", + i -> { + i.startRecord("1"); + i.startEntity("field1"); + i.literal("data1", "a"); + i.endEntity(); + i.endRecord(); + i.startRecord("2"); + i.startEntity("field1"); + i.literal("data2", "a"); + i.endEntity(); + i.endRecord(); + i.startRecord("3"); + i.startEntity("field1"); + i.literal("data1", "a"); + i.literal("data2", "a"); + i.endEntity(); + i.endRecord(); + }, + o -> { + o.get().startRecord("1"); + o.get().endRecord(); + o.get().startRecord("2"); + o.get().endRecord(); + o.get().startRecord("3"); + o.get().literal("equalsFiltered", "a"); + o.get().endRecord(); + } + ); } @Test public void shouldFireOnFlush() { - metamorph = InlineMorph.in(this) - .with("") - .with(" ") - .with(" ") - .with(" ") - .with(" ") - .with("") - .createConnectedTo(receiver); - - metamorph.startRecord("1"); - metamorph.startEntity("field1"); - metamorph.literal("data1", "a"); - metamorph.endEntity(); - metamorph.endRecord(); - metamorph.startRecord("2"); - metamorph.startEntity("field1"); - metamorph.literal("data2", "a"); - metamorph.endEntity(); - metamorph.endRecord(); - metamorph.startRecord("3"); - metamorph.startEntity("field1"); - metamorph.literal("data1", "a"); - metamorph.literal("data2", "a"); - metamorph.endEntity(); - metamorph.endRecord(); - - final InOrder ordered = inOrder(receiver); - ordered.verify(receiver).startRecord("1"); - ordered.verify(receiver).endRecord(); - ordered.verify(receiver).startRecord("2"); - ordered.verify(receiver).literal("equalsFiltered", ""); - ordered.verify(receiver).endRecord(); - ordered.verify(receiver).startRecord("3"); - ordered.verify(receiver).literal("equalsFiltered", "a"); - ordered.verify(receiver).endRecord(); - ordered.verifyNoMoreInteractions(); - verifyNoMoreInteractions(receiver); + assertMorph(receiver, + "" + + " " + + " " + + " " + + " " + + "", + i -> { + i.startRecord("1"); + i.startEntity("field1"); + i.literal("data1", "a"); + i.endEntity(); + i.endRecord(); + i.startRecord("2"); + i.startEntity("field1"); + i.literal("data2", "a"); + i.endEntity(); + i.endRecord(); + i.startRecord("3"); + i.startEntity("field1"); + i.literal("data1", "a"); + i.literal("data2", "a"); + i.endEntity(); + i.endRecord(); + }, + o -> { + o.get().startRecord("1"); + o.get().endRecord(); + o.get().startRecord("2"); + o.get().literal("equalsFiltered", ""); + o.get().endRecord(); + o.get().startRecord("3"); + o.get().literal("equalsFiltered", "a"); + o.get().endRecord(); + } + ); } @Test public void shouldNotFireOnFlushIfIncomplete() { - metamorph = InlineMorph.in(this) - .with("") - .with(" ") - .with(" ") - .with(" ") - .with(" ") - .with("") - .createConnectedTo(receiver); - - metamorph.startRecord("1"); - metamorph.startEntity("field1"); - metamorph.literal("data1", "a"); - metamorph.endEntity(); - metamorph.endRecord(); - metamorph.startRecord("2"); - metamorph.startEntity("field1"); - metamorph.literal("data2", "a"); - metamorph.endEntity(); - metamorph.endRecord(); - metamorph.startRecord("3"); - metamorph.startEntity("field1"); - metamorph.literal("data1", "a"); - metamorph.literal("data2", "a"); - metamorph.endEntity(); - metamorph.endRecord(); - - final InOrder ordered = inOrder(receiver); - ordered.verify(receiver).startRecord("1"); - ordered.verify(receiver).endRecord(); - ordered.verify(receiver).startRecord("2"); - ordered.verify(receiver).endRecord(); - ordered.verify(receiver).startRecord("3"); - ordered.verify(receiver).literal("equalsFiltered", "a"); - ordered.verify(receiver).endRecord(); - ordered.verifyNoMoreInteractions(); - verifyNoMoreInteractions(receiver); + assertMorph(receiver, + "" + + " " + + " " + + " " + + " " + + "", + i -> { + i.startRecord("1"); + i.startEntity("field1"); + i.literal("data1", "a"); + i.endEntity(); + i.endRecord(); + i.startRecord("2"); + i.startEntity("field1"); + i.literal("data2", "a"); + i.endEntity(); + i.endRecord(); + i.startRecord("3"); + i.startEntity("field1"); + i.literal("data1", "a"); + i.literal("data2", "a"); + i.endEntity(); + i.endRecord(); + }, + o -> { + o.get().startRecord("1"); + o.get().endRecord(); + o.get().startRecord("2"); + o.get().endRecord(); + o.get().startRecord("3"); + o.get().literal("equalsFiltered", "a"); + o.get().endRecord(); + } + ); } } diff --git a/metamorph/src/test/java/org/metafacture/metamorph/collectors/GroupTest.java b/metamorph/src/test/java/org/metafacture/metamorph/collectors/GroupTest.java index 15034673a..8a40704f1 100644 --- a/metamorph/src/test/java/org/metafacture/metamorph/collectors/GroupTest.java +++ b/metamorph/src/test/java/org/metafacture/metamorph/collectors/GroupTest.java @@ -16,15 +16,11 @@ package org.metafacture.metamorph.collectors; -import static org.mockito.Mockito.inOrder; -import static org.mockito.Mockito.times; +import static org.metafacture.metamorph.TestHelpers.assertMorph; import org.junit.Rule; import org.junit.Test; import org.metafacture.framework.StreamReceiver; -import org.metafacture.metamorph.InlineMorph; -import org.metafacture.metamorph.Metamorph; -import org.mockito.InOrder; import org.mockito.Mock; import org.mockito.junit.MockitoJUnit; import org.mockito.junit.MockitoRule; @@ -43,32 +39,30 @@ public final class GroupTest { @Mock private StreamReceiver receiver; - private Metamorph metamorph; - @Test public void shouldGroupToOverwriteNameAndValueOfContaintStatements() { - metamorph = InlineMorph.in(this) - .with("") - .with(" ") - .with(" ") - .with(" ") - .with(" ") - .with(" ") - .with("") - .createConnectedTo(receiver); - - metamorph.startRecord("1"); - metamorph.literal("data1", "skjdfh"); - metamorph.literal("data2", "slkdjf"); - metamorph.literal("data3", "A"); - metamorph.endRecord(); - - final InOrder ordered = inOrder(receiver); - ordered.verify(receiver).startRecord("1"); - ordered.verify(receiver, times(2)).literal("group", "constant"); - ordered.verify(receiver).literal("data3", "A"); - ordered.verify(receiver).endRecord(); - ordered.verifyNoMoreInteractions(); + assertMorph(receiver, + "" + + " " + + " " + + " " + + " " + + " " + + "", + i -> { + i.startRecord("1"); + i.literal("data1", "skjdfh"); + i.literal("data2", "slkdjf"); + i.literal("data3", "A"); + i.endRecord(); + }, + (o, f) -> { + o.get().startRecord("1"); + f.apply(2).literal("group", "constant"); + o.get().literal("data3", "A"); + o.get().endRecord(); + } + ); } } diff --git a/metamorph/src/test/java/org/metafacture/metamorph/collectors/NoneTest.java b/metamorph/src/test/java/org/metafacture/metamorph/collectors/NoneTest.java index acac24740..31a4c58ac 100644 --- a/metamorph/src/test/java/org/metafacture/metamorph/collectors/NoneTest.java +++ b/metamorph/src/test/java/org/metafacture/metamorph/collectors/NoneTest.java @@ -16,15 +16,11 @@ package org.metafacture.metamorph.collectors; -import static org.mockito.Mockito.inOrder; -import static org.mockito.Mockito.times; +import static org.metafacture.metamorph.TestHelpers.assertMorph; import org.junit.Rule; import org.junit.Test; import org.metafacture.framework.StreamReceiver; -import org.metafacture.metamorph.InlineMorph; -import org.metafacture.metamorph.Metamorph; -import org.mockito.InOrder; import org.mockito.Mock; import org.mockito.junit.MockitoJUnit; import org.mockito.junit.MockitoRule; @@ -42,138 +38,136 @@ public final class NoneTest { @Mock private StreamReceiver receiver; - private Metamorph metamorph; - @Test public void shouldFireOnlyifNoElementFired() { - metamorph = InlineMorph.in(this) - .with("") - .with(" ") - .with(" ") - .with(" ") - .with(" ") - .with("") - .createConnectedTo(receiver); - - metamorph.startRecord("1"); - metamorph.literal("data1", "A"); - metamorph.endRecord(); - metamorph.startRecord("2"); - metamorph.literal("data2", "C"); - metamorph.endRecord(); - metamorph.startRecord("3"); - metamorph.literal("data3", "C"); - metamorph.endRecord(); - - final InOrder ordered = inOrder(receiver); - ordered.verify(receiver).startRecord("1"); - ordered.verify(receiver).endRecord(); - ordered.verify(receiver).startRecord("2"); - ordered.verify(receiver).endRecord(); - ordered.verify(receiver).startRecord("3"); - ordered.verify(receiver).literal("", "true"); - ordered.verify(receiver).endRecord(); - ordered.verifyNoMoreInteractions(); + assertMorph(receiver, + "" + + " " + + " " + + " " + + " " + + "", + i -> { + i.startRecord("1"); + i.literal("data1", "A"); + i.endRecord(); + i.startRecord("2"); + i.literal("data2", "C"); + i.endRecord(); + i.startRecord("3"); + i.literal("data3", "C"); + i.endRecord(); + }, + o -> { + o.get().startRecord("1"); + o.get().endRecord(); + o.get().startRecord("2"); + o.get().endRecord(); + o.get().startRecord("3"); + o.get().literal("", "true"); + o.get().endRecord(); + } + ); } @Test public void shouldSupportUserdefinedNameAndValue() { - metamorph = InlineMorph.in(this) - .with("") - .with(" ") - .with(" ") - .with(" ") - .with(" ") - .with("") - .createConnectedTo(receiver); - - metamorph.startRecord("1"); - metamorph.literal("data3", "A"); - metamorph.endRecord(); - - final InOrder ordered = inOrder(receiver); - ordered.verify(receiver).startRecord("1"); - ordered.verify(receiver).literal("NONE", "found none"); - ordered.verify(receiver).endRecord(); - ordered.verifyNoMoreInteractions(); + assertMorph(receiver, + "" + + " " + + " " + + " " + + " " + + "", + i -> { + i.startRecord("1"); + i.literal("data3", "A"); + i.endRecord(); + }, + o -> { + o.get().startRecord("1"); + o.get().literal("NONE", "found none"); + o.get().endRecord(); + } + ); } @Test public void shouldNotFireAgainIfFlushedTwoTimesAndResetIsFalse() { - metamorph = InlineMorph.in(this) - .with("") - .with(" ") - .with(" ") - .with(" ") - .with("") - .createConnectedTo(receiver); - - metamorph.startRecord("1"); - metamorph.startEntity("entity"); - metamorph.literal("data1", "A"); - metamorph.endEntity(); - metamorph.startEntity("entity"); - metamorph.literal("data1", "A"); - metamorph.endEntity(); - metamorph.endRecord(); - - final InOrder ordered = inOrder(receiver); - ordered.verify(receiver).startRecord("1"); - ordered.verify(receiver).literal("", "true"); - ordered.verify(receiver).endRecord(); - ordered.verifyNoMoreInteractions(); + assertMorph(receiver, + "" + + " " + + " " + + " " + + "", + i -> { + i.startRecord("1"); + i.startEntity("entity"); + i.literal("data1", "A"); + i.endEntity(); + i.startEntity("entity"); + i.literal("data1", "A"); + i.endEntity(); + i.endRecord(); + }, + o -> { + o.get().startRecord("1"); + o.get().literal("", "true"); + o.get().endRecord(); + } + ); } @Test public void shouldFireAgainIfFlushedTwoTimesAndTesetIsTrue() { - metamorph = InlineMorph.in(this) - .with("") - .with(" ") - .with(" ") - .with(" ") - .with("") - .createConnectedTo(receiver); - - metamorph.startRecord("1"); - metamorph.startEntity("entity"); - metamorph.literal("data1", "A"); - metamorph.endEntity(); - metamorph.startEntity("entity"); - metamorph.literal("data1", "A"); - metamorph.endEntity(); - metamorph.endRecord(); - - final InOrder ordered = inOrder(receiver); - ordered.verify(receiver).startRecord("1"); - ordered.verify(receiver, times(2)).literal("", "true"); - ordered.verify(receiver).endRecord(); - ordered.verifyNoMoreInteractions(); + assertMorph(receiver, + "" + + " " + + " " + + " " + + "", + i -> { + i.startRecord("1"); + i.startEntity("entity"); + i.literal("data1", "A"); + i.endEntity(); + i.startEntity("entity"); + i.literal("data1", "A"); + i.endEntity(); + i.endRecord(); + }, + (o, f) -> { + o.get().startRecord("1"); + f.apply(2).literal("", "true"); + o.get().endRecord(); + } + ); } @Test public void shouldResetWhenEntityChangesIfSameEntity() { - metamorph = InlineMorph.in(this) - .with("") - .with(" ") - .with(" ") - .with(" ") - .with("") - .createConnectedTo(receiver); - - metamorph.startRecord("1"); - metamorph.startEntity("entity"); - metamorph.literal("data2", "A"); - metamorph.endEntity(); - metamorph.startEntity("entity"); - metamorph.literal("data1", "A"); - metamorph.endEntity(); - metamorph.endRecord(); - - final InOrder ordered = inOrder(receiver); - ordered.verify(receiver).startRecord("1"); - ordered.verify(receiver).literal("", "true"); - ordered.verify(receiver).endRecord(); - ordered.verifyNoMoreInteractions(); + assertMorph(receiver, + "" + + " " + + " " + + " " + + "", + i -> { + i.startRecord("1"); + i.startEntity("entity"); + i.literal("data2", "A"); + i.endEntity(); + i.startEntity("entity"); + i.literal("data1", "A"); + i.endEntity(); + i.endRecord(); + }, + o -> { + o.get().startRecord("1"); + o.get().literal("", "true"); + o.get().endRecord(); + } + ); } } diff --git a/metamorph/src/test/java/org/metafacture/metamorph/collectors/RangeTest.java b/metamorph/src/test/java/org/metafacture/metamorph/collectors/RangeTest.java index b17381ca8..a706e0035 100644 --- a/metamorph/src/test/java/org/metafacture/metamorph/collectors/RangeTest.java +++ b/metamorph/src/test/java/org/metafacture/metamorph/collectors/RangeTest.java @@ -16,14 +16,11 @@ package org.metafacture.metamorph.collectors; -import static org.mockito.Mockito.inOrder; +import static org.metafacture.metamorph.TestHelpers.assertMorph; import org.junit.Rule; import org.junit.Test; import org.metafacture.framework.StreamReceiver; -import org.metafacture.metamorph.InlineMorph; -import org.metafacture.metamorph.Metamorph; -import org.mockito.InOrder; import org.mockito.Mock; import org.mockito.junit.MockitoJUnit; import org.mockito.junit.MockitoRule; @@ -41,171 +38,169 @@ public final class RangeTest { @Mock private StreamReceiver receiver; - private Metamorph metamorph; - @Test public void shouldOutputAllnNmbersbBetweenFirstAndLastInclusive() { - metamorph = InlineMorph.in(this) - .with("") - .with(" ") - .with(" ") - .with(" ") - .with(" ") - .with("") - .createConnectedTo(receiver); - - metamorph.startRecord("1"); - metamorph.literal("first", "1789"); - metamorph.literal("last", "1794"); - metamorph.endRecord(); - - final InOrder ordered = inOrder(receiver); - ordered.verify(receiver).startRecord("1"); - ordered.verify(receiver).literal("range", "1789"); - ordered.verify(receiver).literal("range", "1790"); - ordered.verify(receiver).literal("range", "1791"); - ordered.verify(receiver).literal("range", "1792"); - ordered.verify(receiver).literal("range", "1793"); - ordered.verify(receiver).literal("range", "1794"); - ordered.verify(receiver).endRecord(); - ordered.verifyNoMoreInteractions(); + assertMorph(receiver, + "" + + " " + + " " + + " " + + " " + + "", + i -> { + i.startRecord("1"); + i.literal("first", "1789"); + i.literal("last", "1794"); + i.endRecord(); + }, + o -> { + o.get().startRecord("1"); + o.get().literal("range", "1789"); + o.get().literal("range", "1790"); + o.get().literal("range", "1791"); + o.get().literal("range", "1792"); + o.get().literal("range", "1793"); + o.get().literal("range", "1794"); + o.get().endRecord(); + } + ); } @Test public void shouldOutputFirstIfLastEqualsFirst() { - metamorph = InlineMorph.in(this) - .with("") - .with(" ") - .with(" ") - .with(" ") - .with(" ") - .with("") - .createConnectedTo(receiver); - - metamorph.startRecord("1"); - metamorph.literal("first", "1989"); - metamorph.literal("last", "1989"); - metamorph.endRecord(); - - final InOrder ordered = inOrder(receiver); - ordered.verify(receiver).startRecord("1"); - ordered.verify(receiver).literal("range", "1989"); - ordered.verify(receiver).endRecord(); - ordered.verifyNoMoreInteractions(); + assertMorph(receiver, + "" + + " " + + " " + + " " + + " " + + "", + i -> { + i.startRecord("1"); + i.literal("first", "1989"); + i.literal("last", "1989"); + i.endRecord(); + }, + o -> { + o.get().startRecord("1"); + o.get().literal("range", "1989"); + o.get().endRecord(); + } + ); } @Test public void shouldOutputMultipleRanges() { - metamorph = InlineMorph.in(this) - .with("") - .with(" ") - .with(" ") - .with(" ") - .with(" ") - .with("") - .createConnectedTo(receiver); - - metamorph.startRecord("1"); - metamorph.literal("first", "1789"); - metamorph.literal("last", "1792"); - metamorph.literal("first", "1794"); - metamorph.literal("last", "1799"); - metamorph.endRecord(); - - final InOrder ordered = inOrder(receiver); - ordered.verify(receiver).startRecord("1"); - ordered.verify(receiver).literal("range", "1789"); - ordered.verify(receiver).literal("range", "1790"); - ordered.verify(receiver).literal("range", "1791"); - ordered.verify(receiver).literal("range", "1792"); - ordered.verify(receiver).literal("range", "1794"); - ordered.verify(receiver).literal("range", "1795"); - ordered.verify(receiver).literal("range", "1796"); - ordered.verify(receiver).literal("range", "1797"); - ordered.verify(receiver).literal("range", "1798"); - ordered.verify(receiver).literal("range", "1799"); - ordered.verify(receiver).endRecord(); - ordered.verifyNoMoreInteractions(); + assertMorph(receiver, + "" + + " " + + " " + + " " + + " " + + "", + i -> { + i.startRecord("1"); + i.literal("first", "1789"); + i.literal("last", "1792"); + i.literal("first", "1794"); + i.literal("last", "1799"); + i.endRecord(); + }, + o -> { + o.get().startRecord("1"); + o.get().literal("range", "1789"); + o.get().literal("range", "1790"); + o.get().literal("range", "1791"); + o.get().literal("range", "1792"); + o.get().literal("range", "1794"); + o.get().literal("range", "1795"); + o.get().literal("range", "1796"); + o.get().literal("range", "1797"); + o.get().literal("range", "1798"); + o.get().literal("range", "1799"); + o.get().endRecord(); + } + ); } @Test public void shouldRemoveDuplicateNumbersFromOverlappingRanges() { - metamorph = InlineMorph.in(this) - .with("") - .with(" ") - .with(" ") - .with(" ") - .with(" ") - .with("") - .createConnectedTo(receiver); - - metamorph.startRecord("1"); - metamorph.literal("first", "1789"); - metamorph.literal("last", "1792"); - metamorph.literal("first", "1790"); - metamorph.literal("last", "1791"); - metamorph.endRecord(); - - final InOrder ordered = inOrder(receiver); - ordered.verify(receiver).startRecord("1"); - ordered.verify(receiver).literal("range", "1789"); - ordered.verify(receiver).literal("range", "1790"); - ordered.verify(receiver).literal("range", "1791"); - ordered.verify(receiver).literal("range", "1792"); - ordered.verify(receiver).endRecord(); - ordered.verifyNoMoreInteractions(); + assertMorph(receiver, + "" + + " " + + " " + + " " + + " " + + "", + i -> { + i.startRecord("1"); + i.literal("first", "1789"); + i.literal("last", "1792"); + i.literal("first", "1790"); + i.literal("last", "1791"); + i.endRecord(); + }, + o -> { + o.get().startRecord("1"); + o.get().literal("range", "1789"); + o.get().literal("range", "1790"); + o.get().literal("range", "1791"); + o.get().literal("range", "1792"); + o.get().endRecord(); + } + ); } @Test public void shouldUseUserdefinedIncrement() { - metamorph = InlineMorph.in(this) - .with("") - .with(" ") - .with(" ") - .with(" ") - .with(" ") - .with("") - .createConnectedTo(receiver); - - metamorph.startRecord("1"); - metamorph.literal("first", "1789"); - metamorph.literal("last", "1799"); - metamorph.endRecord(); - - final InOrder ordered = inOrder(receiver); - ordered.verify(receiver).startRecord("1"); - ordered.verify(receiver).literal("range", "1789"); - ordered.verify(receiver).literal("range", "1792"); - ordered.verify(receiver).literal("range", "1795"); - ordered.verify(receiver).literal("range", "1798"); - ordered.verify(receiver).endRecord(); - ordered.verifyNoMoreInteractions(); + assertMorph(receiver, + "" + + " " + + " " + + " " + + " " + + "", + i -> { + i.startRecord("1"); + i.literal("first", "1789"); + i.literal("last", "1799"); + i.endRecord(); + }, + o -> { + o.get().startRecord("1"); + o.get().literal("range", "1789"); + o.get().literal("range", "1792"); + o.get().literal("range", "1795"); + o.get().literal("range", "1798"); + o.get().endRecord(); + } + ); } @Test public void shouldAllowNegativeIncrements() { - metamorph = InlineMorph.in(this) - .with("") - .with(" ") - .with(" ") - .with(" ") - .with(" ") - .with("") - .createConnectedTo(receiver); - - metamorph.startRecord("1"); - metamorph.literal("first", "1799"); - metamorph.literal("last", "1789"); - metamorph.endRecord(); - - final InOrder ordered = inOrder(receiver); - ordered.verify(receiver).startRecord("1"); - ordered.verify(receiver).literal("range", "1799"); - ordered.verify(receiver).literal("range", "1796"); - ordered.verify(receiver).literal("range", "1793"); - ordered.verify(receiver).literal("range", "1790"); - ordered.verify(receiver).endRecord(); - ordered.verifyNoMoreInteractions(); + assertMorph(receiver, + "" + + " " + + " " + + " " + + " " + + "", + i -> { + i.startRecord("1"); + i.literal("first", "1799"); + i.literal("last", "1789"); + i.endRecord(); + }, + o -> { + o.get().startRecord("1"); + o.get().literal("range", "1799"); + o.get().literal("range", "1796"); + o.get().literal("range", "1793"); + o.get().literal("range", "1790"); + o.get().endRecord(); + } + ); } } diff --git a/metamorph/src/test/java/org/metafacture/metamorph/collectors/SquareTest.java b/metamorph/src/test/java/org/metafacture/metamorph/collectors/SquareTest.java index de72ad29c..44f2fcd3d 100644 --- a/metamorph/src/test/java/org/metafacture/metamorph/collectors/SquareTest.java +++ b/metamorph/src/test/java/org/metafacture/metamorph/collectors/SquareTest.java @@ -16,14 +16,11 @@ package org.metafacture.metamorph.collectors; -import static org.mockito.Mockito.inOrder; +import static org.metafacture.metamorph.TestHelpers.assertMorph; import org.junit.Rule; import org.junit.Test; import org.metafacture.framework.StreamReceiver; -import org.metafacture.metamorph.InlineMorph; -import org.metafacture.metamorph.Metamorph; -import org.mockito.InOrder; import org.mockito.Mock; import org.mockito.junit.MockitoJUnit; import org.mockito.junit.MockitoRule; @@ -42,96 +39,94 @@ public final class SquareTest { @Mock private StreamReceiver receiver; - private Metamorph metamorph; - @Test public void shouldEmitSquaresOfInputValues() { - metamorph = InlineMorph.in(this) - .with("") - .with(" ") - .with(" ") - .with(" ") - .with(" ") - .with("") - .createConnectedTo(receiver); - - metamorph.startRecord("1"); - metamorph.literal("data1", "b"); - metamorph.literal("data1", "a"); - metamorph.literal("data2", "c"); - metamorph.endRecord(); - metamorph.startRecord("2"); - metamorph.literal("data1", "1"); - metamorph.literal("data1", "2"); - metamorph.literal("data2", "3"); - metamorph.literal("data2", "4"); - metamorph.literal("data2", "5"); - metamorph.literal("data2", "6"); - metamorph.literal("data2", "7"); - metamorph.endRecord(); - - final InOrder ordered = inOrder(receiver); - ordered.verify(receiver).startRecord("1"); - ordered.verify(receiver).literal("square", "{a,c}"); - ordered.verify(receiver).literal("square", "{b,c}"); - ordered.verify(receiver).literal("square", "{a,b}"); - ordered.verify(receiver).endRecord(); - ordered.verify(receiver).startRecord("2"); - ordered.verify(receiver).literal("square", "{1,7}"); - ordered.verify(receiver).literal("square", "{2,7}"); - ordered.verify(receiver).literal("square", "{3,7}"); - ordered.verify(receiver).literal("square", "{4,7}"); - ordered.verify(receiver).literal("square", "{5,7}"); - ordered.verify(receiver).literal("square", "{6,7}"); - ordered.verify(receiver).literal("square", "{1,6}"); - ordered.verify(receiver).literal("square", "{2,6}"); - ordered.verify(receiver).literal("square", "{3,6}"); - ordered.verify(receiver).literal("square", "{4,6}"); - ordered.verify(receiver).literal("square", "{5,6}"); - ordered.verify(receiver).literal("square", "{1,5}"); - ordered.verify(receiver).literal("square", "{2,5}"); - ordered.verify(receiver).literal("square", "{3,5}"); - ordered.verify(receiver).literal("square", "{4,5}"); - ordered.verify(receiver).literal("square", "{1,4}"); - ordered.verify(receiver).literal("square", "{2,4}"); - ordered.verify(receiver).literal("square", "{3,4}"); - ordered.verify(receiver).literal("square", "{1,3}"); - ordered.verify(receiver).literal("square", "{2,3}"); - ordered.verify(receiver).literal("square", "{1,2}"); - ordered.verify(receiver).endRecord(); - ordered.verifyNoMoreInteractions(); + assertMorph(receiver, + "" + + " " + + " " + + " " + + " " + + "", + i -> { + i.startRecord("1"); + i.literal("data1", "b"); + i.literal("data1", "a"); + i.literal("data2", "c"); + i.endRecord(); + i.startRecord("2"); + i.literal("data1", "1"); + i.literal("data1", "2"); + i.literal("data2", "3"); + i.literal("data2", "4"); + i.literal("data2", "5"); + i.literal("data2", "6"); + i.literal("data2", "7"); + i.endRecord(); + }, + o -> { + o.get().startRecord("1"); + o.get().literal("square", "{a,c}"); + o.get().literal("square", "{b,c}"); + o.get().literal("square", "{a,b}"); + o.get().endRecord(); + o.get().startRecord("2"); + o.get().literal("square", "{1,7}"); + o.get().literal("square", "{2,7}"); + o.get().literal("square", "{3,7}"); + o.get().literal("square", "{4,7}"); + o.get().literal("square", "{5,7}"); + o.get().literal("square", "{6,7}"); + o.get().literal("square", "{1,6}"); + o.get().literal("square", "{2,6}"); + o.get().literal("square", "{3,6}"); + o.get().literal("square", "{4,6}"); + o.get().literal("square", "{5,6}"); + o.get().literal("square", "{1,5}"); + o.get().literal("square", "{2,5}"); + o.get().literal("square", "{3,5}"); + o.get().literal("square", "{4,5}"); + o.get().literal("square", "{1,4}"); + o.get().literal("square", "{2,4}"); + o.get().literal("square", "{3,4}"); + o.get().literal("square", "{1,3}"); + o.get().literal("square", "{2,3}"); + o.get().literal("square", "{1,2}"); + o.get().endRecord(); + } + ); } @Test public void shouldEmitSquaresOnFlushEvent() { - metamorph = InlineMorph.in(this) - .with("") - .with(" ") - .with(" ") - .with(" ") - .with("") - .createConnectedTo(receiver); - - metamorph.startRecord("1"); - metamorph.startEntity("d"); - metamorph.literal("1", "a"); - metamorph.literal("1", "b"); - metamorph.endEntity(); - metamorph.startEntity("d"); - metamorph.literal("1", "e"); - metamorph.literal("1", "f"); - metamorph.endEntity(); - metamorph.startEntity("d"); - metamorph.literal("2", "e"); - metamorph.endEntity(); - metamorph.endRecord(); - - final InOrder ordered = inOrder(receiver); - ordered.verify(receiver).startRecord("1"); - ordered.verify(receiver).literal("square", "{a,b}"); - ordered.verify(receiver).literal("square", "{e,f}"); - ordered.verify(receiver).endRecord(); - ordered.verifyNoMoreInteractions(); + assertMorph(receiver, + "" + + " " + + " " + + " " + + "", + i -> { + i.startRecord("1"); + i.startEntity("d"); + i.literal("1", "a"); + i.literal("1", "b"); + i.endEntity(); + i.startEntity("d"); + i.literal("1", "e"); + i.literal("1", "f"); + i.endEntity(); + i.startEntity("d"); + i.literal("2", "e"); + i.endEntity(); + i.endRecord(); + }, + o -> { + o.get().startRecord("1"); + o.get().literal("square", "{a,b}"); + o.get().literal("square", "{e,f}"); + o.get().endRecord(); + } + ); } } diff --git a/metamorph/src/test/java/org/metafacture/metamorph/collectors/TestCollectorBasics.java b/metamorph/src/test/java/org/metafacture/metamorph/collectors/TestCollectorBasics.java index 8b00ec08c..408394ba4 100644 --- a/metamorph/src/test/java/org/metafacture/metamorph/collectors/TestCollectorBasics.java +++ b/metamorph/src/test/java/org/metafacture/metamorph/collectors/TestCollectorBasics.java @@ -16,14 +16,12 @@ package org.metafacture.metamorph.collectors; -import static org.mockito.Mockito.inOrder; +import static org.metafacture.metamorph.TestHelpers.assertMorph; import org.junit.Rule; import org.junit.Test; import org.metafacture.framework.StreamReceiver; -import org.metafacture.metamorph.InlineMorph; import org.metafacture.metamorph.Metamorph; -import org.mockito.InOrder; import org.mockito.Mock; import org.mockito.junit.MockitoJUnit; import org.mockito.junit.MockitoRule; @@ -44,133 +42,132 @@ public final class TestCollectorBasics { @Mock private StreamReceiver receiver; - private Metamorph metamorph; - @Test public void shouldSupportNestedCollectors() { - metamorph = InlineMorph.in(this) - .with("") - .with(" ") - .with(" ") - .with(" ") - .with(" ") - .with(" ") - .with(" ") - .with(" ") - .with(" ") - .with(" ") - .with(" ") - .with("") - .createConnectedTo(receiver); - - metamorph.startRecord("1"); - metamorph.literal("d1", "a"); - metamorph.literal("d2", "b"); - metamorph.literal("d3", "c "); - metamorph.endRecord(); - - final InOrder ordered = inOrder(receiver); - ordered.verify(receiver).startRecord("1"); - ordered.verify(receiver).literal("d", "abc"); - ordered.verify(receiver).endRecord(); - ordered.verifyNoMoreInteractions(); } + assertMorph(receiver, + "" + + " " + + " " + + " " + + " " + + " " + + " " + + " " + + " " + + " " + + " " + + "", + i -> { + i.startRecord("1"); + i.literal("d1", "a"); + i.literal("d2", "b"); + i.literal("d3", "c "); + i.endRecord(); + }, + o -> { + o.get().startRecord("1"); + o.get().literal("d", "abc"); + o.get().endRecord(); + } + ); + } @Test public void shouldSupportNestedSameEntity() { - metamorph = InlineMorph.in(this) - .with("") - .with(" ") - .with(" ") - .with(" ") - .with(" ") - .with(" ") - .with(" ") - .with(" ") - .with(" ") - .with(" ") - .with("") - .createConnectedTo(receiver); - - metamorph.startRecord("1"); - metamorph.startEntity("rel"); - metamorph.literal("ch", "b"); - metamorph.literal("value", "a"); - metamorph.endEntity(); - metamorph.startEntity("rel"); - metamorph.literal("value", "B"); - metamorph.endEntity(); - metamorph.startEntity("rel"); - metamorph.literal("ch", "e"); - metamorph.literal("value", "d"); - metamorph.endEntity(); - metamorph.startEntity("rel"); - metamorph.literal("ch", "X"); - metamorph.endEntity(); - metamorph.endRecord(); - - final InOrder ordered = inOrder(receiver); - ordered.verify(receiver).startRecord("1"); - ordered.verify(receiver).literal("result", "ab"); - ordered.verify(receiver).literal("result", "BM"); - ordered.verify(receiver).literal("result", "de"); - ordered.verify(receiver).endRecord(); - ordered.verifyNoMoreInteractions(); + assertMorph(receiver, + "" + + " " + + " " + + " " + + " " + + " " + + " " + + " " + + " " + + " " + + "", + i -> { + i.startRecord("1"); + i.startEntity("rel"); + i.literal("ch", "b"); + i.literal("value", "a"); + i.endEntity(); + i.startEntity("rel"); + i.literal("value", "B"); + i.endEntity(); + i.startEntity("rel"); + i.literal("ch", "e"); + i.literal("value", "d"); + i.endEntity(); + i.startEntity("rel"); + i.literal("ch", "X"); + i.endEntity(); + i.endRecord(); + }, + o -> { + o.get().startRecord("1"); + o.get().literal("result", "ab"); + o.get().literal("result", "BM"); + o.get().literal("result", "de"); + o.get().endRecord(); + } + ); } @Test public void shouldAllowUsingAnArbitraryLiteralForFlush() { - metamorph = InlineMorph.in(this) - .with("") - .with(" ") - .with(" ") - .with(" ") - .with("") - .createConnectedTo(receiver); - - metamorph.startRecord("1"); - metamorph.literal("d", "1"); - metamorph.literal("d", "2"); - metamorph.literal("f", ""); - metamorph.literal("d", "3"); - metamorph.literal("d", "4"); - metamorph.literal("d", "5"); - metamorph.literal("f", ""); - metamorph.literal("d", "6"); - metamorph.endRecord(); - - final InOrder ordered = inOrder(receiver); - ordered.verify(receiver).startRecord("1"); - ordered.verify(receiver).literal("d", "12"); - ordered.verify(receiver).literal("d", "345"); - ordered.verify(receiver).endRecord(); - ordered.verifyNoMoreInteractions(); + assertMorph(receiver, + "" + + " " + + " " + + " " + + "", + i -> { + i.startRecord("1"); + i.literal("d", "1"); + i.literal("d", "2"); + i.literal("f", ""); + i.literal("d", "3"); + i.literal("d", "4"); + i.literal("d", "5"); + i.literal("f", ""); + i.literal("d", "6"); + i.endRecord(); + }, + o -> { + o.get().startRecord("1"); + o.get().literal("d", "12"); + o.get().literal("d", "345"); + o.get().endRecord(); + } + ); } @Test public void shouldReceiveFlushingLiteralBeforeFlushEvent() { - metamorph = InlineMorph.in(this) - .with("") - .with(" ") - .with(" ") - .with(" ") - .with(" ") - .with("") - .createConnectedTo(receiver); - - metamorph.startRecord("1"); - metamorph.literal("f", "1"); - metamorph.literal("f", "2"); - metamorph.literal("d", "a"); - metamorph.literal("f", "3"); - metamorph.endRecord(); - - final InOrder ordered = inOrder(receiver); - ordered.verify(receiver).startRecord("1"); - ordered.verify(receiver).literal("d", "1"); - ordered.verify(receiver).literal("d", "2"); - ordered.verify(receiver).literal("d", "a3"); - ordered.verify(receiver).endRecord(); - ordered.verifyNoMoreInteractions(); + assertMorph(receiver, + "" + + " " + + " " + + " " + + " " + + "", + i -> { + i.startRecord("1"); + i.literal("f", "1"); + i.literal("f", "2"); + i.literal("d", "a"); + i.literal("f", "3"); + i.endRecord(); + }, + o -> { + o.get().startRecord("1"); + o.get().literal("d", "1"); + o.get().literal("d", "2"); + o.get().literal("d", "a3"); + o.get().endRecord(); + } + ); } } diff --git a/metamorph/src/test/java/org/metafacture/metamorph/collectors/TestCollectorIf.java b/metamorph/src/test/java/org/metafacture/metamorph/collectors/TestCollectorIf.java index fd6f16d61..c026414ec 100644 --- a/metamorph/src/test/java/org/metafacture/metamorph/collectors/TestCollectorIf.java +++ b/metamorph/src/test/java/org/metafacture/metamorph/collectors/TestCollectorIf.java @@ -16,14 +16,11 @@ package org.metafacture.metamorph.collectors; -import static org.mockito.Mockito.inOrder; +import static org.metafacture.metamorph.TestHelpers.assertMorph; import org.junit.Rule; import org.junit.Test; import org.metafacture.framework.StreamReceiver; -import org.metafacture.metamorph.InlineMorph; -import org.metafacture.metamorph.Metamorph; -import org.mockito.InOrder; import org.mockito.Mock; import org.mockito.junit.MockitoJUnit; import org.mockito.junit.MockitoRule; @@ -43,248 +40,246 @@ public final class TestCollectorIf { @Mock private StreamReceiver receiver; - private Metamorph metamorph; - @Test public void shouldOnlyFireIfConditionIsMet() { - metamorph = InlineMorph.in(this) - .with("") - .with(" ") - .with(" ") - .with(" ") - .with(" ") - .with(" ") - .with(" ") - .with(" ") - .with("") - .createConnectedTo(receiver); - - metamorph.startRecord("1"); - metamorph.literal("data1", "a"); - metamorph.literal("data2", "b"); - metamorph.literal("data3", "c"); - metamorph.endRecord(); - metamorph.startRecord("2"); - metamorph.literal("data1", "a"); - metamorph.literal("data2", "b"); - metamorph.literal("data4", "c"); - metamorph.endRecord(); - - final InOrder ordered = inOrder(receiver); - ordered.verify(receiver).startRecord("1"); - ordered.verify(receiver).literal("combined", "a-b"); - ordered.verify(receiver).endRecord(); - ordered.verify(receiver).startRecord("2"); - ordered.verify(receiver).endRecord(); - ordered.verifyNoMoreInteractions(); + assertMorph(receiver, + "" + + " " + + " " + + " " + + " " + + " " + + " " + + " " + + "", + i -> { + i.startRecord("1"); + i.literal("data1", "a"); + i.literal("data2", "b"); + i.literal("data3", "c"); + i.endRecord(); + i.startRecord("2"); + i.literal("data1", "a"); + i.literal("data2", "b"); + i.literal("data4", "c"); + i.endRecord(); + }, + o -> { + o.get().startRecord("1"); + o.get().literal("combined", "a-b"); + o.get().endRecord(); + o.get().startRecord("2"); + o.get().endRecord(); + } + ); } @Test public void shouldAllowToUseSameSourceInbodyAndCondition() { - metamorph = InlineMorph.in(this) - .with("") - .with(" ") - .with(" ") - .with(" ") - .with(" ") - .with(" ") - .with(" ") - .with(" ") - .with(" ") - .with(" ") - .with("") - .createConnectedTo(receiver); - - metamorph.startRecord("1"); - metamorph.literal("data1", "a"); - metamorph.literal("data2", "b"); - metamorph.endRecord(); - metamorph.startRecord("2"); - metamorph.literal("data1", "a"); - metamorph.literal("data2", "c"); - metamorph.endRecord(); - - final InOrder ordered = inOrder(receiver); - ordered.verify(receiver).startRecord("1"); - ordered.verify(receiver).literal("combined", "a-b"); - ordered.verify(receiver).endRecord(); - ordered.verify(receiver).startRecord("2"); - ordered.verify(receiver).endRecord(); - ordered.verifyNoMoreInteractions(); + assertMorph(receiver, + "" + + " " + + " " + + " " + + " " + + " " + + " " + + " " + + " " + + " " + + "", + i -> { + i.startRecord("1"); + i.literal("data1", "a"); + i.literal("data2", "b"); + i.endRecord(); + i.startRecord("2"); + i.literal("data1", "a"); + i.literal("data2", "c"); + i.endRecord(); + }, + o -> { + o.get().startRecord("1"); + o.get().literal("combined", "a-b"); + o.get().endRecord(); + o.get().startRecord("2"); + o.get().endRecord(); + } + ); } @Test public void shouldAllowQuantorsInIfStatements() { - metamorph = InlineMorph.in(this) - .with("") - .with(" ") - .with(" ") - .with(" ") - .with(" ") - .with(" ") - .with(" ") - .with(" ") - .with(" ") - .with(" ") - .with(" ") - .with("") - .createConnectedTo(receiver); - - metamorph.startRecord("1"); - metamorph.literal("data1", "a"); - metamorph.literal("data2", "b"); - metamorph.literal("data3", "c"); - metamorph.endRecord(); - metamorph.startRecord("2"); - metamorph.literal("data1", "a"); - metamorph.literal("data2", "d"); - metamorph.literal("data4", "c"); - metamorph.endRecord(); - metamorph.startRecord("3"); - metamorph.literal("data1", "a"); - metamorph.literal("data2", "b"); - metamorph.literal("data5", "c"); - metamorph.endRecord(); - - final InOrder ordered = inOrder(receiver); - ordered.verify(receiver).startRecord("1"); - ordered.verify(receiver).literal("combined", "a-b"); - ordered.verify(receiver).endRecord(); - ordered.verify(receiver).startRecord("2"); - ordered.verify(receiver).literal("combined", "a-d"); - ordered.verify(receiver).endRecord(); - ordered.verify(receiver).startRecord("3"); - ordered.verify(receiver).endRecord(); - ordered.verifyNoMoreInteractions(); + assertMorph(receiver, + "" + + " " + + " " + + " " + + " " + + " " + + " " + + " " + + " " + + " " + + " " + + "", + i -> { + i.startRecord("1"); + i.literal("data1", "a"); + i.literal("data2", "b"); + i.literal("data3", "c"); + i.endRecord(); + i.startRecord("2"); + i.literal("data1", "a"); + i.literal("data2", "d"); + i.literal("data4", "c"); + i.endRecord(); + i.startRecord("3"); + i.literal("data1", "a"); + i.literal("data2", "b"); + i.literal("data5", "c"); + i.endRecord(); + }, + o -> { + o.get().startRecord("1"); + o.get().literal("combined", "a-b"); + o.get().endRecord(); + o.get().startRecord("2"); + o.get().literal("combined", "a-d"); + o.get().endRecord(); + o.get().startRecord("3"); + o.get().endRecord(); + } + ); } @Test public void shouldResetConditionWithCollector() { - metamorph = InlineMorph.in(this) - .with("") - .with(" ") - .with(" ") - .with(" ") - .with(" ") - .with(" ") - .with(" ") - .with("") - .createConnectedTo(receiver); - - metamorph.startRecord("1"); - metamorph.startEntity("entity"); - metamorph.literal("data1", "output"); - metamorph.literal("data2", "X"); - metamorph.endEntity(); - metamorph.startEntity("entity"); - metamorph.literal("data1", "no-output"); - metamorph.literal("data3", "X"); - metamorph.endEntity(); - metamorph.endRecord(); - - final InOrder ordered = inOrder(receiver); - ordered.verify(receiver).startRecord("1"); - ordered.verify(receiver).literal("result", "output"); - ordered.verify(receiver).endRecord(); - ordered.verifyNoMoreInteractions(); + assertMorph(receiver, + "" + + " " + + " " + + " " + + " " + + " " + + " " + + "", + i -> { + i.startRecord("1"); + i.startEntity("entity"); + i.literal("data1", "output"); + i.literal("data2", "X"); + i.endEntity(); + i.startEntity("entity"); + i.literal("data1", "no-output"); + i.literal("data3", "X"); + i.endEntity(); + i.endRecord(); + }, + o -> { + o.get().startRecord("1"); + o.get().literal("result", "output"); + o.get().endRecord(); + } + ); } @Test public void shouldResetConditionWithCollectorOnFlushWith() { - metamorph = InlineMorph.in(this) - .with("") - .with(" ") - .with(" ") - .with(" ") - .with(" ") - .with(" ") - .with(" ") - .with(" ") - .with("") - .createConnectedTo(receiver); - - metamorph.startRecord("1"); - metamorph.startEntity("entity"); - metamorph.literal("data1", "output"); - metamorph.literal("data2", "X"); - metamorph.endEntity(); - metamorph.startEntity("entity"); - metamorph.literal("data1", "no-output"); - metamorph.literal("data3", "X"); - metamorph.endEntity(); - metamorph.endRecord(); - - final InOrder ordered = inOrder(receiver); - ordered.verify(receiver).startRecord("1"); - ordered.verify(receiver).literal("result", "output"); - ordered.verify(receiver).endRecord(); - ordered.verifyNoMoreInteractions(); + assertMorph(receiver, + "" + + " " + + " " + + " " + + " " + + " " + + " " + + " " + + "", + i -> { + i.startRecord("1"); + i.startEntity("entity"); + i.literal("data1", "output"); + i.literal("data2", "X"); + i.endEntity(); + i.startEntity("entity"); + i.literal("data1", "no-output"); + i.literal("data3", "X"); + i.endEntity(); + i.endRecord(); + }, + o -> { + o.get().startRecord("1"); + o.get().literal("result", "output"); + o.get().endRecord(); + } + ); } @Test public void shouldResetConditionWithCollectorOnSameEntity() { - metamorph = InlineMorph.in(this) - .with("") - .with(" ") - .with(" ") - .with(" ") - .with(" ") - .with(" ") - .with(" ") - .with(" ") - .with("") - .createConnectedTo(receiver); - - metamorph.startRecord("1"); - metamorph.startEntity("entity"); - metamorph.literal("data1", "output"); - metamorph.literal("data2", "X"); - metamorph.endEntity(); - metamorph.startEntity("entity"); - metamorph.literal("data1", "no-output"); - metamorph.literal("data3", "X"); - metamorph.literal("data4", "extra-output"); - metamorph.endEntity(); - metamorph.endRecord(); - - final InOrder ordered = inOrder(receiver); - ordered.verify(receiver).startRecord("1"); - ordered.verify(receiver).endRecord(); - ordered.verifyNoMoreInteractions(); + assertMorph(receiver, + "" + + " " + + " " + + " " + + " " + + " " + + " " + + " " + + "", + i -> { + i.startRecord("1"); + i.startEntity("entity"); + i.literal("data1", "output"); + i.literal("data2", "X"); + i.endEntity(); + i.startEntity("entity"); + i.literal("data1", "no-output"); + i.literal("data3", "X"); + i.literal("data4", "extra-output"); + i.endEntity(); + i.endRecord(); + }, + o -> { + o.get().startRecord("1"); + o.get().endRecord(); + } + ); } @Test public void shouldResetOnFlushWithIfConditionWasNotMet() { - metamorph = InlineMorph.in(this) - .with("") - .with(" ") - .with(" ") - .with(" ") - .with(" ") - .with(" ") - .with(" ") - .with(" ") - .with(" ") - .with(" ") - .with("") - .createConnectedTo(receiver); - - metamorph.startRecord("1"); - metamorph.startEntity("entity"); - metamorph.literal("condition", "false"); - metamorph.literal("literal1", "value1"); - metamorph.endEntity(); - metamorph.startEntity("entity"); - metamorph.literal("condition", "true"); - metamorph.literal("literal2", "value2"); - metamorph.endEntity(); - metamorph.endRecord(); - - final InOrder ordered = inOrder(receiver); - ordered.verify(receiver).startRecord("1"); - ordered.verify(receiver).literal("result", "value2"); - ordered.verify(receiver).endRecord(); - ordered.verifyNoMoreInteractions(); + assertMorph(receiver, + "" + + " " + + " " + + " " + + " " + + " " + + " " + + " " + + " " + + " " + + "", + i -> { + i.startRecord("1"); + i.startEntity("entity"); + i.literal("condition", "false"); + i.literal("literal1", "value1"); + i.endEntity(); + i.startEntity("entity"); + i.literal("condition", "true"); + i.literal("literal2", "value2"); + i.endEntity(); + i.endRecord(); + }, + o -> { + o.get().startRecord("1"); + o.get().literal("result", "value2"); + o.get().endRecord(); + } + ); } } From 67537c26611bdd6aad9a880c96f329988e15af0e Mon Sep 17 00:00:00 2001 From: Jens Wille Date: Fri, 29 Oct 2021 21:55:06 +0200 Subject: [PATCH 3/6] Fix indentation in Metamorph function tests. --- .../metamorph/functions/DateFormatTest.java | 46 +- .../metamorph/functions/ISBNTest.java | 10 +- .../metamorph/functions/LookupTest.java | 78 +-- .../functions/NormalizeUTF8Test.java | 5 +- .../metamorph/functions/RegexpTest.java | 164 ++--- .../metamorph/functions/ScriptTest.java | 56 +- .../metamorph/functions/SplitTest.java | 16 +- .../functions/StringOperationsTest.java | 20 +- .../functions/SwitchNameValueTest.java | 16 +- .../functions/TestFunctionBasics.java | 180 +++--- .../functions/TestVariousFunctions.java | 596 +++++++++--------- .../metamorph/functions/UniqueTest.java | 220 +++---- 12 files changed, 698 insertions(+), 709 deletions(-) diff --git a/metamorph/src/test/java/org/metafacture/metamorph/functions/DateFormatTest.java b/metamorph/src/test/java/org/metafacture/metamorph/functions/DateFormatTest.java index 65801c706..0af8647c7 100644 --- a/metamorph/src/test/java/org/metafacture/metamorph/functions/DateFormatTest.java +++ b/metamorph/src/test/java/org/metafacture/metamorph/functions/DateFormatTest.java @@ -36,33 +36,33 @@ */ public final class DateFormatTest { - @Rule - public final MockitoRule mockitoRule = MockitoJUnit.rule(); + @Rule + public final MockitoRule mockitoRule = MockitoJUnit.rule(); - @Mock - private StreamReceiver receiver; + @Mock + private StreamReceiver receiver; - private Metamorph metamorph; + private Metamorph metamorph; - @Test - public void shouldMakeOutputFormatConfigurable() { - metamorph = InlineMorph.in(this) - .with("") - .with(" ") - .with(" ") - .with(" ") - .with("") - .createConnectedTo(receiver); + @Test + public void shouldMakeOutputFormatConfigurable() { + metamorph = InlineMorph.in(this) + .with("") + .with(" ") + .with(" ") + .with(" ") + .with("") + .createConnectedTo(receiver); - metamorph.startRecord("1"); - metamorph.literal("date", "23.04.1564"); - metamorph.endRecord(); + metamorph.startRecord("1"); + metamorph.literal("date", "23.04.1564"); + metamorph.endRecord(); - final InOrder ordered = inOrder(receiver); - ordered.verify(receiver).startRecord("1"); - ordered.verify(receiver).literal("date", "April 23, 1564"); - ordered.verify(receiver).endRecord(); - ordered.verifyNoMoreInteractions(); - } + final InOrder ordered = inOrder(receiver); + ordered.verify(receiver).startRecord("1"); + ordered.verify(receiver).literal("date", "April 23, 1564"); + ordered.verify(receiver).endRecord(); + ordered.verifyNoMoreInteractions(); + } } diff --git a/metamorph/src/test/java/org/metafacture/metamorph/functions/ISBNTest.java b/metamorph/src/test/java/org/metafacture/metamorph/functions/ISBNTest.java index 60c0fdc2c..1d295cafe 100644 --- a/metamorph/src/test/java/org/metafacture/metamorph/functions/ISBNTest.java +++ b/metamorph/src/test/java/org/metafacture/metamorph/functions/ISBNTest.java @@ -22,7 +22,6 @@ import org.junit.Test; - /** * tests {@link ISBN} * @@ -43,14 +42,11 @@ public final class ISBNTest { private static final String ISBN_INCORRECT_CHECK13 = "9781933988314"; private static final String ISBN_INCORRECT_CHECK10 = "1933988311"; - private static final String ISBN_INCORRECT_SIZE1 = "12345678901234"; private static final String ISBN_INCORRECT_SIZE2 = "123456789012"; private static final String ISBN_INCORRECT_SIZE3 = "123456789"; private static final String ERROR = "invalid"; - - @Test public void testProcess(){ final ISBN isbn = new ISBN(); @@ -70,12 +66,12 @@ public void testTo13() { @Test public void testTo10() { - assertEquals(ISBN10A,ISBN.isbn13to10(ISBN13A)); + assertEquals(ISBN10A, ISBN.isbn13to10(ISBN13A)); } @Test public void testCleanse() { - assertEquals(ISBN10A,ISBN.cleanse(ISBN10A_DIRTY)); + assertEquals(ISBN10A, ISBN.cleanse(ISBN10A_DIRTY)); } @Test(expected = IllegalArgumentException.class) @@ -104,14 +100,12 @@ public void testIsValid() { assertTrue(ISBN.isValid(ISBN.cleanse(ISBN10F_DIRTY))); } - public void testCleanseException1(){ final ISBN isbn = new ISBN(); isbn.setErrorString(ERROR); assertTrue(isbn.process(ISBN_INCORRECT_SIZE3).startsWith(ERROR)); } - public void testCleanseException2(){ final ISBN isbn = new ISBN(); isbn.setErrorString(ERROR); diff --git a/metamorph/src/test/java/org/metafacture/metamorph/functions/LookupTest.java b/metamorph/src/test/java/org/metafacture/metamorph/functions/LookupTest.java index d50204c2c..c2384b08e 100644 --- a/metamorph/src/test/java/org/metafacture/metamorph/functions/LookupTest.java +++ b/metamorph/src/test/java/org/metafacture/metamorph/functions/LookupTest.java @@ -99,19 +99,19 @@ public void shouldReturnNullIfKeyDoesNotExist() { @Test public void shouldLookupValuesInLocalMap() { final Metamorph metamorph = InlineMorph.in(this) - .with("") - .with(" ") - .with(" ") - .with(" ") - .with(" ") - .with(" ") - .with(" ") - .with(" ") - .with(" ") - .with(" ") - .with(" ") - .with("") - .createConnectedTo(receiver); + .with("") + .with(" ") + .with(" ") + .with(" ") + .with(" ") + .with(" ") + .with(" ") + .with(" ") + .with(" ") + .with(" ") + .with(" ") + .with("") + .createConnectedTo(receiver); metamorph.startRecord("1"); metamorph.literal("1", "a"); @@ -132,23 +132,23 @@ public void shouldLookupValuesInLocalMap() { @Test public void shouldLookupValuesInReferencedMap() { final Metamorph metamorph = InlineMorph.in(this) - .with("") - .with(" ") - .with(" ") - .with(" ") - .with(" ") - .with(" ") - .with(" ") - .with("") - .with("") - .with(" ") - .with(" ") - .with(" ") - .with(" ") - .with(" ") - .with(" ") - .with("") - .createConnectedTo(receiver); + .with("") + .with(" ") + .with(" ") + .with(" ") + .with(" ") + .with(" ") + .with(" ") + .with("") + .with("") + .with(" ") + .with(" ") + .with(" ") + .with(" ") + .with(" ") + .with(" ") + .with("") + .createConnectedTo(receiver); metamorph.startRecord("1"); metamorph.literal("1", "a"); @@ -169,15 +169,15 @@ public void shouldLookupValuesInReferencedMap() { @Test public void shouldLookupValuesInMetadata() { final Metamorph metamorph = InlineMorph.in(this) - .with("") - .with(" Hawaii") - .with("") - .with("") - .with(" ") - .with(" ") - .with(" ") - .with("") - .createConnectedTo(receiver); + .with("") + .with(" Hawaii") + .with("") + .with("") + .with(" ") + .with(" ") + .with(" ") + .with("") + .createConnectedTo(receiver); metamorph.startRecord("1"); metamorph.literal("data", "name"); diff --git a/metamorph/src/test/java/org/metafacture/metamorph/functions/NormalizeUTF8Test.java b/metamorph/src/test/java/org/metafacture/metamorph/functions/NormalizeUTF8Test.java index b4796eeda..a62a03419 100644 --- a/metamorph/src/test/java/org/metafacture/metamorph/functions/NormalizeUTF8Test.java +++ b/metamorph/src/test/java/org/metafacture/metamorph/functions/NormalizeUTF8Test.java @@ -20,7 +20,6 @@ import org.junit.Test; - /** * Tests for class {@link NormalizeUTF8}. * @@ -30,11 +29,11 @@ public final class NormalizeUTF8Test { // The umlauts in this string are composed of two characters (u and ", e.g.): private static final String INPUT_STR = - "Bauer, Sigmund: Über den Einfluß der Ackergeräthe auf den Reinertrag."; + "Bauer, Sigmund: Über den Einfluß der Ackergeräthe auf den Reinertrag."; // The umlauts in this string are individual characters: private static final String OUTPUT_STR = - "Bauer, Sigmund: Über den Einfluß der Ackergeräthe auf den Reinertrag."; + "Bauer, Sigmund: Über den Einfluß der Ackergeräthe auf den Reinertrag."; @Test public void testProcess() { diff --git a/metamorph/src/test/java/org/metafacture/metamorph/functions/RegexpTest.java b/metamorph/src/test/java/org/metafacture/metamorph/functions/RegexpTest.java index a1ca10813..ce75bc20d 100644 --- a/metamorph/src/test/java/org/metafacture/metamorph/functions/RegexpTest.java +++ b/metamorph/src/test/java/org/metafacture/metamorph/functions/RegexpTest.java @@ -36,87 +36,87 @@ */ public final class RegexpTest { - @Rule - public final MockitoRule mockitoRule = MockitoJUnit.rule(); - - @Mock - private StreamReceiver receiver; - - private Metamorph metamorph; - - @Test - public void shouldMatchAndReplaceUsingRegularExpressions() { - metamorph = InlineMorph.in(this) - .with("") - .with(" ") - .with(" ") - .with(" ") - .with(" ") - .with(" ") - .with(" ") - .with(" ") - .with(" ") - .with(" ") - .with("") - .createConnectedTo(receiver); - - metamorph.startRecord("1"); - metamorph.startEntity("001"); - metamorph.literal("", "184000"); - metamorph.endEntity(); - metamorph.endRecord(); - - final InOrder ordered = inOrder(receiver); - ordered.verify(receiver).startRecord("1"); - ordered.verify(receiver).literal("subject", "resource:P184000"); - ordered.verify(receiver).literal("subject", ""); - ordered.verify(receiver).literal("subject", "184000"); - ordered.verify(receiver).endRecord(); - ordered.verifyNoMoreInteractions(); - } - - @Test - public void shouldIgnoreEmptyMatchGroups() { - metamorph = InlineMorph.in(this) - .with("") - .with(" ") - .with(" ") - .with(" ") - .with("") - .createConnectedTo(receiver); - - metamorph.startRecord("1"); - metamorph.literal("s", "aaccdd"); - metamorph.literal("s", "ax"); - metamorph.endRecord(); - - final InOrder ordered = inOrder(receiver); - ordered.verify(receiver).startRecord("1"); - ordered.verify(receiver).literal("s", "ccdd"); - ordered.verify(receiver).endRecord(); - ordered.verifyNoMoreInteractions(); - } - - @Test - public void shouldIgnoreNullValues() { - metamorph = InlineMorph.in(this) - .with("") - .with(" ") - .with(" ") - .with(" ") - .with("") - .createConnectedTo(receiver); - - metamorph.startRecord("1"); - metamorph.literal("s", "aaccdd"); - metamorph.literal("s", null); - metamorph.endRecord(); - - final InOrder ordered = inOrder(receiver); - ordered.verify(receiver).startRecord("1"); - ordered.verify(receiver).literal("s", "aaccdd"); - ordered.verify(receiver).endRecord(); - ordered.verifyNoMoreInteractions(); - } + @Rule + public final MockitoRule mockitoRule = MockitoJUnit.rule(); + + @Mock + private StreamReceiver receiver; + + private Metamorph metamorph; + + @Test + public void shouldMatchAndReplaceUsingRegularExpressions() { + metamorph = InlineMorph.in(this) + .with("") + .with(" ") + .with(" ") + .with(" ") + .with(" ") + .with(" ") + .with(" ") + .with(" ") + .with(" ") + .with(" ") + .with("") + .createConnectedTo(receiver); + + metamorph.startRecord("1"); + metamorph.startEntity("001"); + metamorph.literal("", "184000"); + metamorph.endEntity(); + metamorph.endRecord(); + + final InOrder ordered = inOrder(receiver); + ordered.verify(receiver).startRecord("1"); + ordered.verify(receiver).literal("subject", "resource:P184000"); + ordered.verify(receiver).literal("subject", ""); + ordered.verify(receiver).literal("subject", "184000"); + ordered.verify(receiver).endRecord(); + ordered.verifyNoMoreInteractions(); + } + + @Test + public void shouldIgnoreEmptyMatchGroups() { + metamorph = InlineMorph.in(this) + .with("") + .with(" ") + .with(" ") + .with(" ") + .with("") + .createConnectedTo(receiver); + + metamorph.startRecord("1"); + metamorph.literal("s", "aaccdd"); + metamorph.literal("s", "ax"); + metamorph.endRecord(); + + final InOrder ordered = inOrder(receiver); + ordered.verify(receiver).startRecord("1"); + ordered.verify(receiver).literal("s", "ccdd"); + ordered.verify(receiver).endRecord(); + ordered.verifyNoMoreInteractions(); + } + + @Test + public void shouldIgnoreNullValues() { + metamorph = InlineMorph.in(this) + .with("") + .with(" ") + .with(" ") + .with(" ") + .with("") + .createConnectedTo(receiver); + + metamorph.startRecord("1"); + metamorph.literal("s", "aaccdd"); + metamorph.literal("s", null); + metamorph.endRecord(); + + final InOrder ordered = inOrder(receiver); + ordered.verify(receiver).startRecord("1"); + ordered.verify(receiver).literal("s", "aaccdd"); + ordered.verify(receiver).endRecord(); + ordered.verifyNoMoreInteractions(); + } } diff --git a/metamorph/src/test/java/org/metafacture/metamorph/functions/ScriptTest.java b/metamorph/src/test/java/org/metafacture/metamorph/functions/ScriptTest.java index f51203b94..b502c9307 100644 --- a/metamorph/src/test/java/org/metafacture/metamorph/functions/ScriptTest.java +++ b/metamorph/src/test/java/org/metafacture/metamorph/functions/ScriptTest.java @@ -36,38 +36,38 @@ */ public final class ScriptTest { - @Rule - public final MockitoRule mockitoRule = MockitoJUnit.rule(); + @Rule + public final MockitoRule mockitoRule = MockitoJUnit.rule(); - @Mock - private StreamReceiver receiver; + @Mock + private StreamReceiver receiver; - private Metamorph metamorph; + private Metamorph metamorph; - @Test - public void shouldExecuteJavascriptFunctions() { - metamorph = InlineMorph.in(this) - .with("") - .with(" ") - .with("