Skip to content

Commit 0362c5a

Browse files
committed
Metamorph collector tests should verify that no unexpected interactions occurred.
1 parent 17b5c91 commit 0362c5a

File tree

13 files changed

+2135
-2213
lines changed

13 files changed

+2135
-2213
lines changed

metamorph/src/test/java/org/metafacture/metamorph/collectors/AllTest.java

Lines changed: 133 additions & 139 deletions
Original file line numberDiff line numberDiff line change
@@ -16,15 +16,11 @@
1616

1717
package org.metafacture.metamorph.collectors;
1818

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

2221
import org.junit.Rule;
2322
import org.junit.Test;
2423
import org.metafacture.framework.StreamReceiver;
25-
import org.metafacture.metamorph.InlineMorph;
26-
import org.metafacture.metamorph.Metamorph;
27-
import org.mockito.InOrder;
2824
import org.mockito.Mock;
2925
import org.mockito.junit.MockitoJUnit;
3026
import org.mockito.junit.MockitoRule;
@@ -42,162 +38,160 @@ public final class AllTest {
4238
@Mock
4339
private StreamReceiver receiver;
4440

45-
private Metamorph metamorph;
46-
4741
@Test
4842
public void shouldFireOnlyIfAllElementsFire() {
49-
metamorph = InlineMorph.in(this)
50-
.with("<rules>")
51-
.with(" <all>")
52-
.with(" <data source='data1' />")
53-
.with(" <data source='data2' />")
54-
.with(" </all>")
55-
.with("</rules>")
56-
.createConnectedTo(receiver);
57-
58-
metamorph.startRecord("1");
59-
metamorph.literal("data1", "A");
60-
metamorph.literal("data2", "B");
61-
metamorph.endRecord();
62-
metamorph.startRecord("2");
63-
metamorph.literal("data2", "C");
64-
metamorph.endRecord();
65-
66-
final InOrder ordered = inOrder(receiver);
67-
ordered.verify(receiver).startRecord("1");
68-
ordered.verify(receiver).literal("", "true");
69-
ordered.verify(receiver).endRecord();
70-
ordered.verify(receiver).startRecord("2");
71-
ordered.verify(receiver).endRecord();
72-
ordered.verifyNoMoreInteractions();
43+
assertMorph(receiver,
44+
"<rules>" +
45+
" <all>" +
46+
" <data source='data1' />" +
47+
" <data source='data2' />" +
48+
" </all>" +
49+
"</rules>",
50+
i -> {
51+
i.startRecord("1");
52+
i.literal("data1", "A");
53+
i.literal("data2", "B");
54+
i.endRecord();
55+
i.startRecord("2");
56+
i.literal("data2", "C");
57+
i.endRecord();
58+
},
59+
o -> {
60+
o.get().startRecord("1");
61+
o.get().literal("", "true");
62+
o.get().endRecord();
63+
o.get().startRecord("2");
64+
o.get().endRecord();
65+
}
66+
);
7367
}
7468

7569
@Test
7670
public void shouldSupportUserdefinedNameAndValue() {
77-
metamorph = InlineMorph.in(this)
78-
.with("<rules>")
79-
.with(" <all name='ALL' value='found all'>")
80-
.with(" <data source='data1' />")
81-
.with(" <data source='data2' />")
82-
.with(" </all>")
83-
.with("</rules>")
84-
.createConnectedTo(receiver);
85-
86-
metamorph.startRecord("1");
87-
metamorph.literal("data1", "A");
88-
metamorph.literal("data2", "B");
89-
metamorph.endRecord();
90-
91-
final InOrder ordered = inOrder(receiver);
92-
ordered.verify(receiver).startRecord("1");
93-
ordered.verify(receiver).literal("ALL", "found all");
94-
ordered.verify(receiver).endRecord();
95-
ordered.verifyNoMoreInteractions();
71+
assertMorph(receiver,
72+
"<rules>" +
73+
" <all name='ALL' value='found all'>" +
74+
" <data source='data1' />" +
75+
" <data source='data2' />" +
76+
" </all>" +
77+
"</rules>",
78+
i -> {
79+
i.startRecord("1");
80+
i.literal("data1", "A");
81+
i.literal("data2", "B");
82+
i.endRecord();
83+
},
84+
o -> {
85+
o.get().startRecord("1");
86+
o.get().literal("ALL", "found all");
87+
o.get().endRecord();
88+
}
89+
);
9690
}
9791

9892
@Test
9993
public void shouldFireAgainIfValueChangesAndResetIsFalse() {
100-
metamorph = InlineMorph.in(this)
101-
.with("<rules>")
102-
.with(" <all>")
103-
.with(" <data source='entity.data1' />")
104-
.with(" <data source='entity.data2' />")
105-
.with(" </all>")
106-
.with("</rules>")
107-
.createConnectedTo(receiver);
108-
109-
metamorph.startRecord("1");
110-
metamorph.startEntity("entity");
111-
metamorph.literal("data1", "A");
112-
metamorph.literal("data2", "B");
113-
metamorph.endEntity();
114-
metamorph.startEntity("entity");
115-
metamorph.literal("data2", "C");
116-
metamorph.endEntity();
117-
metamorph.endRecord();
118-
119-
final InOrder ordered = inOrder(receiver);
120-
ordered.verify(receiver).startRecord("1");
121-
ordered.verify(receiver, times(2)).literal("", "true");
122-
ordered.verify(receiver).endRecord();
123-
ordered.verifyNoMoreInteractions();
94+
assertMorph(receiver,
95+
"<rules>" +
96+
" <all>" +
97+
" <data source='entity.data1' />" +
98+
" <data source='entity.data2' />" +
99+
" </all>" +
100+
"</rules>",
101+
i -> {
102+
i.startRecord("1");
103+
i.startEntity("entity");
104+
i.literal("data1", "A");
105+
i.literal("data2", "B");
106+
i.endEntity();
107+
i.startEntity("entity");
108+
i.literal("data2", "C");
109+
i.endEntity();
110+
i.endRecord();
111+
},
112+
(o, f) -> {
113+
o.get().startRecord("1");
114+
f.apply(2).literal("", "true");
115+
o.get().endRecord();
116+
}
117+
);
124118
}
125119

126120
@Test
127121
public void shouldNotFireAgainIfOnlyOneValueChangesAndResetIsTrue() {
128-
metamorph = InlineMorph.in(this)
129-
.with("<rules>")
130-
.with(" <all reset='true'>")
131-
.with(" <data source='entity.data1' />")
132-
.with(" <data source='entity.data2' />")
133-
.with(" </all>")
134-
.with("</rules>")
135-
.createConnectedTo(receiver);
136-
137-
metamorph.startRecord("1");
138-
metamorph.startEntity("entity");
139-
metamorph.literal("data1", "A");
140-
metamorph.literal("data2", "B");
141-
metamorph.endEntity();
142-
metamorph.startEntity("entity");
143-
metamorph.literal("data2", "B");
144-
metamorph.endEntity();
145-
metamorph.endRecord();
146-
147-
final InOrder ordered = inOrder(receiver);
148-
ordered.verify(receiver).startRecord("1");
149-
ordered.verify(receiver).literal("", "true");
150-
ordered.verify(receiver).endRecord();
151-
ordered.verifyNoMoreInteractions();
122+
assertMorph(receiver,
123+
"<rules>" +
124+
" <all reset='true'>" +
125+
" <data source='entity.data1' />" +
126+
" <data source='entity.data2' />" +
127+
" </all>" +
128+
"</rules>",
129+
i -> {
130+
i.startRecord("1");
131+
i.startEntity("entity");
132+
i.literal("data1", "A");
133+
i.literal("data2", "B");
134+
i.endEntity();
135+
i.startEntity("entity");
136+
i.literal("data2", "B");
137+
i.endEntity();
138+
i.endRecord();
139+
},
140+
o -> {
141+
o.get().startRecord("1");
142+
o.get().literal("", "true");
143+
o.get().endRecord();
144+
}
145+
);
152146
}
153147

154148
@Test
155149
public void shouldNotFireIfFlushingAnIncompleteCollection() {
156-
metamorph = InlineMorph.in(this)
157-
.with("<rules>")
158-
.with(" <all flushWith='entity'>")
159-
.with(" <data source='entity.data1' />")
160-
.with(" <data source='entity.data2' />")
161-
.with(" </all>")
162-
.with("</rules>")
163-
.createConnectedTo(receiver);
164-
165-
metamorph.startRecord("1");
166-
metamorph.startEntity("entity");
167-
metamorph.literal("data1", "A");
168-
metamorph.endEntity();
169-
metamorph.endRecord();
170-
171-
final InOrder ordered = inOrder(receiver);
172-
ordered.verify(receiver).startRecord("1");
173-
ordered.verify(receiver).endRecord();
174-
ordered.verifyNoMoreInteractions();
150+
assertMorph(receiver,
151+
"<rules>" +
152+
" <all flushWith='entity'>" +
153+
" <data source='entity.data1' />" +
154+
" <data source='entity.data2' />" +
155+
" </all>" +
156+
"</rules>",
157+
i -> {
158+
i.startRecord("1");
159+
i.startEntity("entity");
160+
i.literal("data1", "A");
161+
i.endEntity();
162+
i.endRecord();
163+
},
164+
o -> {
165+
o.get().startRecord("1");
166+
o.get().endRecord();
167+
}
168+
);
175169
}
176170

177171
@Test
178172
public void shouldResetWhenEntityChangesIfSameEntity() {
179-
metamorph = InlineMorph.in(this)
180-
.with("<rules>")
181-
.with(" <all sameEntity='true'>")
182-
.with(" <data source='entity.data2' />")
183-
.with(" <data source='entity.data1' />")
184-
.with(" </all>")
185-
.with("</rules>")
186-
.createConnectedTo(receiver);
187-
188-
metamorph.startRecord("1");
189-
metamorph.startEntity("entity");
190-
metamorph.literal("data2", "A");
191-
metamorph.endEntity();
192-
metamorph.startEntity("entity");
193-
metamorph.literal("data1", "A");
194-
metamorph.endEntity();
195-
metamorph.endRecord();
196-
197-
final InOrder ordered = inOrder(receiver);
198-
ordered.verify(receiver).startRecord("1");
199-
ordered.verify(receiver).endRecord();
200-
ordered.verifyNoMoreInteractions();
173+
assertMorph(receiver,
174+
"<rules>" +
175+
" <all sameEntity='true'>" +
176+
" <data source='entity.data2' />" +
177+
" <data source='entity.data1' />" +
178+
" </all>" +
179+
"</rules>",
180+
i -> {
181+
i.startRecord("1");
182+
i.startEntity("entity");
183+
i.literal("data2", "A");
184+
i.endEntity();
185+
i.startEntity("entity");
186+
i.literal("data1", "A");
187+
i.endEntity();
188+
i.endRecord();
189+
},
190+
o -> {
191+
o.get().startRecord("1");
192+
o.get().endRecord();
193+
}
194+
);
201195
}
202196

203197
}

0 commit comments

Comments
 (0)