Skip to content

Commit 3fc965b

Browse files
committed
Metamorph unique function test should verify that no unexpected interactions occurred.
1 parent 1ffb73d commit 3fc965b

File tree

1 file changed

+101
-107
lines changed

1 file changed

+101
-107
lines changed

metamorph/src/test/java/org/metafacture/metamorph/functions/UniqueTest.java

Lines changed: 101 additions & 107 deletions
Original file line numberDiff line numberDiff line change
@@ -15,15 +15,11 @@
1515
*/
1616
package org.metafacture.metamorph.functions;
1717

18-
import static org.mockito.Mockito.inOrder;
19-
import static org.mockito.Mockito.times;
18+
import static org.metafacture.metamorph.TestHelpers.assertMorph;
2019

2120
import org.junit.Rule;
2221
import org.junit.Test;
2322
import org.metafacture.framework.StreamReceiver;
24-
import org.metafacture.metamorph.InlineMorph;
25-
import org.metafacture.metamorph.Metamorph;
26-
import org.mockito.InOrder;
2723
import org.mockito.Mock;
2824
import org.mockito.junit.MockitoJUnit;
2925
import org.mockito.junit.MockitoRule;
@@ -42,114 +38,112 @@ public final class UniqueTest {
4238
@Mock
4339
private StreamReceiver receiver;
4440

45-
private Metamorph metamorph;
46-
4741
@Test
4842
public void shouldAllowSelectingTheUniqueScope() {
49-
metamorph = InlineMorph.in(this)
50-
.with("<rules>")
51-
.with(" <data source='data' name='inRecord'>")
52-
.with(" <unique />")
53-
.with(" </data>")
54-
.with(" <data source='e.data' name='inEntity'>")
55-
.with(" <unique in='entity' />")
56-
.with(" </data>")
57-
.with("</rules>")
58-
.createConnectedTo(receiver);
59-
60-
metamorph.startRecord("1");
61-
metamorph.startEntity("e");
62-
metamorph.literal("data", "d");
63-
metamorph.literal("data", "d");
64-
metamorph.endEntity();
65-
metamorph.startEntity("e");
66-
metamorph.literal("data", "d");
67-
metamorph.literal("data", "d");
68-
metamorph.endEntity();
69-
metamorph.literal("data", "d");
70-
metamorph.literal("data", "d");
71-
metamorph.literal("data", "d");
72-
metamorph.endRecord();
73-
metamorph.startRecord("2");
74-
metamorph.startEntity("e");
75-
metamorph.literal("data", "d");
76-
metamorph.literal("data", "d");
77-
metamorph.endEntity();
78-
metamorph.startEntity("e");
79-
metamorph.literal("data", "d");
80-
metamorph.literal("data", "d");
81-
metamorph.endEntity();
82-
metamorph.literal("data", "d");
83-
metamorph.literal("data", "d");
84-
metamorph.literal("data", "d");
85-
metamorph.endRecord();
86-
87-
final InOrder ordered = inOrder(receiver);
88-
ordered.verify(receiver).startRecord("1");
89-
ordered.verify(receiver, times(2)).literal("inEntity", "d");
90-
ordered.verify(receiver).literal("inRecord", "d");
91-
ordered.verify(receiver).endRecord();
92-
ordered.verify(receiver).startRecord("2");
93-
ordered.verify(receiver, times(2)).literal("inEntity", "d");
94-
ordered.verify(receiver).literal("inRecord", "d");
95-
ordered.verify(receiver).endRecord();
96-
ordered.verifyNoMoreInteractions();
43+
assertMorph(receiver,
44+
"<rules>" +
45+
" <data source='data' name='inRecord'>" +
46+
" <unique />" +
47+
" </data>" +
48+
" <data source='e.data' name='inEntity'>" +
49+
" <unique in='entity' />" +
50+
" </data>" +
51+
"</rules>",
52+
i -> {
53+
i.startRecord("1");
54+
i.startEntity("e");
55+
i.literal("data", "d");
56+
i.literal("data", "d");
57+
i.endEntity();
58+
i.startEntity("e");
59+
i.literal("data", "d");
60+
i.literal("data", "d");
61+
i.endEntity();
62+
i.literal("data", "d");
63+
i.literal("data", "d");
64+
i.literal("data", "d");
65+
i.endRecord();
66+
i.startRecord("2");
67+
i.startEntity("e");
68+
i.literal("data", "d");
69+
i.literal("data", "d");
70+
i.endEntity();
71+
i.startEntity("e");
72+
i.literal("data", "d");
73+
i.literal("data", "d");
74+
i.endEntity();
75+
i.literal("data", "d");
76+
i.literal("data", "d");
77+
i.literal("data", "d");
78+
i.endRecord();
79+
},
80+
(o, f) -> {
81+
o.get().startRecord("1");
82+
f.apply(2).literal("inEntity", "d");
83+
o.get().literal("inRecord", "d");
84+
o.get().endRecord();
85+
o.get().startRecord("2");
86+
f.apply(2).literal("inEntity", "d");
87+
o.get().literal("inRecord", "d");
88+
o.get().endRecord();
89+
}
90+
);
9791
}
9892

9993
@Test
10094
public void shouldAllowSelectingTheUniquePart() {
101-
metamorph = InlineMorph.in(this)
102-
.with("<rules>")
103-
.with(" <group name='name'>")
104-
.with(" <group>")
105-
.with(" <data source='data1' />")
106-
.with(" <data source='data2' />")
107-
.with(" <postprocess>")
108-
.with(" <unique part='name' />")
109-
.with(" </postprocess>")
110-
.with(" </group>")
111-
.with(" </group>")
112-
.with(" <group name='value'>")
113-
.with(" <group>")
114-
.with(" <data source='data1' />")
115-
.with(" <data source='data2' />")
116-
.with(" <postprocess>")
117-
.with(" <unique part='value' />")
118-
.with(" </postprocess>")
119-
.with(" </group>")
120-
.with(" </group>")
121-
.with(" <group name='both'>")
122-
.with(" <group>")
123-
.with(" <data source='data1' />")
124-
.with(" <data source='data2' />")
125-
.with(" <postprocess>")
126-
.with(" <unique part='name-value' />")
127-
.with(" </postprocess>")
128-
.with(" </group>")
129-
.with(" </group>")
130-
.with("</rules>")
131-
.createConnectedTo(receiver);
132-
133-
metamorph.startRecord("1");
134-
metamorph.literal("data1", "d1");
135-
metamorph.literal("data1", "d1");
136-
metamorph.literal("data1", "d2");
137-
metamorph.literal("data1", "d2");
138-
metamorph.literal("data2", "d2");
139-
metamorph.literal("data2", "d2");
140-
metamorph.endRecord();
141-
142-
final InOrder ordered = inOrder(receiver);
143-
ordered.verify(receiver).startRecord("1");
144-
ordered.verify(receiver).literal("name", "d1");
145-
ordered.verify(receiver).literal("value", "d1");
146-
ordered.verify(receiver).literal("both", "d1");
147-
ordered.verify(receiver).literal("value", "d2");
148-
ordered.verify(receiver).literal("both", "d2");
149-
ordered.verify(receiver).literal("name", "d2");
150-
ordered.verify(receiver).literal("both", "d2");
151-
ordered.verify(receiver).endRecord();
152-
ordered.verifyNoMoreInteractions();
95+
assertMorph(receiver,
96+
"<rules>" +
97+
" <group name='name'>" +
98+
" <group>" +
99+
" <data source='data1' />" +
100+
" <data source='data2' />" +
101+
" <postprocess>" +
102+
" <unique part='name' />" +
103+
" </postprocess>" +
104+
" </group>" +
105+
" </group>" +
106+
" <group name='value'>" +
107+
" <group>" +
108+
" <data source='data1' />" +
109+
" <data source='data2' />" +
110+
" <postprocess>" +
111+
" <unique part='value' />" +
112+
" </postprocess>" +
113+
" </group>" +
114+
" </group>" +
115+
" <group name='both'>" +
116+
" <group>" +
117+
" <data source='data1' />" +
118+
" <data source='data2' />" +
119+
" <postprocess>" +
120+
" <unique part='name-value' />" +
121+
" </postprocess>" +
122+
" </group>" +
123+
" </group>" +
124+
"</rules>",
125+
i -> {
126+
i.startRecord("1");
127+
i.literal("data1", "d1");
128+
i.literal("data1", "d1");
129+
i.literal("data1", "d2");
130+
i.literal("data1", "d2");
131+
i.literal("data2", "d2");
132+
i.literal("data2", "d2");
133+
i.endRecord();
134+
},
135+
o -> {
136+
o.get().startRecord("1");
137+
o.get().literal("name", "d1");
138+
o.get().literal("value", "d1");
139+
o.get().literal("both", "d1");
140+
o.get().literal("value", "d2");
141+
o.get().literal("both", "d2");
142+
o.get().literal("name", "d2");
143+
o.get().literal("both", "d2");
144+
o.get().endRecord();
145+
}
146+
);
153147
}
154148

155149
}

0 commit comments

Comments
 (0)