Skip to content

Commit 4790bcd

Browse files
committed
Modified test to use mocks
1 parent efc1452 commit 4790bcd

File tree

2 files changed

+43
-17
lines changed

2 files changed

+43
-17
lines changed

pom.xml

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -202,7 +202,6 @@
202202
<groupId>junit</groupId>
203203
<artifactId>junit</artifactId>
204204
<version>${junit.version}</version>
205-
<scope>compile</scope>
206205
</dependency>
207206

208207
<dependency>
@@ -263,6 +262,20 @@
263262
<artifactId>jackson-core</artifactId>
264263
<version>2.1.4</version>
265264
</dependency>
265+
<dependency>
266+
<groupId>org.mockito</groupId>
267+
<artifactId>mockito-core</artifactId>
268+
<version>1.9.5</version>
269+
<scope>test</scope>
270+
<exclusions>
271+
<exclusion>
272+
<!-- Conflicts with the newer hamcrest version
273+
pulled in by junit -->
274+
<artifactId>hamcrest-core</artifactId>
275+
<groupId>org.hamcrest</groupId>
276+
</exclusion>
277+
</exclusions>
278+
</dependency>
266279
</dependencies>
267280

268281

src/test/java/org/culturegraph/mf/stream/pipe/Utf8NormalizerTest.java

Lines changed: 29 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,14 @@
1515
*/
1616
package org.culturegraph.mf.stream.pipe;
1717

18-
import static org.junit.Assert.assertEquals;
18+
import static org.mockito.Mockito.verify;
1919

20-
import org.culturegraph.mf.framework.DefaultObjectReceiver;
20+
import org.culturegraph.mf.framework.ObjectReceiver;
21+
import org.junit.After;
22+
import org.junit.Before;
2123
import org.junit.Test;
24+
import org.mockito.Mock;
25+
import org.mockito.MockitoAnnotations;
2226

2327
/**
2428
* Tests {@link Utf8Normalizer}.
@@ -28,26 +32,35 @@
2832
*/
2933
public final class Utf8NormalizerTest {
3034

31-
// The umlauts in this string are composed of two characters (u and ", e.g.):
32-
private static final String INPUT_STR =
35+
private static final String STRING_WITH_DIACRITICS =
3336
"Bauer, Sigmund: Über den Einfluß der Ackergeräthe auf den Reinertrag.";
3437

35-
// The umlauts in this string are individual characters:
36-
private static final String OUTPUT_STR =
38+
private static final String STRING_WITH_PRECOMPOSED_CHARS =
3739
"Bauer, Sigmund: Über den Einfluß der Ackergeräthe auf den Reinertrag.";
3840

39-
@Test
40-
public void testNormalization() {
41-
final Utf8Normalizer normalizer = new Utf8Normalizer();
41+
private Utf8Normalizer normalizer;
42+
43+
@Mock
44+
private ObjectReceiver<String> receiver;
45+
46+
@Before
47+
public void setup() {
48+
MockitoAnnotations.initMocks(this);
4249

43-
normalizer.setReceiver(new DefaultObjectReceiver<String>() {
44-
@Override
45-
public void process(final String obj) {
46-
assertEquals(OUTPUT_STR, obj);
47-
}
48-
});
50+
normalizer = new Utf8Normalizer();
51+
normalizer.setReceiver(receiver);
52+
}
53+
54+
@After
55+
public void cleanup() {
56+
normalizer.closeStream();
57+
}
58+
59+
@Test
60+
public void testShouldReplaceDiacriticsWithPrecomposedChars() {
61+
normalizer.process(STRING_WITH_DIACRITICS);
4962

50-
normalizer.process(INPUT_STR);
63+
verify(receiver).process(STRING_WITH_PRECOMPOSED_CHARS);
5164
}
5265

5366
}

0 commit comments

Comments
 (0)