Skip to content

Commit 6aa3f47

Browse files
committed
add PIT
1 parent 08bc944 commit 6aa3f47

File tree

3 files changed

+66
-0
lines changed

3 files changed

+66
-0
lines changed

spring-boot-example/pom.xml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -453,6 +453,14 @@
453453
<version>1.2.1</version>
454454
</dependency>
455455
</dependencies>
456+
<configuration>
457+
<targetClasses>
458+
<param>de.rieckpil.blog.pit.*</param>
459+
</targetClasses>
460+
<targetTests>
461+
<param>de.rieckpil.blog.pit.*Test</param>
462+
</targetTests>
463+
</configuration>
456464
</plugin>
457465
</plugins>
458466
</build>
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
package de.rieckpil.blog.pit;
2+
3+
import java.util.Set;
4+
5+
public class FraudDetector {
6+
7+
private static final Set<String> HIGH_RISK_COUNTRIES =
8+
Set.of("WONDERLAND", "MARS", "URANUS");
9+
10+
public boolean isFraudulentTransaction(double amount, String country) {
11+
// Any transaction above 10k is flagged
12+
if (amount > 10_000) {
13+
return true;
14+
}
15+
16+
// Transactions from high-risk countries are flagged
17+
if (HIGH_RISK_COUNTRIES.contains(country)) {
18+
return true;
19+
}
20+
21+
return false;
22+
}
23+
}
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
package de.rieckpil.blog.pit;
2+
3+
import org.junit.jupiter.api.Test;
4+
5+
import static org.junit.jupiter.api.Assertions.*;
6+
7+
import static org.assertj.core.api.Assertions.assertThat;
8+
import static org.junit.jupiter.api.Assertions.*;
9+
import static org.mockito.ArgumentMatchers.*;
10+
import static org.mockito.Mockito.when;
11+
import static org.mockito.Mockito.verify;
12+
13+
class FraudDetectorTest {
14+
15+
@Test
16+
void testHighAmountTransaction() {
17+
FraudDetector detector = new FraudDetector();
18+
19+
assertTrue(detector.isFraudulentTransaction(15_000, "USA"));
20+
}
21+
22+
@Test
23+
void testHighRiskCountryTransaction() {
24+
FraudDetector detector = new FraudDetector();
25+
26+
assertTrue(detector.isFraudulentTransaction(500, "MARS"));
27+
}
28+
29+
@Test
30+
void testSafeTransaction() {
31+
FraudDetector cut = new FraudDetector();
32+
33+
assertFalse(cut.isFraudulentTransaction(200, "USA"));
34+
}
35+
}

0 commit comments

Comments
 (0)