diff --git a/metamorph/src/test/java/org/metafacture/metamorph/MetamorphTest.java b/metamorph/src/test/java/org/metafacture/metamorph/MetamorphTest.java
index 369e34909..e2e8b146f 100644
--- a/metamorph/src/test/java/org/metafacture/metamorph/MetamorphTest.java
+++ b/metamorph/src/test/java/org/metafacture/metamorph/MetamorphTest.java
@@ -19,14 +19,6 @@
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
-import static org.mockito.ArgumentMatchers.any;
-import static org.mockito.ArgumentMatchers.anyInt;
-import static org.mockito.ArgumentMatchers.eq;
-import static org.mockito.Mockito.never;
-import static org.mockito.Mockito.verify;
-
-import java.util.HashMap;
-import java.util.Map;
import org.junit.Before;
import org.junit.Rule;
@@ -34,10 +26,17 @@
import org.metafacture.framework.helpers.DefaultStreamReceiver;
import org.metafacture.metamorph.api.Maps;
import org.metafacture.metamorph.api.NamedValueReceiver;
+import org.mockito.ArgumentMatchers;
import org.mockito.Mock;
+import org.mockito.Mockito;
+import org.mockito.exceptions.base.MockitoAssertionError;
import org.mockito.junit.MockitoJUnit;
import org.mockito.junit.MockitoRule;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.function.Consumer;
+
/**
* Tests for class {@link Metamorph}.
*
@@ -50,7 +49,7 @@ public final class MetamorphTest {
public MockitoRule mockitoRule = MockitoJUnit.rule();
@Mock
- private NamedValueReceiver namedValueReceiver;
+ private NamedValueReceiver receiver;
private Metamorph metamorph;
@@ -62,81 +61,64 @@ public void createSystemUnderTest() {
@Test
public void shouldMapMatchingPath() {
- setupSimpleMappingMorph();
-
- metamorph.startRecord("");
- metamorph.literal("testEntity.testLiteral", "testValue");
-
- verify(namedValueReceiver).receive(eq("outName"), eq("testValue"),
- any(), anyInt(), anyInt());
+ assertNamedValue(true, i -> {
+ i.literal("testEntity.testLiteral", "testValue");
+ });
}
@Test
public void shouldNotMapNonMatchingPath() {
- setupSimpleMappingMorph();
-
- metamorph.startRecord("");
- metamorph.literal("nonMatching.path", "testValue");
-
- verify(namedValueReceiver, never()).receive(any(), any(), any(), anyInt(),
- anyInt());
+ assertNamedValue(false, i -> {
+ i.literal("nonMatching.path", "testValue");
+ });
}
@Test
public void shouldMapMatchingLiteralInMatchingEntity() {
- setupSimpleMappingMorph();
-
- metamorph.startRecord("");
- metamorph.startEntity("testEntity");
- metamorph.literal("testLiteral", "testValue");
-
- verify(namedValueReceiver).receive(eq("outName"), eq("testValue"),
- any(), anyInt(), anyInt());
+ assertNamedValue(true, i -> {
+ i.startEntity("testEntity");
+ i.literal("testLiteral", "testValue");
+ });
}
@Test
public void shouldNotMapNonMatchingLiteralInMatchingEntity() {
- setupSimpleMappingMorph();
-
- metamorph.startRecord("");
- metamorph.startEntity("testEntity");
- metamorph.literal("nonMatching", "testValue");
-
- verify(namedValueReceiver, never()).receive(any(), any(), any(), anyInt(),
- anyInt());
+ assertNamedValue(false, i -> {
+ i.startEntity("testEntity");
+ i.literal("nonMatching", "testValue");
+ });
}
@Test
public void shouldNotMapMatchingLiteralInNonMatchingEntity() {
- setupSimpleMappingMorph();
-
- metamorph.startRecord("");
- metamorph.startEntity("nonMatching");
- metamorph.literal("testLiteral", "testValue");
-
- verify(namedValueReceiver, never()).receive(any(), any(), any(), anyInt(),
- anyInt());
+ assertNamedValue(false, i -> {
+ i.startEntity("nonMatching");
+ i.literal("testLiteral", "testValue");
+ });
}
@Test
public void shouldNotMapLiteralWithoutMatchingEntity() {
- setupSimpleMappingMorph();
-
- metamorph.startRecord("");
- metamorph.literal("testLiteral", "testValue");
-
- verify(namedValueReceiver, never()).receive(any(), any(), any(), anyInt(),
- anyInt());
+ assertNamedValue(false, i -> {
+ i.literal("testLiteral", "testValue");
+ });
}
- /**
- * Creates the Metamorph structure that corresponds to the Metamorph XML
- * statement {@code }.
- */
- private void setupSimpleMappingMorph() {
- final Data data = new Data();
- data.setName("outName");
- data.setNamedValueReceiver(namedValueReceiver);
- metamorph.registerNamedValueReceiver("testEntity" + '.' + "testLiteral", data);
+ @Test
+ public void shouldFedbackLiteralsStartingWithAtIntoMetamorph() {
+ assertNamedValue(true, i -> {
+ final Data data1;
+ data1 = new Data();
+ data1.setName("@feedback");
+ i.addNamedValueSource(data1);
+ i.registerNamedValueReceiver("testLiteral", data1);
+
+ final Data data2 = new Data();
+ data2.setName("outName");
+ data2.setNamedValueReceiver(receiver);
+ i.registerNamedValueReceiver("@feedback", data2);
+
+ i.literal("testLiteral", "testValue");
+ });
}
@Test
@@ -160,26 +142,6 @@ public void shouldReturnDefaultValueIfMapIsKnownButNameIsUnknown() {
assertEquals("defaultValue", metamorph.getValue("testMap", "nameNotInMap"));
}
- @Test
- public void shouldFedbackLiteralsStartingWithAtIntoMetamorph() {
- final Data data1;
- data1 = new Data();
- data1.setName("@feedback");
- metamorph.addNamedValueSource(data1);
- metamorph.registerNamedValueReceiver("testLiteral", data1);
-
- final Data data2 = new Data();
- data2.setName("outName");
- data2.setNamedValueReceiver(namedValueReceiver);
- metamorph.registerNamedValueReceiver("@feedback", data2);
-
- metamorph.startRecord("");
- metamorph.literal("testLiteral", "testValue");
-
- verify(namedValueReceiver).receive(eq("outName"), eq("testValue"),
- any(), anyInt(), anyInt());
- }
-
@Test(expected=IllegalStateException.class)
public void shouldThrowIllegalStateExceptionIfEntityIsNotClosed() {
metamorph.startRecord("");
@@ -189,4 +151,32 @@ public void shouldThrowIllegalStateExceptionIfEntityIsNotClosed() {
metamorph.endRecord(); // Exception expected
}
+ private void assertNamedValue(final boolean matching, final Consumer in) {
+ /**
+ * Creates the Metamorph structure that corresponds to the Metamorph XML
+ * statement {@code }.
+ */
+ final Data data = new Data();
+ data.setName("outName");
+ data.setNamedValueReceiver(receiver);
+ metamorph.registerNamedValueReceiver("testEntity" + '.' + "testLiteral", data);
+
+ metamorph.startRecord("");
+ in.accept(metamorph);
+
+ try {
+ if (matching) {
+ Mockito.verify(receiver).receive(
+ ArgumentMatchers.eq("outName"), ArgumentMatchers.eq("testValue"),
+ ArgumentMatchers.any(), ArgumentMatchers.eq(1), ArgumentMatchers.anyInt());
+ }
+
+ Mockito.verifyNoMoreInteractions(receiver);
+ }
+ catch (final MockitoAssertionError e) {
+ System.out.println(Mockito.mockingDetails(receiver).printInvocations());
+ throw e;
+ }
+ }
+
}
diff --git a/metamorph/src/test/java/org/metafacture/metamorph/SplitterTest.java b/metamorph/src/test/java/org/metafacture/metamorph/SplitterTest.java
index ba9ab310e..d1afef6a4 100644
--- a/metamorph/src/test/java/org/metafacture/metamorph/SplitterTest.java
+++ b/metamorph/src/test/java/org/metafacture/metamorph/SplitterTest.java
@@ -16,16 +16,19 @@
package org.metafacture.metamorph;
-import static org.mockito.Mockito.inOrder;
-import static org.mockito.Mockito.verify;
-import static org.mockito.Mockito.verifyZeroInteractions;
-
-import org.junit.Before;
+import org.junit.Rule;
import org.junit.Test;
import org.metafacture.framework.StreamReceiver;
import org.mockito.InOrder;
import org.mockito.Mock;
-import org.mockito.MockitoAnnotations;
+import org.mockito.Mockito;
+import org.mockito.exceptions.base.MockitoAssertionError;
+import org.mockito.junit.MockitoJUnit;
+import org.mockito.junit.MockitoRule;
+
+import java.util.function.BiConsumer;
+import java.util.function.Consumer;
+import java.util.function.Supplier;
/**
* Tests for class {@link Splitter}.
@@ -36,68 +39,101 @@
*/
public final class SplitterTest {
+ @Rule
+ public MockitoRule mockito = MockitoJUnit.rule();
+
@Mock
private StreamReceiver receiver1;
@Mock
private StreamReceiver receiver2;
- private Splitter splitter;
-
- @Before
- public void setup() {
- MockitoAnnotations.initMocks(this);
- splitter = new Splitter("org/metafacture/metamorph/splitter-test.xml");
- splitter.setReceiver("receiver-1", receiver1);
- splitter.setReceiver("receiver-2", receiver2);
- }
-
@Test
public void shouldPassRecordToReceiverWithMatchingKey() {
- splitter.startRecord("1");
- splitter.startEntity("data");
- splitter.literal("forward-to", "receiver-1");
- splitter.endEntity();
- splitter.endRecord();
- splitter.startRecord("2");
- splitter.literal("forward-to", "receiver-2");
- splitter.endRecord();
-
- final InOrder ordered = inOrder(receiver1, receiver2);
- ordered.verify(receiver1).startRecord("1");
- ordered.verify(receiver1).startEntity("data");
- ordered.verify(receiver1).literal("forward-to", "receiver-1");
- ordered.verify(receiver1).endEntity();
- ordered.verify(receiver1).endRecord();
- ordered.verify(receiver2).startRecord("2");
- ordered.verify(receiver2).literal("forward-to", "receiver-2");
- ordered.verify(receiver2).endRecord();
- ordered.verifyNoMoreInteractions();
+ assertSplitter(
+ i -> {
+ i.startRecord("1");
+ i.startEntity("data");
+ i.literal("forward-to", "receiver-1");
+ i.endEntity();
+ i.endRecord();
+ i.startRecord("2");
+ i.literal("forward-to", "receiver-2");
+ i.endRecord();
+ },
+ (o1, o2) -> {
+ o1.get().startRecord("1");
+ o1.get().startEntity("data");
+ o1.get().literal("forward-to", "receiver-1");
+ o1.get().endEntity();
+ o1.get().endRecord();
+ o2.get().startRecord("2");
+ o2.get().literal("forward-to", "receiver-2");
+ o2.get().endRecord();
+ }
+ );
}
@Test
public void shouldDiscardNonMatchingRecords() {
- splitter.startRecord("1");
- splitter.literal("forward-to", "none");
- splitter.endRecord();
-
- verifyZeroInteractions(receiver1, receiver2);
+ assertSplitter(
+ i -> {
+ i.startRecord("1");
+ i.literal("forward-to", "none");
+ i.endRecord();
+ },
+ (o1, o2) -> {
+ }
+ );
}
@Test
public void shouldPassResetStreamToAllReceivers() {
- splitter.resetStream();
-
- verify(receiver1).resetStream();
- verify(receiver2).resetStream();
+ assertSplitter(
+ i -> {
+ i.resetStream();
+ },
+ (o1, o2) -> {
+ o1.get().resetStream();
+ o2.get().resetStream();
+ }
+ );
}
@Test
public void shouldPassCloseStreamToAllReceivers() {
- splitter.closeStream();
+ assertSplitter(
+ i -> {
+ i.closeStream();
+ },
+ (o1, o2) -> {
+ o1.get().closeStream();
+ o2.get().closeStream();
+ }
+ );
+ }
+
+ private void assertSplitter(final Consumer in, final BiConsumer, Supplier> out) {
+ final InOrder ordered = Mockito.inOrder(receiver1, receiver2);
+
+ final Splitter splitter = new Splitter("org/metafacture/metamorph/splitter-test.xml");
+ splitter.setReceiver("receiver-1", receiver1);
+ splitter.setReceiver("receiver-2", receiver2);
+
+ in.accept(splitter);
+
+ try {
+ out.accept(() -> ordered.verify(receiver1), () -> ordered.verify(receiver2));
- verify(receiver1).closeStream();
- verify(receiver2).closeStream();
+ ordered.verifyNoMoreInteractions();
+ Mockito.verifyNoMoreInteractions(receiver1);
+ Mockito.verifyNoMoreInteractions(receiver2);
+ }
+ catch (final MockitoAssertionError e) {
+ System.out.println(Mockito.mockingDetails(receiver1).printInvocations());
+ System.out.println(Mockito.mockingDetails(receiver2).printInvocations());
+ throw e;
+ }
}
}
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..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;
@@ -36,168 +32,166 @@
*/
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;
+
+ @Test
+ public void shouldFireOnlyIfAllElementsFire() {
+ 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() {
+ 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() {
+ 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() {
+ 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() {
+ 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() {
+ 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 8a697c650..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;
@@ -36,165 +32,163 @@
*/
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;
+
+ @Test
+ public void shouldFireOnlyIfAtLeastOneElementFires() {
+ 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() {
+ 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() {
+ 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() {
+ 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() {
+ 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() {
+ 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 278066505..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;
@@ -37,257 +33,255 @@
*/
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;
+
+ @Test
+ public void shouldChooseValueOfTopMostFiringStatement() {
+ 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() {
+ 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() {
+ 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() {
+ 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() {
+ 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() {
+ 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() {
+ 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() {
+ 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() {
+ 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 75d56ef87..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;
@@ -37,190 +33,187 @@
*/
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;
+
+ @Test
+ public void shouldCombineTwoValues() {
+ 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() {
+ 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() {
+ 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() {
+ 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() {
+ 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() {
+ 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 83821782b..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;
@@ -36,170 +33,168 @@
*/
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;
+
+ @Test
+ public void shouldConcatenateValues() {
+ 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() {
+ 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() {
+ 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() {
+ 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() {
+ 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() {
+ 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 83a53ffc4..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;
@@ -39,515 +34,512 @@
*/
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;
+
+ @Test
+ public void shouldEmitEntities() {
+ 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() {
+ 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() {
+ 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() {
+ 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() {
+ 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() {
+ 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() {
+ 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() {
+ 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() {
+ 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() {
+ 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() {
+ 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() {
+ 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() {
+ 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 998aada7e..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;
@@ -40,280 +34,276 @@
*/
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;
+
+ @Test
+ public void shouldEmitValueIfAllReceivedValuesAreEqual() {
+ 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() {
+ 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() {
+ 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() {
+ 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() {
+ 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() {
+ 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() {
+ 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() {
+ 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() {
+ 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 c983b258b..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;
@@ -37,38 +33,36 @@
*/
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;
-
- @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();
- }
+ @Test
+ public void shouldGroupToOverwriteNameAndValueOfContaintStatements() {
+ 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 4953222be..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;
@@ -36,144 +32,142 @@
*/
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;
+
+ @Test
+ public void shouldFireOnlyifNoElementFired() {
+ 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() {
+ 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() {
+ 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() {
+ 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() {
+ 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 8294d12b9..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;
@@ -35,177 +32,175 @@
*/
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;
+
+ @Test
+ public void shouldOutputAllnNmbersbBetweenFirstAndLastInclusive() {
+ 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() {
+ 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() {
+ 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() {
+ 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() {
+ 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() {
+ 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 e5c022335..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;
@@ -36,102 +33,100 @@
*/
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;
+ @Test
+ public void shouldEmitSquaresOfInputValues() {
+ 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 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();
- }
-
- @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();
- }
+ @Test
+ public void shouldEmitSquaresOnFlushEvent() {
+ 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 7cf2cbd3c..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;
@@ -36,141 +34,140 @@
*/
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;
+
+ @Test
+ public void shouldSupportNestedCollectors() {
+ 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() {
+ 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() {
+ 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() {
+ 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 ea8378eb2..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;
@@ -35,256 +32,254 @@
*/
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;
+ @Test
+ public void shouldOnlyFireIfConditionIsMet() {
+ 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 shouldOnlyFireIfConditionIsMet() {
- metamorph = InlineMorph.in(this)
- .with("")
- .with(" ")
- .with(" ")
- .with(" ")
- .with(" ")
- .with(" ")
- .with(" ")
- .with(" ")
- .with("")
- .createConnectedTo(receiver);
+ @Test
+ public void shouldAllowToUseSameSourceInbodyAndCondition() {
+ 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();
+ }
+ );
+ }
- 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();
+ @Test
+ public void shouldAllowQuantorsInIfStatements() {
+ 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();
+ }
+ );
+ }
- 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 shouldResetConditionWithCollector() {
+ 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 shouldAllowToUseSameSourceInbodyAndCondition() {
- metamorph = InlineMorph.in(this)
- .with("")
- .with(" ")
- .with(" ")
- .with(" ")
- .with(" ")
- .with(" ")
- .with(" ")
- .with(" ")
- .with(" ")
- .with(" ")
- .with("")
- .createConnectedTo(receiver);
+ @Test
+ public void shouldResetConditionWithCollectorOnFlushWith() {
+ 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();
+ }
+ );
+ }
- 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();
+ @Test
+ public void shouldResetConditionWithCollectorOnSameEntity() {
+ 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();
+ }
+ );
+ }
- 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);
-
- 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();
- }
-
- @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();
- }
-
- @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();
- }
-
- @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();
- }
-
- @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();
- }
+ @Test
+ public void shouldResetOnFlushWithIfConditionWasNotMet() {
+ 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();
+ }
+ );
+ }
}
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..1b02157b4 100644
--- a/metamorph/src/test/java/org/metafacture/metamorph/functions/DateFormatTest.java
+++ b/metamorph/src/test/java/org/metafacture/metamorph/functions/DateFormatTest.java
@@ -16,14 +16,11 @@
package org.metafacture.metamorph.functions;
-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;
@@ -36,33 +33,31 @@
*/
public final class DateFormatTest {
- @Rule
- public final MockitoRule mockitoRule = MockitoJUnit.rule();
-
- @Mock
- private StreamReceiver receiver;
-
- private Metamorph metamorph;
-
- @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();
-
- final InOrder ordered = inOrder(receiver);
- ordered.verify(receiver).startRecord("1");
- ordered.verify(receiver).literal("date", "April 23, 1564");
- ordered.verify(receiver).endRecord();
- ordered.verifyNoMoreInteractions();
- }
+ @Rule
+ public final MockitoRule mockitoRule = MockitoJUnit.rule();
+
+ @Mock
+ private StreamReceiver receiver;
+
+ @Test
+ public void shouldMakeOutputFormatConfigurable() {
+ assertMorph(receiver,
+ "" +
+ " " +
+ " " +
+ " " +
+ "",
+ i -> {
+ i.startRecord("1");
+ i.literal("date", "23.04.1564");
+ i.endRecord();
+ },
+ o -> {
+ o.get().startRecord("1");
+ o.get().literal("date", "April 23, 1564");
+ o.get().endRecord();
+ }
+ );
+ }
}
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 79e8ae709..91162be4b 100644
--- a/metamorph/src/test/java/org/metafacture/metamorph/functions/LookupTest.java
+++ b/metamorph/src/test/java/org/metafacture/metamorph/functions/LookupTest.java
@@ -18,20 +18,14 @@
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNull;
-import static org.mockito.Mockito.inOrder;
-import static org.mockito.Mockito.times;
-import static org.mockito.Mockito.verifyNoMoreInteractions;
-import static org.mockito.Mockito.when;
+import static org.metafacture.metamorph.TestHelpers.assertMorph;
-import org.junit.Before;
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.metafacture.metamorph.api.Maps;
-import org.mockito.InOrder;
import org.mockito.Mock;
+import org.mockito.Mockito;
import org.mockito.junit.MockitoJUnit;
import org.mockito.junit.MockitoRule;
@@ -51,7 +45,7 @@ public final class LookupTest {
private static final String VALUE = "Kafka";
@Rule
- public MockitoRule mockito = MockitoJUnit.rule().silent();
+ public MockitoRule mockito = MockitoJUnit.rule();
@Mock
private Maps maps;
@@ -59,16 +53,8 @@ public final class LookupTest {
@Mock
private StreamReceiver receiver;
- @Before
- public void initMaps() {
- when(maps.getValue(MAP_NAME, KEY)).thenReturn(VALUE);
- when(maps.getValue(MAP_NAME, KEY_WRONG)).thenReturn(null);
- when(maps.getValue(MAP_NAME_WRONG, KEY)).thenReturn(null);
- when(maps.getValue(MAP_NAME_WRONG, KEY_WRONG)).thenReturn(null);
- }
-
@Test
- public void shouldReturnNullIfMapNameIsDoesNotExist() {
+ public void shouldReturnNullIfMapNameDoesNotExist() {
final Lookup lookup = new Lookup();
lookup.setMaps(maps);
@@ -83,6 +69,7 @@ public void shouldReturnValueIfMapAndKeyExist() {
lookup.setMaps(maps);
lookup.setIn(MAP_NAME);
+ Mockito.when(maps.getValue(MAP_NAME, KEY)).thenReturn(VALUE);
assertEquals(VALUE, lookup.process(KEY));
}
@@ -99,124 +86,122 @@ 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);
-
- metamorph.startRecord("1");
- metamorph.literal("1", "a");
- metamorph.literal("1", "b");
- metamorph.literal("2", "a");
- metamorph.literal("2", "b");
- metamorph.endRecord();
-
- final InOrder ordered = inOrder(receiver);
- ordered.verify(receiver).startRecord("1");
- ordered.verify(receiver).literal("1", "A");
- ordered.verify(receiver).literal("2", "A");
- ordered.verify(receiver).literal("2", "B");
- ordered.verify(receiver).endRecord();
- ordered.verifyNoMoreInteractions();
- verifyNoMoreInteractions(receiver);
+ assertMorph(receiver,
+ "" +
+ " " +
+ " " +
+ " " +
+ " " +
+ " " +
+ " " +
+ " " +
+ " " +
+ " " +
+ " " +
+ "",
+ i -> {
+ i.startRecord("1");
+ i.literal("1", "a");
+ i.literal("1", "b");
+ i.literal("2", "a");
+ i.literal("2", "b");
+ i.endRecord();
+ },
+ o -> {
+ o.get().startRecord("1");
+ o.get().literal("1", "A");
+ o.get().literal("2", "A");
+ o.get().literal("2", "B");
+ o.get().endRecord();
+ }
+ );
}
@Test
public void shouldLookupValuesInReferencedMap() {
- final Metamorph metamorph = InlineMorph.in(this)
- .with("")
- .with(" ")
- .with(" ")
- .with(" ")
- .with(" ")
- .with(" ")
- .with(" ")
- .with("")
- .with("")
- .with(" ")
- .with(" ")
- .with("")
- .createConnectedTo(receiver);
-
- metamorph.startRecord("1");
- metamorph.literal("1", "a");
- metamorph.literal("1", "b");
- metamorph.literal("2", "a");
- metamorph.literal("2", "b");
- metamorph.endRecord();
-
- final InOrder ordered = inOrder(receiver);
- ordered.verify(receiver).startRecord("1");
- ordered.verify(receiver).literal("1", "A");
- ordered.verify(receiver).literal("2", "A");
- ordered.verify(receiver).literal("2", "B");
- ordered.verify(receiver).endRecord();
- ordered.verifyNoMoreInteractions();
+ assertMorph(receiver,
+ "" +
+ " " +
+ " " +
+ " " +
+ " " +
+ " " +
+ " " +
+ "" +
+ "" +
+ " " +
+ " " +
+ "",
+ i -> {
+ i.startRecord("1");
+ i.literal("1", "a");
+ i.literal("1", "b");
+ i.literal("2", "a");
+ i.literal("2", "b");
+ i.endRecord();
+ },
+ o -> {
+ o.get().startRecord("1");
+ o.get().literal("1", "A");
+ o.get().literal("2", "A");
+ o.get().literal("2", "B");
+ o.get().endRecord();
+ }
+ );
}
@Test
public void shouldLookupValuesInMetadata() {
- final Metamorph metamorph = InlineMorph.in(this)
- .with("")
- .with(" Hawaii")
- .with("")
- .with("")
- .with(" ")
- .with(" ")
- .with(" ")
- .with("")
- .createConnectedTo(receiver);
-
- metamorph.startRecord("1");
- metamorph.literal("data", "name");
- metamorph.endRecord();
-
- final InOrder ordered = inOrder(receiver);
- ordered.verify(receiver).startRecord("1");
- ordered.verify(receiver).literal("data", "Hawaii");
- ordered.verify(receiver).endRecord();
- ordered.verifyNoMoreInteractions();
+ assertMorph(receiver,
+ "" +
+ " Hawaii" +
+ "" +
+ "" +
+ " " +
+ " " +
+ " " +
+ "",
+ i -> {
+ i.startRecord("1");
+ i.literal("data", "name");
+ i.endRecord();
+ },
+ o -> {
+ o.get().startRecord("1");
+ o.get().literal("data", "Hawaii");
+ o.get().endRecord();
+ }
+ );
}
@Test
public void issue372_shouldFilterMissingValue() {
- final Metamorph metamorph = InlineMorph.in(this)
- .with("")
- .with(" ")
- .with(" ")
- .with(" ")
- .with(" ")
- .with(" ")
- .with(" ")
- .with("")
- .createConnectedTo(receiver);
-
- metamorph.startRecord("1");
- metamorph.literal("litA", "cat");
- metamorph.literal("litA", "dog");
- metamorph.literal("litA", "dragon");
- metamorph.endRecord();
-
- final InOrder ordered = inOrder(receiver);
- ordered.verify(receiver).startRecord("1");
- ordered.verify(receiver, times(2)).literal("litA", "mammal");
- ordered.verify(receiver).endRecord();
- ordered.verifyNoMoreInteractions();
- verifyNoMoreInteractions(receiver);
+ assertMorph(receiver,
+ "" +
+ " " +
+ " " +
+ " " +
+ " " +
+ " " +
+ " " +
+ "",
+ i -> {
+ i.startRecord("1");
+ i.literal("litA", "cat");
+ i.literal("litA", "dog");
+ i.literal("litA", "dragon");
+ i.endRecord();
+ },
+ (o, f) -> {
+ o.get().startRecord("1");
+ f.apply(2).literal("litA", "mammal");
+ o.get().endRecord();
+ }
+ );
}
}
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..0177de29a 100644
--- a/metamorph/src/test/java/org/metafacture/metamorph/functions/RegexpTest.java
+++ b/metamorph/src/test/java/org/metafacture/metamorph/functions/RegexpTest.java
@@ -16,14 +16,11 @@
package org.metafacture.metamorph.functions;
-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;
@@ -36,87 +33,85 @@
*/
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;
+
+ @Test
+ public void shouldMatchAndReplaceUsingRegularExpressions() {
+ assertMorph(receiver,
+ "" +
+ " " +
+ " " +
+ " " +
+ " " +
+ " " +
+ " " +
+ " " +
+ " " +
+ " " +
+ "",
+ i -> {
+ i.startRecord("1");
+ i.startEntity("001");
+ i.literal("", "184000");
+ i.endEntity();
+ i.endRecord();
+ },
+ o -> {
+ o.get().startRecord("1");
+ o.get().literal("subject", "resource:P184000");
+ o.get().literal("subject", "");
+ o.get().literal("subject", "184000");
+ o.get().endRecord();
+ }
+ );
+ }
+
+ @Test
+ public void shouldIgnoreEmptyMatchGroups() {
+ assertMorph(receiver,
+ "" +
+ " " +
+ " " +
+ " " +
+ "",
+ i -> {
+ i.startRecord("1");
+ i.literal("s", "aaccdd");
+ i.literal("s", "ax");
+ i.endRecord();
+ },
+ o -> {
+ o.get().startRecord("1");
+ o.get().literal("s", "ccdd");
+ o.get().endRecord();
+ }
+ );
+ }
+
+ @Test
+ public void shouldIgnoreNullValues() {
+ assertMorph(receiver,
+ "" +
+ " " +
+ " " +
+ " " +
+ "",
+ i -> {
+ i.startRecord("1");
+ i.literal("s", "aaccdd");
+ i.literal("s", null);
+ i.endRecord();
+ },
+ o -> {
+ o.get().startRecord("1");
+ o.get().literal("s", "aaccdd");
+ o.get().endRecord();
+ }
+ );
+ }
}
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..09914f374 100644
--- a/metamorph/src/test/java/org/metafacture/metamorph/functions/ScriptTest.java
+++ b/metamorph/src/test/java/org/metafacture/metamorph/functions/ScriptTest.java
@@ -16,14 +16,11 @@
package org.metafacture.metamorph.functions;
-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;
@@ -36,38 +33,36 @@
*/
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;
-
- @Test
- public void shouldExecuteJavascriptFunctions() {
- metamorph = InlineMorph.in(this)
- .with("")
- .with(" ")
- .with(" ")
- .with(" ")
- .with(" ")
- .with(" ")
- .with(" ")
- .with("")
- .createConnectedTo(receiver);
-
- metamorph.startRecord("1");
- metamorph.literal("data1", "ABC");
- metamorph.literal("data2", "ABC");
- metamorph.endRecord();
-
- final InOrder ordered = inOrder(receiver);
- ordered.verify(receiver).startRecord("1");
- ordered.verify(receiver).literal("data1", "ABC!");
- ordered.verify(receiver).literal("data2", "ABCABC");
- ordered.verify(receiver).endRecord();
- ordered.verifyNoMoreInteractions();
- }
+ @Test
+ public void shouldExecuteJavascriptFunctions() {
+ assertMorph(receiver,
+ "" +
+ " " +
+ " " +
+ " " +
+ " " +
+ " " +
+ " " +
+ "",
+ i -> {
+ i.startRecord("1");
+ i.literal("data1", "ABC");
+ i.literal("data2", "ABC");
+ i.endRecord();
+ },
+ o -> {
+ o.get().startRecord("1");
+ o.get().literal("data1", "ABC!");
+ o.get().literal("data2", "ABCABC");
+ o.get().endRecord();
+ }
+ );
+ }
}
diff --git a/metamorph/src/test/java/org/metafacture/metamorph/functions/SplitTest.java b/metamorph/src/test/java/org/metafacture/metamorph/functions/SplitTest.java
index 414a05cf7..90ada5c7a 100644
--- a/metamorph/src/test/java/org/metafacture/metamorph/functions/SplitTest.java
+++ b/metamorph/src/test/java/org/metafacture/metamorph/functions/SplitTest.java
@@ -16,13 +16,11 @@
package org.metafacture.metamorph.functions;
-import static org.mockito.Mockito.verify;
+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.Mock;
import org.mockito.junit.MockitoJUnit;
import org.mockito.junit.MockitoRule;
@@ -40,26 +38,28 @@ public final class SplitTest {
@Mock
private StreamReceiver receiver;
- private Metamorph metamorph;
-
@Test
public void issue265_shouldWorkIfLastFunctionInCombineStatement() {
- metamorph = InlineMorph.in(this)
- .with("")
- .with(" ")
- .with(" ")
- .with(" ")
- .with(" ")
- .with(" ")
- .with("")
- .createConnectedTo(receiver);
-
- metamorph.startRecord("1");
- metamorph.literal("in", "1 2");
- metamorph.endRecord();
-
- verify(receiver).literal("out", "1");
- verify(receiver).literal("out", "2");
+ assertMorph(receiver,
+ "" +
+ " " +
+ " " +
+ " " +
+ " " +
+ " " +
+ "",
+ i -> {
+ i.startRecord("1");
+ i.literal("in", "1 2");
+ i.endRecord();
+ },
+ o -> {
+ o.get().startRecord("1");
+ o.get().literal("out", "1");
+ o.get().literal("out", "2");
+ o.get().endRecord();
+ }
+ );
}
}
diff --git a/metamorph/src/test/java/org/metafacture/metamorph/functions/StringOperationsTest.java b/metamorph/src/test/java/org/metafacture/metamorph/functions/StringOperationsTest.java
index 03216f875..f2c67297c 100644
--- a/metamorph/src/test/java/org/metafacture/metamorph/functions/StringOperationsTest.java
+++ b/metamorph/src/test/java/org/metafacture/metamorph/functions/StringOperationsTest.java
@@ -21,7 +21,6 @@
import org.junit.Test;
-
/**
* tests {@link Regexp}, {@link Substring}, {@link Compose}, {@link Replace}
*
@@ -30,12 +29,10 @@
public final class StringOperationsTest {
-
private static final String VALUE1 = "Franz";
private static final String VALUE2 = "Kafka";
private static final String VALUE3 = "Josef";
-
@Test
public void testSubstring() {
final Substring substring = new Substring();
@@ -55,14 +52,14 @@ public void testSubstring() {
}
-// TODO: Can we remove this test?
-// @Test(expected=Regexp.PatternNotFoundException.class)
-// public void testRegexpExceptionOnFail() {
-// final Regexp regexp = new Regexp();
-// regexp.setMatch(VALUE2);
-// regexp.setExceptionOnFail("true");
-// regexp.process(VALUE3);
-// }
+ // TODO: Can we remove this test?
+ // @Test(expected=Regexp.PatternNotFoundException.class)
+ // public void testRegexpExceptionOnFail() {
+ // final Regexp regexp = new Regexp();
+ // regexp.setMatch(VALUE2);
+ // regexp.setExceptionOnFail("true");
+ // regexp.process(VALUE3);
+ // }
@Test
public void testCompose() {
@@ -72,7 +69,6 @@ public void testCompose() {
compose.setPrefix("");
compose.setPostfix(VALUE1);
assertEquals(VALUE2+VALUE1, compose.process(VALUE2));
-
}
@Test
diff --git a/metamorph/src/test/java/org/metafacture/metamorph/functions/SwitchNameValueTest.java b/metamorph/src/test/java/org/metafacture/metamorph/functions/SwitchNameValueTest.java
index a5a4e3b1b..34dc779dc 100644
--- a/metamorph/src/test/java/org/metafacture/metamorph/functions/SwitchNameValueTest.java
+++ b/metamorph/src/test/java/org/metafacture/metamorph/functions/SwitchNameValueTest.java
@@ -16,13 +16,11 @@
package org.metafacture.metamorph.functions;
-import static org.mockito.Mockito.verify;
+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.Mock;
import org.mockito.junit.MockitoJUnit;
import org.mockito.junit.MockitoRule;
@@ -40,25 +38,27 @@ public final class SwitchNameValueTest {
@Mock
private StreamReceiver receiver;
- private Metamorph metamorph;
-
@Test
public void issue265_shouldWorkIfLastFunctionInCombineStatement() {
- metamorph = InlineMorph.in(this)
- .with("")
- .with(" ")
- .with(" ")
- .with(" ")
- .with(" ")
- .with(" ")
- .with("")
- .createConnectedTo(receiver);
-
- metamorph.startRecord("1");
- metamorph.literal("in", "val");
- metamorph.endRecord();
-
- verify(receiver).literal("out", "val");
+ assertMorph(receiver,
+ "" +
+ " " +
+ " " +
+ " " +
+ " " +
+ " " +
+ "",
+ i -> {
+ i.startRecord("1");
+ i.literal("in", "val");
+ i.endRecord();
+ },
+ o -> {
+ o.get().startRecord("1");
+ o.get().literal("out", "val");
+ o.get().endRecord();
+ }
+ );
}
}
diff --git a/metamorph/src/test/java/org/metafacture/metamorph/functions/TestFunctionBasics.java b/metamorph/src/test/java/org/metafacture/metamorph/functions/TestFunctionBasics.java
index 112943317..e0ebe0ee4 100644
--- a/metamorph/src/test/java/org/metafacture/metamorph/functions/TestFunctionBasics.java
+++ b/metamorph/src/test/java/org/metafacture/metamorph/functions/TestFunctionBasics.java
@@ -16,14 +16,12 @@
package org.metafacture.metamorph.functions;
-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;
@@ -36,95 +34,93 @@
*/
public final class TestFunctionBasics {
- @Rule
- public final MockitoRule mockitoRule = MockitoJUnit.rule();
-
- @Mock
- private StreamReceiver receiver;
-
- private Metamorph metamorph;
-
- @Test
- public void shouldSupportFunctionChainingInDataStatements() {
- metamorph = InlineMorph.in(this)
- .with("")
- .with(" ")
- .with(" ")
- .with(" ")
- .with(" ")
- .with(" ")
- .with(" ")
- .with("")
- .createConnectedTo(receiver);
-
- metamorph.startRecord("1");
- metamorph.literal("data", " abc ");
- metamorph.endRecord();
- metamorph.startRecord("2");
- metamorph.literal("data", " abc ");
- metamorph.endRecord();
-
- final InOrder ordered = inOrder(receiver);
- ordered.verify(receiver).startRecord("1");
- ordered.verify(receiver).literal("data", "Abc");
- ordered.verify(receiver).endRecord();
- ordered.verify(receiver).startRecord("2");
- ordered.verify(receiver).literal("data", "Abc");
- ordered.verify(receiver).endRecord();
- ordered.verifyNoMoreInteractions();
- }
-
- @Test
- public void shouldSupportFunctionChainingInEntities() {
- metamorph = InlineMorph.in(this)
- .with("")
- .with(" ")
- .with(" ")
- .with(" ")
- .with(" ")
- .with(" ")
- .with(" ")
- .with(" ")
- .with(" ")
- .with("")
- .createConnectedTo(receiver);
-
- metamorph.startRecord("1");
- metamorph.literal("data", " abc ");
- metamorph.endRecord();
- metamorph.startRecord("2");
- metamorph.literal("data", " abc ");
- metamorph.endRecord();
-
- final InOrder ordered = inOrder(receiver);
- ordered.verify(receiver).startRecord("1");
- ordered.verify(receiver).literal("data", "Abc");
- ordered.verify(receiver).endRecord();
- ordered.verify(receiver).startRecord("2");
- ordered.verify(receiver).literal("data", "Abc");
- ordered.verify(receiver).endRecord();
- ordered.verifyNoMoreInteractions();
- }
-
- @Test
- public void shouldUseJavaClassesAsFunctions() {
- metamorph = InlineMorph.in(this)
- .with("")
- .with(" ")
- .with(" ")
- .with(" ")
- .with("")
- .createConnectedTo(receiver);
-
- metamorph.startRecord("1");
- metamorph.literal("data", "Aloha");
- metamorph.endRecord();
-
- final InOrder ordered = inOrder(receiver);
- ordered.verify(receiver).startRecord("1");
- ordered.verify(receiver).literal("data", "Hula Aloha");
- ordered.verify(receiver).endRecord();
- ordered.verifyNoMoreInteractions();
- }
+ @Rule
+ public final MockitoRule mockitoRule = MockitoJUnit.rule();
+
+ @Mock
+ private StreamReceiver receiver;
+
+ @Test
+ public void shouldSupportFunctionChainingInDataStatements() {
+ assertMorph(receiver,
+ "" +
+ " " +
+ " " +
+ " " +
+ " " +
+ " " +
+ " " +
+ "",
+ i -> {
+ i.startRecord("1");
+ i.literal("data", " abc ");
+ i.endRecord();
+ i.startRecord("2");
+ i.literal("data", " abc ");
+ i.endRecord();
+ },
+ o -> {
+ o.get().startRecord("1");
+ o.get().literal("data", "Abc");
+ o.get().endRecord();
+ o.get().startRecord("2");
+ o.get().literal("data", "Abc");
+ o.get().endRecord();
+ }
+ );
+ }
+
+ @Test
+ public void shouldSupportFunctionChainingInEntities() {
+ assertMorph(receiver,
+ "" +
+ " " +
+ " " +
+ " " +
+ " " +
+ " " +
+ " " +
+ " " +
+ " " +
+ "",
+ i -> {
+ i.startRecord("1");
+ i.literal("data", " abc ");
+ i.endRecord();
+ i.startRecord("2");
+ i.literal("data", " abc ");
+ i.endRecord();
+ },
+ o -> {
+ o.get().startRecord("1");
+ o.get().literal("data", "Abc");
+ o.get().endRecord();
+ o.get().startRecord("2");
+ o.get().literal("data", "Abc");
+ o.get().endRecord();
+ }
+ );
+ }
+
+ @Test
+ public void shouldUseJavaClassesAsFunctions() {
+ assertMorph(receiver,
+ "" +
+ " " +
+ " " +
+ " " +
+ "",
+ i -> {
+ i.startRecord("1");
+ i.literal("data", "Aloha");
+ i.endRecord();
+ },
+ o -> {
+ o.get().startRecord("1");
+ o.get().literal("data", "Hula Aloha");
+ o.get().endRecord();
+ }
+ );
+ }
}
diff --git a/metamorph/src/test/java/org/metafacture/metamorph/functions/TestVariousFunctions.java b/metamorph/src/test/java/org/metafacture/metamorph/functions/TestVariousFunctions.java
index 484507f52..17d8da284 100644
--- a/metamorph/src/test/java/org/metafacture/metamorph/functions/TestVariousFunctions.java
+++ b/metamorph/src/test/java/org/metafacture/metamorph/functions/TestVariousFunctions.java
@@ -16,23 +16,16 @@
package org.metafacture.metamorph.functions;
-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;
-import java.io.BufferedOutputStream;
-import java.io.IOException;
-import java.io.ObjectOutputStream;
-import java.io.OutputStream;
-
/**
* Tests for various Metamorph functions.
*
@@ -41,492 +34,490 @@
*/
public final class TestVariousFunctions {
- // TODO: This class need to be split into separate classes for each function!
-
- @Rule
- public final MockitoRule mockitoRule = MockitoJUnit.rule();
-
- @Mock
- private StreamReceiver receiver;
-
- private Metamorph metamorph;
-
- @Test
- public void testRegexpFunction() {
- metamorph = InlineMorph.in(this)
- .with("")
- .with(" ")
- .with(" ")
- .with(" ")
- .with(" ")
- .with(" ")
- .with(" ")
- .with("")
- .createConnectedTo(receiver);
-
- metamorph.startRecord("1");
- metamorph.literal("data", "Aloha!");
- metamorph.literal("data", "Oahu island, Hawaii island, Maui island");
- metamorph.literal("data", "year 1960!");
- metamorph.endRecord();
-
- final InOrder ordered = inOrder(receiver);
- ordered.verify(receiver).startRecord("1");
- ordered.verify(receiver).literal("island", "Oahu");
- ordered.verify(receiver).literal("island", "Hawaii");
- ordered.verify(receiver).literal("island", "Maui");
- ordered.verify(receiver).literal("year", "1960");
- ordered.verify(receiver).endRecord();
- ordered.verifyNoMoreInteractions();
- }
-
- @Test
- public void testIsbnFunction() {
- metamorph = InlineMorph.in(this)
- .with("")
- .with(" ")
- .with(" ")
- .with(" ")
- .with(" ")
- .with(" ")
- .with(" ")
- .with("")
- .createConnectedTo(receiver);
-
- metamorph.startRecord("1");
- metamorph.literal("isbn", "123 invalid");
- metamorph.endRecord();
-
- final InOrder ordered = inOrder(receiver);
- ordered.verify(receiver).startRecord("1");
- ordered.verify(receiver).literal("withError", "error");
- ordered.verify(receiver).endRecord();
- ordered.verifyNoMoreInteractions();
- }
-
- @Test
- public void testSplitFunction() {
- metamorph = InlineMorph.in(this)
- .with("")
- .with(" ")
- .with(" ")
- .with(" ")
- .with("")
- .createConnectedTo(receiver);
-
- metamorph.startRecord("1");
- metamorph.literal("data", "Oahu,Hawaii,Maui");
- metamorph.endRecord();
+ // TODO: This class need to be split into separate classes for each function!
- final InOrder ordered = inOrder(receiver);
- ordered.verify(receiver).startRecord("1");
- ordered.verify(receiver).literal("island", "Oahu");
- ordered.verify(receiver).literal("island", "Hawaii");
- ordered.verify(receiver).literal("island", "Maui");
- ordered.verify(receiver).endRecord();
- ordered.verifyNoMoreInteractions();
- }
+ @Rule
+ public final MockitoRule mockitoRule = MockitoJUnit.rule();
- @Test
- public void testSubstringFunction() {
- metamorph = InlineMorph.in(this)
- .with("")
- .with(" ")
- .with(" ")
- .with(" ")
- .with("")
- .createConnectedTo(receiver);
+ @Mock
+ private StreamReceiver receiver;
- metamorph.startRecord("1");
- metamorph.literal("a", "012345");
- metamorph.endRecord();
-
- final InOrder ordered = inOrder(receiver);
- ordered.verify(receiver).startRecord("1");
- ordered.verify(receiver).literal("a", "34");
- ordered.verify(receiver).endRecord();
- ordered.verifyNoMoreInteractions();
- }
-
- @Test
- public void testConstantFunction() {
- metamorph = InlineMorph.in(this)
- .with("")
- .with(" ")
- .with(" ")
- .with(" ")
- .with("")
- .createConnectedTo(receiver);
-
- metamorph.startRecord("1");
- metamorph.literal("data", "Aloha");
- metamorph.endRecord();
-
- final InOrder ordered = inOrder(receiver);
- ordered.verify(receiver).startRecord("1");
- ordered.verify(receiver).literal("data", "Hawaii");
- ordered.verify(receiver).endRecord();
- ordered.verifyNoMoreInteractions();
- }
+ @Test
+ public void testRegexpFunction() {
+ assertMorph(receiver,
+ "" +
+ " " +
+ " " +
+ " " +
+ " " +
+ " " +
+ " " +
+ "",
+ i -> {
+ i.startRecord("1");
+ i.literal("data", "Aloha!");
+ i.literal("data", "Oahu island, Hawaii island, Maui island");
+ i.literal("data", "year 1960!");
+ i.endRecord();
+ },
+ o -> {
+ o.get().startRecord("1");
+ o.get().literal("island", "Oahu");
+ o.get().literal("island", "Hawaii");
+ o.get().literal("island", "Maui");
+ o.get().literal("year", "1960");
+ o.get().endRecord();
+ }
+ );
+ }
- @Test
- public void testSetReplaceFunction() {
- metamorph = InlineMorph.in(this)
- .with("")
- .with(" ")
- .with(" ")
- .with(" ")
- .with(" ")
- .with(" ")
- .with(" ")
- .with(" ")
- .with("")
- .createConnectedTo(receiver);
+ @Test
+ public void testIsbnFunction() {
+ assertMorph(receiver,
+ "" +
+ " " +
+ " " +
+ " " +
+ " " +
+ " " +
+ " " +
+ "",
+ i -> {
+ i.startRecord("1");
+ i.literal("isbn", "123 invalid");
+ i.endRecord();
+ },
+ o -> {
+ o.get().startRecord("1");
+ o.get().literal("withError", "error");
+ o.get().endRecord();
+ }
+ );
+ }
- metamorph.startRecord("1");
- metamorph.literal("data", "dt., frz. und eng.");
- metamorph.endRecord();
+ @Test
+ public void testSplitFunction() {
+ assertMorph(receiver,
+ "" +
+ " " +
+ " " +
+ " " +
+ "",
+ i -> {
+ i.startRecord("1");
+ i.literal("data", "Oahu,Hawaii,Maui");
+ i.endRecord();
+ },
+ o -> {
+ o.get().startRecord("1");
+ o.get().literal("island", "Oahu");
+ o.get().literal("island", "Hawaii");
+ o.get().literal("island", "Maui");
+ o.get().endRecord();
+ }
+ );
+ }
- final InOrder ordered = inOrder(receiver);
- ordered.verify(receiver).startRecord("1");
- ordered.verify(receiver).literal("data", "deutsch, französich und englisch");
- ordered.verify(receiver).endRecord();
- ordered.verifyNoMoreInteractions();
- }
+ @Test
+ public void testSubstringFunction() {
+ assertMorph(receiver,
+ "" +
+ " " +
+ " " +
+ " " +
+ "",
+ i -> {
+ i.startRecord("1");
+ i.literal("a", "012345");
+ i.endRecord();
+ },
+ o -> {
+ o.get().startRecord("1");
+ o.get().literal("a", "34");
+ o.get().endRecord();
+ }
+ );
+ }
- @Test
- public void testCaseFunction() {
- metamorph = InlineMorph.in(this)
- .with("")
- .with(" ")
- .with(" ")
- .with(" ")
- .with(" ")
- .with(" ")
- .with(" ")
- .with("")
- .createConnectedTo(receiver);
+ @Test
+ public void testConstantFunction() {
+ assertMorph(receiver,
+ "" +
+ " " +
+ " " +
+ " " +
+ "",
+ i -> {
+ i.startRecord("1");
+ i.literal("data", "Aloha");
+ i.endRecord();
+ },
+ o -> {
+ o.get().startRecord("1");
+ o.get().literal("data", "Hawaii");
+ o.get().endRecord();
+ }
+ );
+ }
- metamorph.startRecord("1");
- metamorph.literal("data", "Aloha");
- metamorph.endRecord();
+ @Test
+ public void testSetReplaceFunction() {
+ assertMorph(receiver,
+ "" +
+ " " +
+ " " +
+ " " +
+ " " +
+ " " +
+ " " +
+ " " +
+ "",
+ i -> {
+ i.startRecord("1");
+ i.literal("data", "dt., frz. und eng.");
+ i.endRecord();
+ },
+ o -> {
+ o.get().startRecord("1");
+ o.get().literal("data", "deutsch, französich und englisch");
+ o.get().endRecord();
+ }
+ );
+ }
- final InOrder ordered = inOrder(receiver);
- ordered.verify(receiver).startRecord("1");
- ordered.verify(receiver).literal("data", "ALOHA");
- ordered.verify(receiver).literal("data", "aloha");
- ordered.verify(receiver).endRecord();
- ordered.verifyNoMoreInteractions();
- }
+ @Test
+ public void testCaseFunction() {
+ assertMorph(receiver,
+ "" +
+ " " +
+ " " +
+ " " +
+ " " +
+ " " +
+ " " +
+ "",
+ i -> {
+ i.startRecord("1");
+ i.literal("data", "Aloha");
+ i.endRecord();
+ },
+ o -> {
+ o.get().startRecord("1");
+ o.get().literal("data", "ALOHA");
+ o.get().literal("data", "aloha");
+ o.get().endRecord();
+ }
+ );
+ }
@Test
public void testEqualsFunction() {
- metamorph = InlineMorph.in(this)
- .with("")
- .with(" ")
- .with(" ")
- .with(" ")
- .with(" ")
- .with(" ")
- .with(" ")
- .with("")
- .createConnectedTo(receiver);
-
- metamorph.startRecord("1");
- metamorph.literal("data", "Aloha");
- metamorph.literal("data", "Hawaii");
- metamorph.endRecord();
-
- final InOrder ordered = inOrder(receiver);
- ordered.verify(receiver).startRecord("1");
- ordered.verify(receiver).literal("data1", "Aloha");
- ordered.verify(receiver).literal("data2", "Hawaii");
- ordered.verify(receiver).endRecord();
- ordered.verifyNoMoreInteractions();
+ assertMorph(receiver,
+ "" +
+ " " +
+ " " +
+ " " +
+ " " +
+ " " +
+ " " +
+ "",
+ i -> {
+ i.startRecord("1");
+ i.literal("data", "Aloha");
+ i.literal("data", "Hawaii");
+ i.endRecord();
+ },
+ o -> {
+ o.get().startRecord("1");
+ o.get().literal("data1", "Aloha");
+ o.get().literal("data2", "Hawaii");
+ o.get().endRecord();
+ }
+ );
}
@Test
public void testContainsFunction() {
- metamorph = InlineMorph.in(this)
- .with("")
- .with(" ")
- .with(" ")
- .with(" ")
- .with(" ")
- .with(" ")
- .with(" ")
- .with("")
- .createConnectedTo(receiver);
-
- metamorph.startRecord("1");
- metamorph.literal("data", "1990 Periodical MultiVolumeBook");
- metamorph.literal("data", "2013 BibliographicResource Book Series");
- metamorph.endRecord();
-
- final InOrder ordered = inOrder(receiver);
- ordered.verify(receiver).startRecord("1");
- ordered.verify(receiver).literal("data1", "1990 Periodical MultiVolumeBook");
- ordered.verify(receiver).literal("data2", "2013 BibliographicResource Book Series");
- ordered.verify(receiver).endRecord();
- ordered.verifyNoMoreInteractions();
+ assertMorph(receiver,
+ "" +
+ " " +
+ " " +
+ " " +
+ " " +
+ " " +
+ " " +
+ "",
+ i -> {
+ i.startRecord("1");
+ i.literal("data", "1990 Periodical MultiVolumeBook");
+ i.literal("data", "2013 BibliographicResource Book Series");
+ i.endRecord();
+ },
+ o -> {
+ o.get().startRecord("1");
+ o.get().literal("data1", "1990 Periodical MultiVolumeBook");
+ o.get().literal("data2", "2013 BibliographicResource Book Series");
+ o.get().endRecord();
+ }
+ );
}
- @Test
- public void testBufferFunction() {
- metamorph = InlineMorph.in(this)
- .with("")
- .with(" ")
- .with(" ")
- .with(" ")
- .with(" ")
- .with(" ")
- .with(" ")
- .with("")
- .createConnectedTo(receiver);
-
- metamorph.startRecord("0");
- metamorph.literal("d1", "Aloha");
- metamorph.endRecord();
- metamorph.startRecord("1");
- metamorph.literal("d2", "Hawaii");
- metamorph.literal("d2", "Oahu");
- metamorph.literal("d1", "Aloha");
- metamorph.endRecord();
- metamorph.startRecord("2");
- metamorph.endRecord();
- metamorph.startRecord("3");
- metamorph.literal("d1", "Aloha");
- metamorph.endRecord();
- metamorph.startRecord("4");
- metamorph.literal("d2", "to all");
- metamorph.literal("d1", "Aloha");
- metamorph.endRecord();
-
- final InOrder ordered = inOrder(receiver);
- ordered.verify(receiver).startRecord("0");
- ordered.verify(receiver).endRecord();
- ordered.verify(receiver).startRecord("1");
- ordered.verify(receiver).literal("greeting", "Aloha Hawaii");
- ordered.verify(receiver).literal("greeting", "Aloha Oahu");
- ordered.verify(receiver).endRecord();
- ordered.verify(receiver).startRecord("2");
- ordered.verify(receiver).endRecord();
- ordered.verify(receiver).startRecord("3");
- ordered.verify(receiver).endRecord();
- ordered.verify(receiver).startRecord("4");
- ordered.verify(receiver).literal("greeting", "Aloha to all");
- ordered.verify(receiver).endRecord();
- ordered.verifyNoMoreInteractions();
- }
+ @Test
+ public void testBufferFunction() {
+ assertMorph(receiver,
+ "" +
+ " " +
+ " " +
+ " " +
+ " " +
+ " " +
+ " " +
+ "",
+ i -> {
+ i.startRecord("0");
+ i.literal("d1", "Aloha");
+ i.endRecord();
+ i.startRecord("1");
+ i.literal("d2", "Hawaii");
+ i.literal("d2", "Oahu");
+ i.literal("d1", "Aloha");
+ i.endRecord();
+ i.startRecord("2");
+ i.endRecord();
+ i.startRecord("3");
+ i.literal("d1", "Aloha");
+ i.endRecord();
+ i.startRecord("4");
+ i.literal("d2", "to all");
+ i.literal("d1", "Aloha");
+ i.endRecord();
+ },
+ o -> {
+ o.get().startRecord("0");
+ o.get().endRecord();
+ o.get().startRecord("1");
+ o.get().literal("greeting", "Aloha Hawaii");
+ o.get().literal("greeting", "Aloha Oahu");
+ o.get().endRecord();
+ o.get().startRecord("2");
+ o.get().endRecord();
+ o.get().startRecord("3");
+ o.get().endRecord();
+ o.get().startRecord("4");
+ o.get().literal("greeting", "Aloha to all");
+ o.get().endRecord();
+ }
+ );
+ }
@Test
public void testOccurrenceFunction() {
- metamorph = InlineMorph.in(this)
- .with("")
- .with(" ")
- .with(" ")
- .with(" ")
- .with(" ")
- .with(" ")
- .with(" ")
- .with(" ")
- .with(" ")
- .with(" ")
- .with("")
- .createConnectedTo(receiver);
-
- metamorph.startRecord("1");
- metamorph.literal("data", "1");
- metamorph.literal("data", "2");
- metamorph.literal("data", "3");
- metamorph.endRecord();
- metamorph.startRecord("2");
- metamorph.literal("data", "1");
- metamorph.literal("data", "2");
- metamorph.literal("data", "3");
- metamorph.endRecord();
-
- final InOrder ordered = inOrder(receiver);
- ordered.verify(receiver).startRecord("1");
- ordered.verify(receiver).literal("l2", "1");
- ordered.verify(receiver).literal("2", "2");
- ordered.verify(receiver).literal("g2", "3");
- ordered.verify(receiver).endRecord();
- ordered.verify(receiver).startRecord("2");
- ordered.verify(receiver).literal("l2", "1");
- ordered.verify(receiver).literal("2", "2");
- ordered.verify(receiver).literal("g2", "3");
- ordered.verify(receiver).endRecord();
- ordered.verifyNoMoreInteractions();
+ assertMorph(receiver,
+ "" +
+ " " +
+ " " +
+ " " +
+ " " +
+ " " +
+ " " +
+ " " +
+ " " +
+ " " +
+ "",
+ i -> {
+ i.startRecord("1");
+ i.literal("data", "1");
+ i.literal("data", "2");
+ i.literal("data", "3");
+ i.endRecord();
+ i.startRecord("2");
+ i.literal("data", "1");
+ i.literal("data", "2");
+ i.literal("data", "3");
+ i.endRecord();
+ },
+ o -> {
+ o.get().startRecord("1");
+ o.get().literal("l2", "1");
+ o.get().literal("2", "2");
+ o.get().literal("g2", "3");
+ o.get().endRecord();
+ o.get().startRecord("2");
+ o.get().literal("l2", "1");
+ o.get().literal("2", "2");
+ o.get().literal("g2", "3");
+ o.get().endRecord();
+ }
+ );
}
@Test
public void testOccurrenceFunctionWithSameEntity() {
- metamorph = InlineMorph.in(this)
- .with("")
- .with(" ")
- .with(" ")
- .with(" ")
- .with(" ")
- .with(" ")
- .with(" ")
- .with(" ")
- .with(" ")
- .with(" ")
- .with("")
- .createConnectedTo(receiver);
-
- metamorph.startRecord("1");
- metamorph.startEntity("e");
- metamorph.literal("data", "1");
- metamorph.literal("data", "2");
- metamorph.literal("data", "3");
- metamorph.endEntity();
- metamorph.startEntity("e");
- metamorph.literal("data", "1");
- metamorph.literal("data", "2");
- metamorph.literal("data", "3");
- metamorph.endEntity();
- metamorph.endRecord();
-
- final InOrder ordered = inOrder(receiver);
- ordered.verify(receiver).startRecord("1");
- ordered.verify(receiver).literal("l2", "1");
- ordered.verify(receiver).literal("2", "2");
- ordered.verify(receiver).literal("g2", "3");
- ordered.verify(receiver).literal("l2", "1");
- ordered.verify(receiver).literal("2", "2");
- ordered.verify(receiver).literal("g2", "3");
- ordered.verify(receiver).endRecord();
- ordered.verifyNoMoreInteractions();
+ assertMorph(receiver,
+ "" +
+ " " +
+ " " +
+ " " +
+ " " +
+ " " +
+ " " +
+ " " +
+ " " +
+ " " +
+ "",
+ i -> {
+ i.startRecord("1");
+ i.startEntity("e");
+ i.literal("data", "1");
+ i.literal("data", "2");
+ i.literal("data", "3");
+ i.endEntity();
+ i.startEntity("e");
+ i.literal("data", "1");
+ i.literal("data", "2");
+ i.literal("data", "3");
+ i.endEntity();
+ i.endRecord();
+ },
+ o -> {
+ o.get().startRecord("1");
+ o.get().literal("l2", "1");
+ o.get().literal("2", "2");
+ o.get().literal("g2", "3");
+ o.get().literal("l2", "1");
+ o.get().literal("2", "2");
+ o.get().literal("g2", "3");
+ o.get().endRecord();
+ }
+ );
}
@Test
public void testOccurrenceFunctionWithSameEntityInNestedEntitiesShouldChangeWithInnerEntities() {
- metamorph = InlineMorph.in(this)
- .with("")
- .with(" ")
- .with(" ")
- .with(" ")
- .with(" ")
- .with(" ")
- .with(" ")
- .with(" ")
- .with(" ")
- .with(" ")
- .with("")
- .createConnectedTo(receiver);
-
- metamorph.startRecord("1");
- metamorph.startEntity("o");
- metamorph.startEntity("i");
- metamorph.literal("data", "1");
- metamorph.literal("data", "2");
- metamorph.literal("data", "3");
- metamorph.endEntity();
- metamorph.startEntity("i");
- metamorph.literal("data", "1");
- metamorph.literal("data", "2");
- metamorph.literal("data", "3");
- metamorph.endEntity();
- metamorph.endEntity();
- metamorph.endRecord();
-
- final InOrder ordered = inOrder(receiver);
- ordered.verify(receiver).startRecord("1");
- ordered.verify(receiver).literal("l2", "1");
- ordered.verify(receiver).literal("2", "2");
- ordered.verify(receiver).literal("g2", "3");
- ordered.verify(receiver).literal("l2", "1");
- ordered.verify(receiver).literal("2", "2");
- ordered.verify(receiver).literal("g2", "3");
- ordered.verify(receiver).endRecord();
- ordered.verifyNoMoreInteractions();
+ assertMorph(receiver,
+ "" +
+ " " +
+ " " +
+ " " +
+ " " +
+ " " +
+ " " +
+ " " +
+ " " +
+ " " +
+ "",
+ i -> {
+ i.startRecord("1");
+ i.startEntity("o");
+ i.startEntity("i");
+ i.literal("data", "1");
+ i.literal("data", "2");
+ i.literal("data", "3");
+ i.endEntity();
+ i.startEntity("i");
+ i.literal("data", "1");
+ i.literal("data", "2");
+ i.literal("data", "3");
+ i.endEntity();
+ i.endEntity();
+ i.endRecord();
+ },
+ o -> {
+ o.get().startRecord("1");
+ o.get().literal("l2", "1");
+ o.get().literal("2", "2");
+ o.get().literal("g2", "3");
+ o.get().literal("l2", "1");
+ o.get().literal("2", "2");
+ o.get().literal("g2", "3");
+ o.get().endRecord();
+ }
+ );
}
@Test
public void testCountFunction() {
- metamorph = InlineMorph.in(this)
- .with("")
- .with(" ")
- .with(" ")
- .with(" ")
- .with(" ")
- .with(" ")
- .with(" ")
- .with(" ")
- .with(" ")
- .with("")
- .createConnectedTo(receiver);
-
- metamorph.startRecord("0");
- metamorph.literal("datax", "1");
- metamorph.literal("datax", "2");
- metamorph.endRecord();
- metamorph.startRecord("1");
- metamorph.literal("data", "1");
- metamorph.literal("data", "2");
- metamorph.literal("data", "3");
- metamorph.endRecord();
- metamorph.startRecord("2");
- metamorph.literal("data", "1");
- metamorph.literal("data", "2");
- metamorph.endRecord();
- metamorph.startRecord("3");
- metamorph.literal("datax", "1");
- metamorph.literal("datax", "2");
- metamorph.endRecord();
-
- final InOrder ordered = inOrder(receiver);
- ordered.verify(receiver).startRecord("0");
- ordered.verify(receiver).literal("count", "2");
- ordered.verify(receiver).endRecord();
- ordered.verify(receiver).startRecord("1");
- ordered.verify(receiver).literal("count", "1");
- ordered.verify(receiver).literal("count", "2");
- ordered.verify(receiver).literal("count", "3");
- ordered.verify(receiver).endRecord();
- ordered.verify(receiver).startRecord("2");
- ordered.verify(receiver).literal("count", "1");
- ordered.verify(receiver).literal("count", "2");
- ordered.verify(receiver).endRecord();
- ordered.verify(receiver).startRecord("3");
- ordered.verify(receiver).literal("count", "2");
- ordered.verify(receiver).endRecord();
- ordered.verifyNoMoreInteractions();
+ assertMorph(receiver,
+ "" +
+ " " +
+ " " +
+ " " +
+ " " +
+ " " +
+ " " +
+ " " +
+ " " +
+ "",
+ i -> {
+ i.startRecord("0");
+ i.literal("datax", "1");
+ i.literal("datax", "2");
+ i.endRecord();
+ i.startRecord("1");
+ i.literal("data", "1");
+ i.literal("data", "2");
+ i.literal("data", "3");
+ i.endRecord();
+ i.startRecord("2");
+ i.literal("data", "1");
+ i.literal("data", "2");
+ i.endRecord();
+ i.startRecord("3");
+ i.literal("datax", "1");
+ i.literal("datax", "2");
+ i.endRecord();
+ },
+ o -> {
+ o.get().startRecord("0");
+ o.get().literal("count", "2");
+ o.get().endRecord();
+ o.get().startRecord("1");
+ o.get().literal("count", "1");
+ o.get().literal("count", "2");
+ o.get().literal("count", "3");
+ o.get().endRecord();
+ o.get().startRecord("2");
+ o.get().literal("count", "1");
+ o.get().literal("count", "2");
+ o.get().endRecord();
+ o.get().startRecord("3");
+ o.get().literal("count", "2");
+ o.get().endRecord();
+ }
+ );
}
@Test
public void testNestedCountFunction() {
- metamorph = InlineMorph.in(this)
- .with("")
- .with(" ")
- .with(" ")
- .with(" ")
- .with(" ")
- .with(" ")
- .with(" ")
- .with("")
- .createConnectedTo(receiver);
-
- metamorph.startRecord("1");
- metamorph.literal("data", "1");
- metamorph.literal("data", "2");
- metamorph.literal("data", "3");
- metamorph.endRecord();
- metamorph.startRecord("2");
- metamorph.literal("data", "1");
- metamorph.literal("data", "2");
- metamorph.endRecord();
-
- final InOrder ordered = inOrder(receiver);
- ordered.verify(receiver).startRecord("1");
- ordered.verify(receiver).literal("count", "3");
- ordered.verify(receiver).endRecord();
- ordered.verify(receiver).startRecord("2");
- ordered.verify(receiver).literal("count", "2");
- ordered.verify(receiver).endRecord();
- ordered.verifyNoMoreInteractions();
+ assertMorph(receiver,
+ "" +
+ " " +
+ " " +
+ " " +
+ " " +
+ " " +
+ " " +
+ "",
+ i -> {
+ i.startRecord("1");
+ i.literal("data", "1");
+ i.literal("data", "2");
+ i.literal("data", "3");
+ i.endRecord();
+ i.startRecord("2");
+ i.literal("data", "1");
+ i.literal("data", "2");
+ i.endRecord();
+ },
+ o -> {
+ o.get().startRecord("1");
+ o.get().literal("count", "3");
+ o.get().endRecord();
+ o.get().startRecord("2");
+ o.get().literal("count", "2");
+ o.get().endRecord();
+ }
+ );
}
}
diff --git a/metamorph/src/test/java/org/metafacture/metamorph/functions/UniqueTest.java b/metamorph/src/test/java/org/metafacture/metamorph/functions/UniqueTest.java
index 878baf3e3..4d1f91dd0 100644
--- a/metamorph/src/test/java/org/metafacture/metamorph/functions/UniqueTest.java
+++ b/metamorph/src/test/java/org/metafacture/metamorph/functions/UniqueTest.java
@@ -33,118 +33,118 @@
*/
public final class UniqueTest {
- @Rule
- public final MockitoRule mockitoRule = MockitoJUnit.rule();
+ @Rule
+ public final MockitoRule mockitoRule = MockitoJUnit.rule();
- @Mock
- private StreamReceiver receiver;
+ @Mock
+ private StreamReceiver receiver;
- @Test
- public void shouldAllowSelectingTheUniqueScope() {
- assertMorph(receiver,
- "" +
- " " +
- " " +
- " " +
- " " +
- " " +
- " " +
- "",
- i -> {
- i.startRecord("1");
- i.startEntity("e");
- i.literal("data", "d");
- i.literal("data", "d");
- i.endEntity();
- i.startEntity("e");
- i.literal("data", "d");
- i.literal("data", "d");
- i.endEntity();
- i.literal("data", "d");
- i.literal("data", "d");
- i.literal("data", "d");
- i.endRecord();
- i.startRecord("2");
- i.startEntity("e");
- i.literal("data", "d");
- i.literal("data", "d");
- i.endEntity();
- i.startEntity("e");
- i.literal("data", "d");
- i.literal("data", "d");
- i.endEntity();
- i.literal("data", "d");
- i.literal("data", "d");
- i.literal("data", "d");
- i.endRecord();
- },
- (o, f) -> {
- o.get().startRecord("1");
- f.apply(2).literal("inEntity", "d");
- o.get().literal("inRecord", "d");
- o.get().endRecord();
- o.get().startRecord("2");
- f.apply(2).literal("inEntity", "d");
- o.get().literal("inRecord", "d");
- o.get().endRecord();
- }
- );
- }
+ @Test
+ public void shouldAllowSelectingTheUniqueScope() {
+ assertMorph(receiver,
+ "" +
+ " " +
+ " " +
+ " " +
+ " " +
+ " " +
+ " " +
+ "",
+ i -> {
+ i.startRecord("1");
+ i.startEntity("e");
+ i.literal("data", "d");
+ i.literal("data", "d");
+ i.endEntity();
+ i.startEntity("e");
+ i.literal("data", "d");
+ i.literal("data", "d");
+ i.endEntity();
+ i.literal("data", "d");
+ i.literal("data", "d");
+ i.literal("data", "d");
+ i.endRecord();
+ i.startRecord("2");
+ i.startEntity("e");
+ i.literal("data", "d");
+ i.literal("data", "d");
+ i.endEntity();
+ i.startEntity("e");
+ i.literal("data", "d");
+ i.literal("data", "d");
+ i.endEntity();
+ i.literal("data", "d");
+ i.literal("data", "d");
+ i.literal("data", "d");
+ i.endRecord();
+ },
+ (o, f) -> {
+ o.get().startRecord("1");
+ f.apply(2).literal("inEntity", "d");
+ o.get().literal("inRecord", "d");
+ o.get().endRecord();
+ o.get().startRecord("2");
+ f.apply(2).literal("inEntity", "d");
+ o.get().literal("inRecord", "d");
+ o.get().endRecord();
+ }
+ );
+ }
- @Test
- public void shouldAllowSelectingTheUniquePart() {
- assertMorph(receiver,
- "" +
- " " +
- " " +
- " " +
- " " +
- " " +
- " " +
- " " +
- " " +
- " " +
- " " +
- " " +
- " " +
- " " +
- " " +
- " " +
- " " +
- " " +
- " " +
- " " +
- " " +
- " " +
- " " +
- " " +
- " " +
- " " +
- " " +
- " " +
- "",
- i -> {
- i.startRecord("1");
- i.literal("data1", "d1");
- i.literal("data1", "d1");
- i.literal("data1", "d2");
- i.literal("data1", "d2");
- i.literal("data2", "d2");
- i.literal("data2", "d2");
- i.endRecord();
- },
- o -> {
- o.get().startRecord("1");
- o.get().literal("name", "d1");
- o.get().literal("value", "d1");
- o.get().literal("both", "d1");
- o.get().literal("value", "d2");
- o.get().literal("both", "d2");
- o.get().literal("name", "d2");
- o.get().literal("both", "d2");
- o.get().endRecord();
- }
- );
- }
+ @Test
+ public void shouldAllowSelectingTheUniquePart() {
+ assertMorph(receiver,
+ "" +
+ " " +
+ " " +
+ " " +
+ " " +
+ " " +
+ " " +
+ " " +
+ " " +
+ " " +
+ " " +
+ " " +
+ " " +
+ " " +
+ " " +
+ " " +
+ " " +
+ " " +
+ " " +
+ " " +
+ " " +
+ " " +
+ " " +
+ " " +
+ " " +
+ " " +
+ " " +
+ " " +
+ "",
+ i -> {
+ i.startRecord("1");
+ i.literal("data1", "d1");
+ i.literal("data1", "d1");
+ i.literal("data1", "d2");
+ i.literal("data1", "d2");
+ i.literal("data2", "d2");
+ i.literal("data2", "d2");
+ i.endRecord();
+ },
+ o -> {
+ o.get().startRecord("1");
+ o.get().literal("name", "d1");
+ o.get().literal("value", "d1");
+ o.get().literal("both", "d1");
+ o.get().literal("value", "d2");
+ o.get().literal("both", "d2");
+ o.get().literal("name", "d2");
+ o.get().literal("both", "d2");
+ o.get().endRecord();
+ }
+ );
+ }
}