Compare commits

..

2 Commits

Author SHA1 Message Date
hummel 355fbdf042 Update Ignores 2025-05-20 19:41:56 +02:00
hummel 0d310adf01 add Surefire config in POM 2025-05-15 14:37:48 +02:00
9 changed files with 21 additions and 80 deletions

1
.gitignore vendored 100644
View File

@ -0,0 +1 @@
/.DS_Store

1
MvnDemo/.gitignore vendored
View File

@ -2,3 +2,4 @@
/.DS_Store
/.classpath
/.project
/.settings

View File

@ -1,3 +0,0 @@
/org.eclipse.core.resources.prefs
/org.eclipse.jdt.core.prefs
/org.eclipse.m2e.core.prefs

View File

@ -27,13 +27,6 @@
<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>
@ -55,6 +48,23 @@
</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
MvnDemo/src/.gitignore vendored 100644
View File

@ -0,0 +1 @@
/.DS_Store

1
MvnDemo/src/main/.gitignore vendored 100644
View File

@ -0,0 +1 @@
/.DS_Store

View File

@ -1,28 +0,0 @@
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));
}
}

View File

@ -1,5 +0,0 @@
package de.hs_mannheim.informatik.mvn.mocking;
public abstract class TextExtractor {
public abstract String extractText(String path);
}

View File

@ -1,37 +0,0 @@
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"));
}
}