Thomas Papendieck
2 years ago
commit
4d18da9bfa
4 changed files with 145 additions and 0 deletions
-
23README.md
-
61pom.xml
-
42src/main/java/de/edu/hsfulda/pmut/Berechnung.java
-
19src/test/java/de/edu/hsfulda/pmut/UebungTesten.java
@ -0,0 +1,23 @@ |
|||
# Übung Testen in Java |
|||
## Vorbereitung |
|||
- clonen Sie dieses Repository |
|||
- importieren Sie dieses Projekt als *"existing Java project"* in eine Java IDE |
|||
|
|||
## Übung1 |
|||
- Öffnen Sie die Klasse `de.edu.hsfulda.pmut.UebungTesten` |
|||
- Verwenden Sie die `assertThat()` Methode aus dem *assertj* Framework für folgende Testfälle für die Methode `convert()`: |
|||
|
|||
1. 2 -> "2" |
|||
1. 3 -> "Fizz" |
|||
1. 5 -> "Buzz" |
|||
1. 11 -> "11" |
|||
1. 15 -> "FizzBuzz" |
|||
1. 12 -> "12" (schlägt fehl) |
|||
|
|||
- Verwenden Sie die `assertThat()` Methode aus dem *assertj* Framework für folgende Testfälle für die Methode `gcd()`: |
|||
|
|||
1. 15, 20 -> 5 |
|||
1. 183, 99 -> 3 |
|||
1. 91, 1008 -> 7 |
|||
|
|||
- Ergänzen Sie die `assertThat()` Anweisungen um eine Bechreibung mit der Methode `as()` |
@ -0,0 +1,61 @@ |
|||
<project xmlns="http://maven.apache.org/POM/4.0.0" |
|||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" |
|||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> |
|||
<modelVersion>4.0.0</modelVersion> |
|||
|
|||
<groupId>de.edu.hsfulda.pmut</groupId> |
|||
<artifactId>TestenInJava</artifactId> |
|||
<version>1.0-SNAPSHOT</version> |
|||
<packaging>jar</packaging> |
|||
<properties> |
|||
<maven.compiler.target>11</maven.compiler.target> |
|||
<maven.compiler.source>11</maven.compiler.source> |
|||
<junit.jupiter.version>[5.8.1,6)</junit.jupiter.version> |
|||
<junit.platform.version>[1.8.1,2)</junit.platform.version> |
|||
<mockito.version>4.1.0</mockito.version> |
|||
<assertj.version>[3.20.2,4)</assertj.version> |
|||
</properties> |
|||
<dependencies> |
|||
<dependency> |
|||
<groupId>org.junit.jupiter</groupId> |
|||
<artifactId>junit-jupiter-api</artifactId> |
|||
<version>${junit.jupiter.version}</version> |
|||
<scope>test</scope> |
|||
</dependency> |
|||
<dependency> |
|||
<groupId>org.junit.jupiter</groupId> |
|||
<artifactId>junit-jupiter-params</artifactId> |
|||
<version>${junit.jupiter.version}</version> |
|||
<scope>test</scope> |
|||
</dependency> |
|||
<dependency> |
|||
<groupId>org.assertj</groupId> |
|||
<artifactId>assertj-core</artifactId> |
|||
<version>${assertj.version}</version> |
|||
<scope>test</scope> |
|||
</dependency> |
|||
<dependency> |
|||
<groupId>org.mockito</groupId> |
|||
<artifactId>mockito-junit-jupiter</artifactId> |
|||
<version>${mockito.version}</version> |
|||
<scope>test</scope> |
|||
</dependency> |
|||
</dependencies> |
|||
<build> |
|||
<plugins> |
|||
<plugin> |
|||
<groupId>org.apache.maven.plugins</groupId> |
|||
<artifactId>maven-surefire-plugin</artifactId> |
|||
<version>3.0.0-M5</version> |
|||
<dependencies> |
|||
<dependency> |
|||
<groupId>org.junit.jupiter</groupId> |
|||
<artifactId>junit-jupiter-engine</artifactId> |
|||
<version>${junit.jupiter.version}</version> |
|||
</dependency> |
|||
</dependencies> |
|||
</plugin> |
|||
</plugins> |
|||
</build> |
|||
|
|||
</project> |
@ -0,0 +1,42 @@ |
|||
package de.edu.hsfulda.pmut; |
|||
|
|||
import java.util.stream.Collectors; |
|||
import java.util.stream.Stream; |
|||
|
|||
public class Berechnung { |
|||
|
|||
public String convert(int currentNumber) { |
|||
String fizzBuzz = Stream.of(FizzBuzz.values()) |
|||
.map(fb -> fb.map(currentNumber)) |
|||
.collect(Collectors.joining("")); |
|||
return 0 == fizzBuzz.length() |
|||
? String.valueOf(currentNumber) |
|||
: fizzBuzz; |
|||
} |
|||
|
|||
int gcd(int a, int b) { |
|||
if (b == 0) |
|||
return a; |
|||
return gcd(b, a % b); |
|||
} |
|||
} |
|||
|
|||
enum FizzBuzz { |
|||
FIZZ(3, "Fizz"), BUZZ(5, "Buzz"), QUIX(7, "Quix"); |
|||
|
|||
private final int probeNumber; |
|||
private final String numberWord; |
|||
|
|||
FizzBuzz(int probeNumber, String numberWord) { |
|||
this.probeNumber = probeNumber; |
|||
this.numberWord = numberWord; |
|||
} |
|||
|
|||
String map(int currentNumber) { |
|||
if (0 == currentNumber % probeNumber) { |
|||
return numberWord; |
|||
} else { |
|||
return ""; |
|||
} |
|||
} |
|||
} |
@ -0,0 +1,19 @@ |
|||
package de.edu.hsfulda.pmut; |
|||
|
|||
import static org.assertj.core.api.Assertions.assertThat; |
|||
import static org.junit.jupiter.api.Assertions.*; |
|||
|
|||
import org.junit.jupiter.api.Test; |
|||
|
|||
class UebungTesten { |
|||
final Berechnung berechnung = new Berechnung(); |
|||
|
|||
@Test |
|||
void convert_number_to_digit() { |
|||
// arrange |
|||
String expected = "2"; |
|||
// act |
|||
String result = berechnung.convert(2); |
|||
// assert |
|||
} |
|||
} |
Write
Preview
Loading…
Cancel
Save
Reference in new issue