Skip to content

Commit 159f048

Browse files
authored
Merge pull request #341 from metafacture/339-metamorph-verify-no-more-interactions
Metamorph tests verify that no unexpected interactions occurred (first batch).
2 parents 688dc71 + 4b76491 commit 159f048

File tree

9 files changed

+673
-627
lines changed

9 files changed

+673
-627
lines changed

metamorph/build.gradle

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,3 +39,10 @@ sourceSets {
3939
output.resourcesDir = sourceSets.test.java.outputDir
4040
}
4141
}
42+
43+
test {
44+
testLogging {
45+
showStandardStreams = true
46+
exceptionFormat = 'full'
47+
}
48+
}
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
/*
2+
* Copyright 2020 hbz NRW
3+
*
4+
* Licensed under the Apache License, Version 2.0 the "License";
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
package org.metafacture.metamorph;
17+
18+
import org.metafacture.framework.StreamReceiver;
19+
import org.mockito.InOrder;
20+
import org.mockito.Mockito;
21+
import org.mockito.exceptions.base.MockitoAssertionError;
22+
23+
import java.util.function.BiConsumer;
24+
import java.util.function.Consumer;
25+
import java.util.function.IntFunction;
26+
import java.util.function.Supplier;
27+
28+
/**
29+
* Helper functions for Metamorph tests.
30+
*
31+
* @author Jens Wille
32+
*/
33+
public final class TestHelpers {
34+
35+
public static void assertMorph(final StreamReceiver receiver, final String morphDef, final Consumer<Metamorph> in, final Consumer<Supplier<StreamReceiver>> out) {
36+
assertMorph(receiver, morphDef, in, (s, f) -> out.accept(s));
37+
}
38+
39+
public static void assertMorph(final StreamReceiver receiver, final String morphDef, final Consumer<Metamorph> in, final BiConsumer<Supplier<StreamReceiver>, IntFunction<StreamReceiver>> out) {
40+
final Metamorph metamorph = InlineMorph.in(TestHelpers.class).with(morphDef).createConnectedTo(receiver);
41+
final InOrder ordered = Mockito.inOrder(receiver);
42+
43+
try {
44+
in.accept(metamorph);
45+
out.accept(() -> ordered.verify(receiver), i -> ordered.verify(receiver, Mockito.times(i)));
46+
47+
ordered.verifyNoMoreInteractions();
48+
Mockito.verifyNoMoreInteractions(receiver);
49+
}
50+
catch (final MockitoAssertionError e) {
51+
System.out.println(Mockito.mockingDetails(receiver).printInvocations());
52+
throw e;
53+
}
54+
}
55+
56+
}

0 commit comments

Comments
 (0)