Skip to content

Commit d4f0b58

Browse files
author
coursar
committed
feat(maven-junit)
1 parent 0697b04 commit d4f0b58

File tree

9 files changed

+145
-1
lines changed

9 files changed

+145
-1
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010

1111
2.1. [x] [Примитивные типы данных, условия](data)
1212

13-
2.2. [ ] [Системы сборки и авто-тесты](maven-junit)
13+
2.2. [x] [Системы сборки и авто-тесты](maven-junit)
1414

1515
2.3. [ ] [Циклы, параметризованные тесты и аннотации](params)
1616

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<project xmlns="http://maven.apache.org/POM/4.0.0"
3+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
5+
<modelVersion>4.0.0</modelVersion>
6+
7+
<groupId>ru.netology</groupId>
8+
<artifactId>bonus-calculator</artifactId>
9+
<version>1.0-SNAPSHOT</version>
10+
11+
<properties>
12+
<maven.compiler.source>11</maven.compiler.source>
13+
<maven.compiler.target>11</maven.compiler.target>
14+
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
15+
</properties>
16+
17+
<dependencies>
18+
<dependency>
19+
<groupId>org.junit.jupiter</groupId>
20+
<artifactId>junit-jupiter</artifactId>
21+
<version>5.4.2</version>
22+
<scope>test</scope>
23+
</dependency>
24+
</dependencies>
25+
26+
<build>
27+
<plugins>
28+
<plugin>
29+
<groupId>org.apache.maven.plugins</groupId>
30+
<artifactId>maven-surefire-plugin</artifactId>
31+
<version>2.22.2</version>
32+
</plugin>
33+
</plugins>
34+
</build>
35+
</project>
36+
37+
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
public class BonusService {
2+
public long calculate(long amount, boolean registered) {
3+
int percent = registered ? 3 : 1;
4+
long bonus = amount * percent / 100 / 100;
5+
long limit = 500;
6+
if (bonus > limit) {
7+
bonus = limit;
8+
}
9+
return bonus;
10+
}
11+
}
12+
13+
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
public class Main {
2+
public static void main(String[] args) {
3+
BonusService service = new BonusService();
4+
5+
// подготавливаем данные:
6+
long amount = 1000_60;
7+
boolean registered = true;
8+
long expected = 30;
9+
10+
// вызываем целевой метод:
11+
long actual = service.calculate(amount, registered);
12+
13+
// производим проверку (сравниваем ожидаемый и фактический):
14+
// если true - то PASS
15+
// если false - то FAIL
16+
boolean passed = expected == actual;
17+
18+
// выводим результат
19+
System.out.println(passed);
20+
}
21+
}
22+
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
import static org.junit.jupiter.api.Assertions.*;
2+
3+
class BonusServiceTest {
4+
5+
@org.junit.jupiter.api.Test
6+
void shouldCalculateForRegisteredAndUnderLimit() {
7+
BonusService service = new BonusService();
8+
9+
// подготавливаем данные:
10+
long amount = 1000_60;
11+
boolean registered = true;
12+
long expected = 30;
13+
14+
// вызываем целевой метод:
15+
long actual = service.calculate(amount, registered);
16+
17+
// производим проверку (сравниваем ожидаемый и фактический):
18+
assertEquals(expected, actual);
19+
}
20+
21+
@org.junit.jupiter.api.Test
22+
void shouldCalculateForRegisteredAndOverLimit() {
23+
BonusService service = new BonusService();
24+
25+
// подготавливаем данные:
26+
long amount = 1_000_000_60;
27+
boolean registered = true;
28+
long expected = 500;
29+
30+
// вызываем целевой метод:
31+
long actual = service.calculate(amount, registered);
32+
33+
// производим проверку (сравниваем ожидаемый и фактический):
34+
assertEquals(expected, actual);
35+
}
36+
}
37+

maven-junit/bonus-handmade/out/.gitkeep

Whitespace-only changes.
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
public class BonusService {
2+
public long calculate(long amount, boolean registered) {
3+
int percent = registered ? 3 : 1;
4+
long bonus = amount * percent / 100 / 100;
5+
long limit = 500;
6+
if (bonus > limit) {
7+
bonus = limit;
8+
}
9+
return bonus;
10+
}
11+
}
12+
13+
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
public class Main {
2+
public static void main(String[] args) {
3+
BonusService service = new BonusService();
4+
5+
// подготавливаем данные:
6+
long amount = 1000_60;
7+
boolean registered = true;
8+
long expected = 30;
9+
10+
// вызываем целевой метод:
11+
long actual = service.calculate(amount, registered);
12+
13+
// производим проверку (сравниваем ожидаемый и фактический):
14+
// если true - то PASS
15+
// если false - то FAIL
16+
boolean passed = expected == actual;
17+
18+
// выводим результат
19+
System.out.println(passed);
20+
}
21+
}
22+

maven-junit/xml.md

Whitespace-only changes.

0 commit comments

Comments
 (0)