Compare commits
1 Commits
Author | SHA1 | Date |
---|---|---|
|
4fe9ff36e9 |
|
@ -1 +0,0 @@
|
|||
/.DS_Store
|
|
@ -2,4 +2,3 @@
|
|||
/.DS_Store
|
||||
/.classpath
|
||||
/.project
|
||||
/.settings
|
||||
|
|
|
@ -0,0 +1,3 @@
|
|||
/org.eclipse.core.resources.prefs
|
||||
/org.eclipse.jdt.core.prefs
|
||||
/org.eclipse.m2e.core.prefs
|
|
@ -27,6 +27,13 @@
|
|||
<scope>test</scope>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.mockito</groupId>
|
||||
<artifactId>mockito-core</artifactId>
|
||||
<version>5.17.0</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.apache.logging.log4j</groupId>
|
||||
<artifactId>log4j-core</artifactId>
|
||||
|
@ -48,23 +55,6 @@
|
|||
</configuration>
|
||||
</plugin>
|
||||
|
||||
<!-- Testing -->
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-surefire-plugin</artifactId>
|
||||
<version>3.5.3</version>
|
||||
<configuration>
|
||||
<includes>
|
||||
<include>**/*Test.java</include>
|
||||
</includes>
|
||||
<excludes>
|
||||
<exclude>**/IntegrationTest.java</exclude>
|
||||
</excludes>
|
||||
<parallel>classes</parallel>
|
||||
<threadCount>4</threadCount>
|
||||
</configuration>
|
||||
</plugin>
|
||||
|
||||
<!-- JAR creation -->
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
|
|
|
@ -1 +0,0 @@
|
|||
/.DS_Store
|
|
@ -1 +0,0 @@
|
|||
/.DS_Store
|
|
@ -0,0 +1,28 @@
|
|||
package de.hs_mannheim.informatik.mvn.mocking;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
public class CountWords {
|
||||
|
||||
public static void main(String[] args) {
|
||||
var cnt = new CountWords().countWords("Der schnelle braune Fuchs springt über den mueden Hund. Der Hund liegt nur muede herum.");
|
||||
cnt.entrySet().stream().forEach(e -> System.out.println(e.getKey() + ": " + e.getValue()));
|
||||
}
|
||||
|
||||
public Map<String, Integer> countWords(String text) {
|
||||
var words = text.toLowerCase().split("\\W+");
|
||||
var cnt = new HashMap<String, Integer>();
|
||||
|
||||
for (String w : words) {
|
||||
cnt.put(w, cnt.getOrDefault(w, 0) + 1);
|
||||
}
|
||||
|
||||
return cnt;
|
||||
}
|
||||
|
||||
public Map<String, Integer> countWordsFromFile(TextExtractor te, String path) {
|
||||
return this.countWords(te.extractText(path));
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,5 @@
|
|||
package de.hs_mannheim.informatik.mvn.mocking;
|
||||
|
||||
public abstract class TextExtractor {
|
||||
public abstract String extractText(String path);
|
||||
}
|
|
@ -0,0 +1,37 @@
|
|||
package de.hs_mannheim.informatik.mvn.mocking;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
import static org.mockito.Mockito.*;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.mockito.Mockito;
|
||||
|
||||
class TextExtractorTest {
|
||||
|
||||
@Test
|
||||
void testCountWords() {
|
||||
CountWords cw = new CountWords();
|
||||
var cnt = cw.countWords("hallo welt");
|
||||
|
||||
assertEquals(1, cnt.get("hallo"));
|
||||
assertEquals(1, cnt.get("welt"));
|
||||
|
||||
assertEquals(null, cnt.get("unbekannt"));
|
||||
}
|
||||
|
||||
@Test
|
||||
void testCountWordsFromFile() {
|
||||
CountWords cw = new CountWords();
|
||||
|
||||
TextExtractor teMock = Mockito.mock(TextExtractor.class);
|
||||
when(teMock.extractText("/tmp/test.pdf")).thenReturn("hallo welt");
|
||||
|
||||
var cnt = cw.countWordsFromFile(teMock, "/tmp/test.pdf");
|
||||
|
||||
assertEquals(1, cnt.get("hallo"));
|
||||
assertEquals(1, cnt.get("welt"));
|
||||
|
||||
assertEquals(null, cnt.get("unbekannt"));
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in New Issue