├── .gitignore
├── README.md
└── katas-java
├── .gitignore
├── argent-rose
├── Makefile
├── README.md
├── pom.xml
└── src
│ ├── main
│ └── java
│ │ └── .gitkeep
│ └── test
│ └── java
│ └── ArgentRoseTest.java
├── awkward-dependencies-examples
├── course-duration
│ ├── README.md
│ ├── pom.xml
│ └── src
│ │ ├── main
│ │ └── java
│ │ │ └── course_duration
│ │ │ └── Course.java
│ │ └── test
│ │ └── java
│ │ └── unit_tests
│ │ └── CourseTest.java
├── morning-routine
│ ├── README.md
│ ├── pom.xml
│ └── src
│ │ ├── main
│ │ └── java
│ │ │ └── morningroutine
│ │ │ └── MyMorningRoutine.java
│ │ └── test
│ │ └── java
│ │ └── unit_tests
│ │ └── MyMorningRoutineTest.java
├── problematic-discount
│ ├── README.md
│ ├── pom.xml
│ └── src
│ │ ├── main
│ │ └── java
│ │ │ └── problematic_discount
│ │ │ ├── Discount.java
│ │ │ ├── MarketingCampaign.java
│ │ │ └── Money.java
│ │ └── test
│ │ └── java
│ │ └── unit_tests
│ │ └── DiscountTest.java
└── trip-service
│ ├── README.md
│ ├── pom.xml
│ └── src
│ ├── main
│ └── java
│ │ └── trip_service
│ │ ├── exceptions
│ │ └── UserNotLoggedInException.java
│ │ ├── trip
│ │ ├── Trip.java
│ │ ├── TripDAO.java
│ │ └── TripService.java
│ │ └── user
│ │ ├── User.java
│ │ └── UserSession.java
│ └── test
│ └── java
│ └── unit_tests
│ └── TripServiceTest.java
├── birthday-greetings
├── Makefile
├── README.md
├── pom.xml
└── src
│ ├── main
│ └── java
│ │ └── birthday_greetings
│ │ └── .keep
│ └── test
│ └── java
│ └── unit_tests
│ └── BirthdayGreetingsTest.java
├── coffee-machine
├── Makefile
├── README.md
├── pom.xml
└── src
│ └── test
│ └── java
│ └── CoffeeMachineTest.java
├── fizz-buzz
├── README.md
├── pom.xml
└── src
│ ├── main
│ └── java
│ │ └── .gitkeep
│ └── test
│ └── java
│ └── FizzBuzzTest.java
├── inspiration-of-the-day
├── Makefile
├── README.md
├── pom.xml
└── src
│ ├── main
│ └── java
│ │ └── inspiration
│ │ └── .keep
│ └── test
│ └── java
│ └── unit_tests
│ └── DailyInspirationTest.java
├── luhn-test
├── README.md
├── pom.xml
└── src
│ ├── main
│ └── java
│ │ └── .gitkeep
│ └── test
│ └── java
│ └── LuhnTestTest.java
├── ohce
├── Makefile
├── README.md
├── pom.xml
└── src
│ ├── main
│ └── java
│ │ └── ohce
│ │ └── .keep
│ └── test
│ └── java
│ └── unit_tests
│ └── OhceTest.java
├── password-validator
├── Makefile
├── README.md
├── pom.xml
└── src
│ ├── main
│ └── java
│ │ └── password_validation
│ │ └── .gitkeep
│ └── test
│ └── java
│ └── password_validation
│ └── PasswordValidatorTest.java
└── tire-pressure-variation
├── Makefile
├── README.md
├── pom.xml
└── src
├── main
└── java
│ └── .keep
└── test
└── java
└── unit_tests
└── AlarmTest.java
/.gitignore:
--------------------------------------------------------------------------------
1 | .idea/
2 | .DS_Store/
3 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # Katas
2 |
3 | ## Fizz Buzz
4 | Kata to start doing TDD.
5 |
6 | ## Password validator
7 | Kata to practice the importance of examples list and test order.
8 |
9 | ## Argent Rose
10 | Kata to practice TDD heuristics.
11 |
12 | ## Tire Pressure Variation
13 | Kata to practice TDD with test doubles.
14 |
15 | ## Ohce
16 | Kata to practice TDD with test doubles.
17 |
18 | ## Inspiration of the day
19 | Kata to practice TDD with test doubles.
20 |
21 | ## Birthday Greetings
22 | Kata to practice TDD with test doubles.
23 |
24 | ## Coffee Machine
25 | Kata to practice TDD with test doubles.
26 |
27 | ## Awkward dependencies examples.
28 | Exercises to detect violations of FIRS (side-effects and sources of non determinism).
29 |
--------------------------------------------------------------------------------
/katas-java/.gitignore:
--------------------------------------------------------------------------------
1 | /bin/
2 | .classpath
3 | .project
4 | .idea
5 | *.iml
6 | target
7 |
8 | .DS_Store/
--------------------------------------------------------------------------------
/katas-java/argent-rose/Makefile:
--------------------------------------------------------------------------------
1 | help:
2 | @grep -E '^[^:]+:.*?## .*$$' $(MAKEFILE_LIST) | grep -v grep | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-30s\033[0m %s\n", $$1, $$2}' | sort
3 |
4 | mutant-tests: ## run mutation tests
5 | mvn test-compile org.pitest:pitest-maven:mutationCoverage
6 |
7 | mutant-report: ## show mutation tests report
8 | firefox target/pit-reports/index.html
9 |
10 | coverage: ## run coverage tests
11 | mvn clean test jacoco:report
12 |
13 | coverage-report: ## show coverage tests report
14 | firefox target/site/jacoco/index.html
15 |
--------------------------------------------------------------------------------
/katas-java/argent-rose/README.md:
--------------------------------------------------------------------------------
1 | # Argent Rose
2 | [Argent Rose Requirements Specification](https://gist.github.com/trikitrok/5443ec70424d567be8e7612fe71e014f)
--------------------------------------------------------------------------------
/katas-java/argent-rose/pom.xml:
--------------------------------------------------------------------------------
1 |
3 | 4.0.0
4 | com.codesai.katas-java
5 | argent-rose
6 | 0.0.1-SNAPSHOT
7 |
8 |
9 | 11
10 | 11
11 |
12 |
13 |
14 |
15 | org.hamcrest
16 | hamcrest
17 | 2.2
18 | test
19 |
20 |
21 | org.junit.jupiter
22 | junit-jupiter
23 | 5.7.0
24 | test
25 |
26 |
27 | org.junit.jupiter
28 | junit-jupiter-engine
29 | 5.7.0
30 | test
31 |
32 |
33 |
34 |
35 |
36 |
37 | org.apache.maven.plugins
38 | maven-surefire-plugin
39 | 2.22.2
40 |
41 |
42 |
43 | org.jacoco
44 | jacoco-maven-plugin
45 | 0.8.12
46 |
47 |
48 |
49 | prepare-agent
50 |
51 |
52 |
53 | report
54 | prepare-package
55 |
56 | report
57 |
58 |
59 |
60 |
61 |
62 |
63 | org.pitest
64 | pitest-maven
65 | 1.15.2
66 |
67 |
68 | org.pitest
69 | pitest-junit5-plugin
70 | 1.2.1
71 |
72 |
73 |
74 |
75 | ALL
76 |
77 | false
78 |
79 |
80 |
81 |
82 |
83 |
84 |
--------------------------------------------------------------------------------
/katas-java/argent-rose/src/main/java/.gitkeep:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Codesai/curso-tdd-java/f83760bed518d309def1e019e43f11b7014c706f/katas-java/argent-rose/src/main/java/.gitkeep
--------------------------------------------------------------------------------
/katas-java/argent-rose/src/test/java/ArgentRoseTest.java:
--------------------------------------------------------------------------------
1 | import static org.junit.jupiter.api.Assertions.assertTrue;
2 |
3 | import org.junit.jupiter.api.Test;
4 |
5 | public class ArgentRoseTest {
6 |
7 | @Test
8 | public void fix_me_and_rename_me() {
9 | assertTrue(false);
10 | }
11 | }
12 |
--------------------------------------------------------------------------------
/katas-java/awkward-dependencies-examples/course-duration/README.md:
--------------------------------------------------------------------------------
1 | # Course Duration example
2 |
3 | ## Goal
4 | Recognizing awkward dependencies (FIRS violations).
5 |
6 | 1. Examine the code and the tests that are disabled.
7 |
8 | a. Can you write those disabled unit tests?
9 |
10 | b. If not, identify which violations of FIRS make the code not unit-testable.
11 |
12 | 2. Optional: how would you design this code in order to be unit-testable?
13 |
14 | ## References
15 |
16 | [FIRST: an idea that ran away from home](https://agileotter.blogspot.com/2021/09/first-idea-that-ran-away-from-home.html), [Tim Ottinger](http://agileotter.blogspot.com/)
17 |
18 |
19 |
20 |
--------------------------------------------------------------------------------
/katas-java/awkward-dependencies-examples/course-duration/pom.xml:
--------------------------------------------------------------------------------
1 |
3 | 4.0.0
4 | course-duration
5 | course-duration
6 | 0.0.1-SNAPSHOT
7 |
8 | 11
9 | 11
10 |
11 |
12 |
13 |
14 | org.hamcrest
15 | hamcrest
16 | 2.2
17 | test
18 |
19 |
20 | org.junit.jupiter
21 | junit-jupiter
22 | 5.7.0
23 | test
24 |
25 |
26 | org.junit.jupiter
27 | junit-jupiter-engine
28 | 5.7.0
29 | test
30 |
31 |
32 | org.mockito
33 | mockito-core
34 | 3.6.28
35 | test
36 |
37 |
38 |
39 |
40 |
41 |
42 | org.apache.maven.plugins
43 | maven-surefire-plugin
44 | 2.22.2
45 |
46 |
47 |
48 | org.pitest
49 | pitest-maven
50 | 1.5.2
51 |
52 |
53 | org.pitest
54 | pitest-junit5-plugin
55 | 0.12
56 |
57 |
58 |
59 |
60 | course_duration.Course
61 |
62 |
63 | unit_tests.CourseTest
64 |
65 |
66 | java.util.logging
67 | org.apache.log4j
68 | org.slf4j
69 | org.apache.commons.logging
70 |
71 | false
72 | 3
73 |
74 |
75 |
76 |
77 |
78 |
--------------------------------------------------------------------------------
/katas-java/awkward-dependencies-examples/course-duration/src/main/java/course_duration/Course.java:
--------------------------------------------------------------------------------
1 | package course_duration;
2 |
3 | import java.util.Date;
4 |
5 | public class Course {
6 | private final String name;
7 | private long startTime;
8 | private long durationInMinutes;
9 |
10 | public Course(String name) {
11 | this.name = name;
12 | durationInMinutes = 0;
13 | }
14 |
15 | public void start() {
16 | startTime = new Date().getTime();
17 | }
18 |
19 | public void end() {
20 | var endTime = new Date().getTime();
21 | durationInMinutes = (endTime - startTime) / (1000 * 60);
22 | }
23 |
24 | public boolean isShort() {
25 | var tenMinutes = 10 * 60;
26 | return durationInMinutes < tenMinutes;
27 | }
28 |
29 | public boolean isLong() {
30 | return !isShort();
31 | }
32 |
33 | public String getTitle() {
34 | return name + " course in " + getCollege() + " college";
35 | }
36 |
37 | private String getCollege() {
38 | String college = System.getenv("COLLEGE");
39 | if (college == null) {
40 | return "not found";
41 | }
42 | return college;
43 | }
44 | }
45 |
--------------------------------------------------------------------------------
/katas-java/awkward-dependencies-examples/course-duration/src/test/java/unit_tests/CourseTest.java:
--------------------------------------------------------------------------------
1 | package unit_tests;
2 |
3 | import static org.hamcrest.MatcherAssert.assertThat;
4 | import static org.hamcrest.Matchers.is;
5 |
6 | import course_duration.Course;
7 | import org.junit.jupiter.api.BeforeEach;
8 | import org.junit.jupiter.api.Disabled;
9 | import org.junit.jupiter.api.Test;
10 |
11 | public class CourseTest {
12 |
13 | private Course course;
14 |
15 | @BeforeEach
16 | public void SetUp() {
17 | course = new Course("macramé");
18 | }
19 |
20 | @Test
21 | public void identifies_short_courses() {
22 | course.start();
23 | course.end();
24 |
25 | assertThat(course.isShort(), is(true));
26 | }
27 |
28 | @Test
29 | @Disabled("pending")
30 | public void identifies_long_courses() {
31 | }
32 |
33 | @Test
34 | @Disabled("pending")
35 | public void knows_the_course_title() {
36 | }
37 | }
38 |
39 |
--------------------------------------------------------------------------------
/katas-java/awkward-dependencies-examples/morning-routine/README.md:
--------------------------------------------------------------------------------
1 | # Morning Routine example
2 |
3 | ## Goal
4 | Recognizing awkward dependencies (FIRS violations).
5 |
6 | 1. Examine the code and identify which violations of FIRS made it not unit-testable.
7 |
8 | 2. Optional: how would you design this code in order to be unit-testable?
9 |
10 | ## References
11 |
12 | [FIRST: an idea that ran away from home](https://agileotter.blogspot.com/2021/09/first-idea-that-ran-away-from-home.html), [Tim Ottinger](http://agileotter.blogspot.com/)
13 |
14 | Based on [Morning Routine TDD kata](https://www.codurance.com/katas/morning-routine-kata)
15 |
16 |
17 |
18 |
--------------------------------------------------------------------------------
/katas-java/awkward-dependencies-examples/morning-routine/pom.xml:
--------------------------------------------------------------------------------
1 |
3 | 4.0.0
4 | morning-routine
5 | morning-routine
6 | 0.0.1-SNAPSHOT
7 |
8 | 11
9 | 11
10 |
11 |
12 |
13 |
14 | org.hamcrest
15 | hamcrest
16 | 2.2
17 | test
18 |
19 |
20 | org.junit.jupiter
21 | junit-jupiter
22 | 5.7.0
23 | test
24 |
25 |
26 | org.junit.jupiter
27 | junit-jupiter-engine
28 | 5.7.0
29 | test
30 |
31 |
32 | org.mockito
33 | mockito-core
34 | 3.6.28
35 | test
36 |
37 |
38 |
39 |
40 |
41 |
42 | org.apache.maven.plugins
43 | maven-surefire-plugin
44 | 2.22.2
45 |
46 |
47 |
48 | org.pitest
49 | pitest-maven
50 | 1.5.2
51 |
52 |
53 | org.pitest
54 | pitest-junit5-plugin
55 | 0.12
56 |
57 |
58 |
59 |
60 | morningroutine.MyMorningRoutine
61 |
62 |
63 | unit_tests.MyMorningRoutineTest
64 |
65 |
66 | java.util.logging
67 | org.apache.log4j
68 | org.slf4j
69 | org.apache.commons.logging
70 |
71 | false
72 | 3
73 |
74 |
75 |
76 |
77 |
78 |
--------------------------------------------------------------------------------
/katas-java/awkward-dependencies-examples/morning-routine/src/main/java/morningroutine/MyMorningRoutine.java:
--------------------------------------------------------------------------------
1 | package morningroutine;
2 |
3 | import java.time.LocalDateTime;
4 |
5 | public class MyMorningRoutine {
6 | public void whatShouldIDoNow() {
7 | LocalDateTime now = LocalDateTime.now();
8 | int currentHour = now.getHour();
9 | if (currentHour == 6) {
10 | System.out.println("Do exercise");
11 | } else if (currentHour == 7) {
12 | System.out.println("Read and study");
13 | } else if (currentHour == 8) {
14 | System.out.println("Have breakfast");
15 | } else {
16 | System.out.println("No activity");
17 | }
18 | }
19 | }
20 |
--------------------------------------------------------------------------------
/katas-java/awkward-dependencies-examples/morning-routine/src/test/java/unit_tests/MyMorningRoutineTest.java:
--------------------------------------------------------------------------------
1 | package unit_tests;
2 |
3 | import static org.hamcrest.MatcherAssert.assertThat;
4 | import static org.hamcrest.Matchers.is;
5 |
6 | import org.junit.jupiter.api.Test;
7 |
8 | public class MyMorningRoutineTest {
9 |
10 | @Test
11 | public void fix_me_and_rename_me() {
12 | assertThat(true, is(false));
13 | }
14 | }
15 |
16 |
--------------------------------------------------------------------------------
/katas-java/awkward-dependencies-examples/problematic-discount/README.md:
--------------------------------------------------------------------------------
1 | # Problematic Discount example
2 |
3 | ## Goal
4 | Recognizing awkward dependencies (FIRS violations).
5 |
6 | 1. Examine the code and the tests.
7 |
8 | a. What's the problem with the existing test?
9 |
10 | b. If not, identify which violations of FIRS make the code not unit-testable.
11 |
12 | 2. Optional: how would you design this code in order to be unit-testable?
13 |
14 | ## References
15 |
16 | [FIRST: an idea that ran away from home](https://agileotter.blogspot.com/2021/09/first-idea-that-ran-away-from-home.html), [Tim Ottinger](http://agileotter.blogspot.com/)
17 |
--------------------------------------------------------------------------------
/katas-java/awkward-dependencies-examples/problematic-discount/pom.xml:
--------------------------------------------------------------------------------
1 |
3 | 4.0.0
4 | problematic-discount
5 | problematic-discount
6 | 0.0.1-SNAPSHOT
7 |
8 | 11
9 | 11
10 |
11 |
12 |
13 |
14 | org.hamcrest
15 | hamcrest
16 | 2.2
17 | test
18 |
19 |
20 | org.junit.jupiter
21 | junit-jupiter
22 | 5.7.0
23 | test
24 |
25 |
26 | org.junit.jupiter
27 | junit-jupiter-engine
28 | 5.7.0
29 | test
30 |
31 |
32 | org.mockito
33 | mockito-core
34 | 3.6.28
35 | test
36 |
37 |
38 |
39 |
40 |
41 |
42 | org.apache.maven.plugins
43 | maven-surefire-plugin
44 | 2.22.2
45 |
46 |
47 |
48 | org.pitest
49 | pitest-maven
50 | 1.5.2
51 |
52 |
53 | org.pitest
54 | pitest-junit5-plugin
55 | 0.12
56 |
57 |
58 |
59 |
60 | problematic_discount.Discount
61 |
62 |
63 | unit_tests.DiscountTest
64 |
65 |
66 | java.util.logging
67 | org.apache.log4j
68 | org.slf4j
69 | org.apache.commons.logging
70 |
71 | false
72 | 3
73 |
74 |
75 |
76 |
77 |
78 |
--------------------------------------------------------------------------------
/katas-java/awkward-dependencies-examples/problematic-discount/src/main/java/problematic_discount/Discount.java:
--------------------------------------------------------------------------------
1 | package problematic_discount;
2 |
3 | public class Discount {
4 | private final MarketingCampaign marketingCampaign;
5 |
6 | public Discount() {
7 | marketingCampaign = new MarketingCampaign();
8 | }
9 |
10 | public Money discountFor(Money netPrice) {
11 | if (marketingCampaign.isCrazySalesDay()) {
12 | return netPrice.reduceBy(15);
13 | }
14 | if (netPrice.moreThan(Money.oneThousand())) {
15 | return netPrice.reduceBy(10);
16 | }
17 |
18 | if (netPrice.moreThan(Money.oneHundred()) && marketingCampaign.isActive()) {
19 | return netPrice.reduceBy(5);
20 | }
21 | return netPrice;
22 | }
23 | }
24 |
--------------------------------------------------------------------------------
/katas-java/awkward-dependencies-examples/problematic-discount/src/main/java/problematic_discount/MarketingCampaign.java:
--------------------------------------------------------------------------------
1 | package problematic_discount;
2 |
3 | import java.time.DayOfWeek;
4 | import java.time.LocalDate;
5 | import java.time.ZonedDateTime;
6 |
7 |
8 | public class MarketingCampaign {
9 | public boolean isActive() {
10 | return ZonedDateTime.now().toInstant().toEpochMilli() % 2 == 0;
11 | }
12 |
13 | public boolean isCrazySalesDay() {
14 | return LocalDate.now().getDayOfWeek().equals(DayOfWeek.FRIDAY);
15 | }
16 | }
17 |
--------------------------------------------------------------------------------
/katas-java/awkward-dependencies-examples/problematic-discount/src/main/java/problematic_discount/Money.java:
--------------------------------------------------------------------------------
1 | package problematic_discount;
2 |
3 | import java.math.BigDecimal;
4 | import java.util.Objects;
5 |
6 | public class Money {
7 | public static Money oneThousand() {
8 | return new Money(aValueOf(1000));
9 | }
10 |
11 | public static Money oneHundred() {
12 | return new Money(aValueOf(100));
13 | }
14 |
15 | public static Money amount(double amount) {
16 | return new Money(aValueOf(amount));
17 | }
18 |
19 | private final BigDecimal value;
20 |
21 | public Money(BigDecimal value) {
22 | this.value = value;
23 | }
24 |
25 | public Money reduceBy(int percentage) {
26 | BigDecimal newValue = value.multiply(aValueOf(100 - percentage)).divide(aValueOf(100));
27 | return new Money(newValue);
28 | }
29 |
30 | public boolean moreThan(Money other) {
31 | return value.compareTo(other.value) > 0;
32 | }
33 |
34 | private static BigDecimal aValueOf(int amount) {
35 | return new BigDecimal(amount);
36 | }
37 |
38 | private static BigDecimal aValueOf(double amount) {
39 | return new BigDecimal(amount);
40 | }
41 |
42 | @Override
43 | public String toString() {
44 | return "Money{" +
45 | "value=" + value +
46 | '}';
47 | }
48 |
49 | @Override
50 | public boolean equals(Object o) {
51 | if (this == o) return true;
52 | if (o == null || getClass() != o.getClass()) return false;
53 | Money money = (Money) o;
54 | return Objects.equals(value, money.value);
55 | }
56 |
57 | @Override
58 | public int hashCode() {
59 | return Objects.hashCode(value);
60 | }
61 | }
62 |
--------------------------------------------------------------------------------
/katas-java/awkward-dependencies-examples/problematic-discount/src/test/java/unit_tests/DiscountTest.java:
--------------------------------------------------------------------------------
1 | package unit_tests;
2 |
3 | import problematic_discount.Discount;
4 | import problematic_discount.Money;
5 | import org.junit.jupiter.api.Test;
6 |
7 | import static org.hamcrest.MatcherAssert.assertThat;
8 | import static org.hamcrest.Matchers.is;
9 |
10 | public class DiscountTest {
11 |
12 | @Test
13 | public void fix_me() {
14 | var discount = new Discount();
15 |
16 | var net = Money.amount(110);
17 | var total = discount.discountFor(net);
18 |
19 | assertThat(total, is(Money.amount(104.5)));
20 | }
21 | }
22 |
23 |
--------------------------------------------------------------------------------
/katas-java/awkward-dependencies-examples/trip-service/README.md:
--------------------------------------------------------------------------------
1 | # Trip Service example
2 |
3 | ## Goal
4 | Recognizing awkward dependencies (FIRS violations).
5 |
6 | 1. Examine the code of `TripService` and identify which violations of FIRS make the code not unit-testable.
7 |
8 | 2. Optional: how would you design `TripService` so that it is unit-testable?
9 |
10 | ## References
11 |
12 | [FIRST: an idea that ran away from home](https://agileotter.blogspot.com/2021/09/first-idea-that-ran-away-from-home.html), [Tim Ottinger](http://agileotter.blogspot.com/)
13 |
14 | Based on [Sandro Mancuso](https://github.com/sandromancuso)'s [Trip Service Kata](https://kata-log.rocks/trip-service-kata)
15 |
--------------------------------------------------------------------------------
/katas-java/awkward-dependencies-examples/trip-service/pom.xml:
--------------------------------------------------------------------------------
1 |
3 | 4.0.0
4 | trip-service
5 | trip-service
6 | 0.0.1-SNAPSHOT
7 |
8 | 11
9 | 11
10 |
11 |
12 |
13 |
14 | org.hamcrest
15 | hamcrest
16 | 2.2
17 | test
18 |
19 |
20 | org.junit.jupiter
21 | junit-jupiter
22 | 5.7.0
23 | test
24 |
25 |
26 | org.junit.jupiter
27 | junit-jupiter-engine
28 | 5.7.0
29 | test
30 |
31 |
32 | org.mockito
33 | mockito-core
34 | 3.6.28
35 | test
36 |
37 |
38 |
39 |
40 |
41 |
42 | org.apache.maven.plugins
43 | maven-surefire-plugin
44 | 2.22.2
45 |
46 |
47 |
48 | org.pitest
49 | pitest-maven
50 | 1.5.2
51 |
52 |
53 | org.pitest
54 | pitest-junit5-plugin
55 | 0.12
56 |
57 |
58 |
59 |
60 | trip_service.TripService
61 |
62 |
63 | unit_tests.TripServiceTest
64 |
65 |
66 | java.util.logging
67 | org.apache.log4j
68 | org.slf4j
69 | org.apache.commons.logging
70 |
71 | false
72 | 3
73 |
74 |
75 |
76 |
77 |
78 |
--------------------------------------------------------------------------------
/katas-java/awkward-dependencies-examples/trip-service/src/main/java/trip_service/exceptions/UserNotLoggedInException.java:
--------------------------------------------------------------------------------
1 | package trip_service.exceptions;
2 |
3 | public class UserNotLoggedInException extends Exception {
4 |
5 | private static final long serialVersionUID = 8959479918185637340L;
6 |
7 | }
--------------------------------------------------------------------------------
/katas-java/awkward-dependencies-examples/trip-service/src/main/java/trip_service/trip/Trip.java:
--------------------------------------------------------------------------------
1 | package trip_service.trip;
2 |
3 | import java.util.Objects;
4 | import java.util.StringJoiner;
5 |
6 | public class Trip {
7 | private final String id;
8 |
9 | public Trip(String id) {
10 | this.id = id;
11 | }
12 |
13 | @Override
14 | public String toString() {
15 | return new StringJoiner(", ", Trip.class.getSimpleName() + "[", "]")
16 | .add("tripId='" + id + "'")
17 | .toString();
18 | }
19 |
20 | @Override
21 | public boolean equals(Object o) {
22 | if (this == o) return true;
23 | if (!(o instanceof Trip)) return false;
24 | Trip trip = (Trip) o;
25 | return Objects.equals(id, trip.id);
26 | }
27 |
28 | @Override
29 | public int hashCode() {
30 | return Objects.hashCode(id);
31 | }
32 | }
33 |
--------------------------------------------------------------------------------
/katas-java/awkward-dependencies-examples/trip-service/src/main/java/trip_service/trip/TripDAO.java:
--------------------------------------------------------------------------------
1 | package trip_service.trip;
2 |
3 | import trip_service.user.User;
4 |
5 | import java.sql.*;
6 | import java.util.ArrayList;
7 | import java.util.List;
8 |
9 | public class TripDAO {
10 |
11 | private static final String DATABASE_NAME = "trips";
12 | private static final String USER = "phileas";
13 | private static final String PASS = "123456";
14 |
15 | public static List findTripsByUser(User user) {
16 | var trips = new ArrayList();
17 | try (Connection connection = DriverManager.getConnection("jdbc:mysql://localhost/" + DATABASE_NAME, USER, PASS)) {
18 |
19 | final String sql = "select id from trips where user like ?";
20 | try (PreparedStatement statement = connection.prepareStatement(sql)) {
21 | statement.setString(1, user.getName());
22 | ResultSet resultSet = statement.executeQuery();
23 |
24 | while (resultSet.next()) {
25 | trips.add(new Trip(resultSet.getString(1)));
26 | }
27 | } catch (SQLException e) {
28 | e.printStackTrace();
29 | }
30 | } catch (SQLException e) {
31 | e.printStackTrace();
32 | }
33 | return trips;
34 | }
35 | }
36 |
--------------------------------------------------------------------------------
/katas-java/awkward-dependencies-examples/trip-service/src/main/java/trip_service/trip/TripService.java:
--------------------------------------------------------------------------------
1 | package trip_service.trip;
2 |
3 | import trip_service.exceptions.UserNotLoggedInException;
4 | import trip_service.user.User;
5 | import trip_service.user.UserSession;
6 |
7 | import java.util.ArrayList;
8 | import java.util.List;
9 |
10 | public class TripService {
11 |
12 | public List getTripsByUser(User user) throws UserNotLoggedInException {
13 | List tripList = new ArrayList<>();
14 | User loggedUser = UserSession.getInstance().getLoggedUser();
15 | boolean isFriend = false;
16 | if (loggedUser != null) {
17 | for (User friend : user.getFriends()) {
18 | if (friend.equals(loggedUser)) {
19 | isFriend = true;
20 | break;
21 | }
22 | }
23 | if (isFriend) {
24 | tripList = TripDAO.findTripsByUser(user);
25 | }
26 | return tripList;
27 | } else {
28 | throw new UserNotLoggedInException();
29 | }
30 | }
31 |
32 | }
33 |
34 |
--------------------------------------------------------------------------------
/katas-java/awkward-dependencies-examples/trip-service/src/main/java/trip_service/user/User.java:
--------------------------------------------------------------------------------
1 | package trip_service.user;
2 |
3 | import trip_service.trip.Trip;
4 |
5 | import java.util.ArrayList;
6 | import java.util.List;
7 | import java.util.Objects;
8 | import java.util.StringJoiner;
9 |
10 | public class User {
11 |
12 | private final String name;
13 | private final List trips = new ArrayList<>();
14 | private final List friends = new ArrayList<>();
15 |
16 | public User(String name) {
17 | this.name = name;
18 | }
19 |
20 | public String getName() {
21 | return name;
22 | }
23 |
24 | public List getFriends() {
25 | return friends;
26 | }
27 |
28 | public void addFriend(User user) {
29 | friends.add(user);
30 | }
31 |
32 | public void addTrip(Trip trip) {
33 | trips.add(trip);
34 | }
35 |
36 | public List trips() {
37 | return trips;
38 | }
39 |
40 | @Override
41 | public String toString() {
42 | return new StringJoiner(", ", User.class.getSimpleName() + "[", "]")
43 | .add("name='" + name + "'")
44 | .add("trips=" + trips)
45 | .add("friends=" + friends)
46 | .toString();
47 | }
48 |
49 | @Override
50 | public boolean equals(Object o) {
51 | if (this == o) return true;
52 | if (!(o instanceof User)) return false;
53 | User user = (User) o;
54 | return Objects.equals(name, user.name) && Objects.equals(trips, user.trips) && Objects.equals(friends, user.friends);
55 | }
56 |
57 | @Override
58 | public int hashCode() {
59 | return Objects.hash(name, trips, friends);
60 | }
61 | }
--------------------------------------------------------------------------------
/katas-java/awkward-dependencies-examples/trip-service/src/main/java/trip_service/user/UserSession.java:
--------------------------------------------------------------------------------
1 | package trip_service.user;
2 |
3 | import java.io.IOException;
4 | import java.net.URI;
5 | import java.net.URISyntaxException;
6 | import java.net.http.HttpClient;
7 | import java.net.http.HttpRequest;
8 | import java.net.http.HttpResponse;
9 |
10 | public class UserSession {
11 |
12 | private static final UserSession userSession = new UserSession();
13 |
14 | private UserSession() {
15 | }
16 |
17 | public static UserSession getInstance() {
18 | return userSession;
19 | }
20 |
21 | public User getLoggedUser() {
22 | try {
23 | var client = HttpClient.newHttpClient();
24 | var request = HttpRequest.newBuilder()
25 | .uri(new URI("https://trip-service.nanana/client-2038/logged-user/"))
26 | .GET()
27 | .build();
28 | var response = client.send(request, HttpResponse.BodyHandlers.ofString());
29 | var name = response.body();
30 | if (name != null) {
31 | return new User(name);
32 | }
33 | return null;
34 | } catch (URISyntaxException | IOException | InterruptedException e) {
35 | throw new RuntimeException("Unable to recover session", e);
36 | }
37 | }
38 |
39 | }
40 |
41 |
--------------------------------------------------------------------------------
/katas-java/awkward-dependencies-examples/trip-service/src/test/java/unit_tests/TripServiceTest.java:
--------------------------------------------------------------------------------
1 | package unit_tests;
2 |
3 | import org.junit.jupiter.api.Test;
4 |
5 | import static org.hamcrest.MatcherAssert.assertThat;
6 | import static org.hamcrest.Matchers.is;
7 |
8 | public class TripServiceTest {
9 |
10 | @Test
11 | public void fix_me() {
12 | assertThat(true, is(false));
13 | }
14 | }
15 |
16 |
--------------------------------------------------------------------------------
/katas-java/birthday-greetings/Makefile:
--------------------------------------------------------------------------------
1 | help:
2 | @grep -E '^[^:]+:.*?## .*$$' $(MAKEFILE_LIST) | grep -v grep | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-30s\033[0m %s\n", $$1, $$2}' | sort
3 |
4 | mutant-tests: ## run mutation tests
5 | mvn test-compile org.pitest:pitest-maven:mutationCoverage
6 |
7 | mutant-report: ## show mutation tests report
8 | firefox target/pit-reports/
9 |
10 | coverage: ## run coverage tests
11 | mvn clean test jacoco:report
12 |
13 | coverage-report: ## show coverage tests report
14 | firefox target/site/jacoco/index.html
15 |
--------------------------------------------------------------------------------
/katas-java/birthday-greetings/README.md:
--------------------------------------------------------------------------------
1 | Birthday Greetings
2 | ==================
3 |
4 | As you’re a very friendly person, you would like to send a birthday note to all the friends you have. But you have a lot of friends and a bit lazy, it may take some times to write all the notes by hand.
5 |
6 | The good news is that computers can do it automatically for you.
7 |
8 | Imagine you have a flat file with all your friends :
9 |
10 | last_name, first_name, date_of_birth, email
11 | Doe, John, 1982/10/08, john.doe@foobar.com
12 | Ann, Mary, 1975/09/11, mary.ann@foobar.com
13 |
14 |
15 | And you want to send them a happy birthday email on their birthdate :
16 |
17 | Subject: Happy birthday!
18 |
19 | Happy birthday, dear !
20 |
21 |
22 | Constraints
23 | ------
24 | The signature of the only public method in the entry point must be => `void send(Date today)`
25 |
26 |
27 | Origin
28 | ------
29 |
30 | This kata is largely inspired by the work of Matteo Vaccari in [http://matteo.vaccari.name/blog/archives/154](http://matteo.vaccari.name/blog/archives/154)
31 |
--------------------------------------------------------------------------------
/katas-java/birthday-greetings/pom.xml:
--------------------------------------------------------------------------------
1 |
3 | 4.0.0
4 | com.codesai.katas-java
5 | birthday-greetings
6 | 0.0.1-SNAPSHOT
7 |
8 |
9 | 11
10 | 11
11 |
12 |
13 |
14 |
15 | org.hamcrest
16 | hamcrest
17 | 2.2
18 | test
19 |
20 |
21 | org.junit.jupiter
22 | junit-jupiter
23 | 5.7.0
24 | test
25 |
26 |
27 | org.junit.jupiter
28 | junit-jupiter-engine
29 | 5.7.0
30 | test
31 |
32 |
33 | org.mockito
34 | mockito-core
35 | 3.6.28
36 | test
37 |
38 |
39 |
40 |
41 |
42 |
43 | org.apache.maven.plugins
44 | maven-surefire-plugin
45 | 2.22.2
46 |
47 |
48 |
49 | org.jacoco
50 | jacoco-maven-plugin
51 | 0.8.12
52 |
53 |
54 |
55 | prepare-agent
56 |
57 |
58 |
59 | report
60 | prepare-package
61 |
62 | report
63 |
64 |
65 |
66 |
67 |
68 |
69 | org.pitest
70 | pitest-maven
71 | 1.15.2
72 |
73 |
74 | org.pitest
75 | pitest-junit5-plugin
76 | 1.2.1
77 |
78 |
79 |
80 |
81 | ALL
82 |
83 | false
84 |
85 |
86 |
87 |
88 |
89 |
90 |
--------------------------------------------------------------------------------
/katas-java/birthday-greetings/src/main/java/birthday_greetings/.keep:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Codesai/curso-tdd-java/f83760bed518d309def1e019e43f11b7014c706f/katas-java/birthday-greetings/src/main/java/birthday_greetings/.keep
--------------------------------------------------------------------------------
/katas-java/birthday-greetings/src/test/java/unit_tests/BirthdayGreetingsTest.java:
--------------------------------------------------------------------------------
1 | package unit_tests;
2 |
3 | import org.junit.jupiter.api.Test;
4 |
5 | import static org.hamcrest.MatcherAssert.assertThat;
6 | import static org.hamcrest.Matchers.is;
7 |
8 |
9 | public class BirthdayGreetingsTest {
10 |
11 | @Test
12 | public void fix_me_and_rename_me() {
13 | assertThat(false, is(true));
14 | }
15 | }
16 |
--------------------------------------------------------------------------------
/katas-java/coffee-machine/Makefile:
--------------------------------------------------------------------------------
1 | help:
2 | @grep -E '^[^:]+:.*?## .*$$' $(MAKEFILE_LIST) | grep -v grep | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-30s\033[0m %s\n", $$1, $$2}' | sort
3 |
4 | mutant-tests: ## run mutation tests
5 | mvn test-compile org.pitest:pitest-maven:mutationCoverage
6 |
7 | mutant-report: ## show mutation tests report
8 | firefox target/pit-reports/
9 |
10 | coverage: ## run coverage tests
11 | mvn clean test jacoco:report
12 |
13 | coverage-report: ## show coverage tests report
14 | firefox target/site/jacoco/index.html
15 |
--------------------------------------------------------------------------------
/katas-java/coffee-machine/README.md:
--------------------------------------------------------------------------------
1 | # Project
2 | In this Coffee Machine Project, your task is to implement the logic (starting from a simple class) that translates orders from customers of the coffee machine to the drink maker. Your code will use the drink maker protocol to send commands to the drink maker.
3 |
4 | ## Example of using test doubles
5 | [Use of test doubles with Mockito](https://gist.github.com/trikitrok/1573df976f090f46f3b188646de8b3be)
6 |
7 | ## Constraint
8 | ### Public interface of CoffeeMachine
9 |
10 | ```java
11 | void selectCoffee()
12 | void selectTea()
13 | void selectChocolate()
14 | void addOneSpoonOfSugar()
15 | void makeDrink()
16 | void addMoney(float amount)
17 | ```
18 |
19 | # First iteration - Making drinks
20 | In this iteration, your task is to implement the logic (starting from a simple class) that translates orders from customers of the coffee machine to the drink maker. Your code will use the drink maker protocol (see below) to send commands to the drink maker.
21 |
22 | The coffee machine can serves 3 type of drinks: tea, coffee, chocolate.
23 |
24 | ## Use cases
25 | Your product owner has delivered the stories and here they are:
26 | - The drink maker should receive the correct instructions for my coffee / tea / chocolate order.
27 | - I want to be able to send instructions to the drink maker to add one or two sugars.
28 | - When my order contains sugar the drink maker should add a stick (touillette) with it.
29 |
30 | ## Drink maker protocol
31 | The drink maker receives string commands from your code to make the drinks. It can also deliver info messages to the customer if ordered so. The instructions it receives follow this format:
32 |
33 | "T:1:0" (Drink maker makes 1 tea with 1 sugar and a stick)
34 | "H::" (Drink maker makes 1 chocolate with no sugar and therefore no stick)
35 | "C:2:0" (Drink maker makes 1 coffee with 2 sugars and a stick)
36 | "M:message-content" (Drink maker forwards any message received onto the coffee machine interface for the customer to see)
37 |
38 |
--------------------------------------------------------------------------------
/katas-java/coffee-machine/pom.xml:
--------------------------------------------------------------------------------
1 |
3 | 4.0.0
4 | com.codesai.katas-java
5 | coffee-machine
6 | 0.0.1-SNAPSHOT
7 |
8 |
9 | 11
10 | 11
11 |
12 |
13 |
14 |
15 | org.hamcrest
16 | hamcrest
17 | 2.2
18 | test
19 |
20 |
21 | org.junit.jupiter
22 | junit-jupiter
23 | 5.7.0
24 | test
25 |
26 |
27 | org.junit.jupiter
28 | junit-jupiter-engine
29 | 5.7.0
30 | test
31 |
32 |
33 | org.mockito
34 | mockito-core
35 | 3.6.28
36 | test
37 |
38 |
39 |
40 |
41 |
42 |
43 | org.apache.maven.plugins
44 | maven-surefire-plugin
45 | 2.22.2
46 |
47 |
48 |
49 | org.jacoco
50 | jacoco-maven-plugin
51 | 0.8.12
52 |
53 |
54 |
55 | prepare-agent
56 |
57 |
58 |
59 | report
60 | prepare-package
61 |
62 | report
63 |
64 |
65 |
66 |
67 |
68 |
69 | org.pitest
70 | pitest-maven
71 | 1.15.2
72 |
73 |
74 | org.pitest
75 | pitest-junit5-plugin
76 | 1.2.1
77 |
78 |
79 |
80 |
81 | ALL
82 |
83 | false
84 |
85 |
86 |
87 |
88 |
89 |
--------------------------------------------------------------------------------
/katas-java/coffee-machine/src/test/java/CoffeeMachineTest.java:
--------------------------------------------------------------------------------
1 | import static org.junit.jupiter.api.Assertions.assertTrue;
2 |
3 | import org.junit.jupiter.api.Test;
4 |
5 | public class CoffeeMachineTest {
6 |
7 | @Test
8 | public void fix_me_and_rename_me() {
9 | assertTrue(false);
10 | }
11 | }
12 |
--------------------------------------------------------------------------------
/katas-java/fizz-buzz/README.md:
--------------------------------------------------------------------------------
1 | # Goal
2 |
3 | Write a program that returns the numbers from 1 to 100. But for multiples of three return "Fizz" instead of the number and for the multiples of five return "Buzz". For numbers which are multiples of both three and five return "FizzBuzz".
4 |
5 | # Sample output
6 |
7 | 1
8 | 2
9 | Fizz
10 | 4
11 | Buzz
12 | Fizz
13 | 7
14 | 8
15 | Fizz
16 | Buzz
17 | 11
18 | Fizz
19 | 13
20 | 14
21 | FizzBuzz
22 | 16
23 | 17
24 | Fizz
25 | 19
26 | Buzz
27 | ... etc up to 100
--------------------------------------------------------------------------------
/katas-java/fizz-buzz/pom.xml:
--------------------------------------------------------------------------------
1 |
3 | 4.0.0
4 | com.codesai.katas-java
5 | fizz-buzz
6 | 0.0.1-SNAPSHOT
7 |
8 |
9 | 11
10 | 11
11 |
12 |
13 |
14 |
15 | org.hamcrest
16 | hamcrest
17 | 2.2
18 | test
19 |
20 |
21 | org.junit.jupiter
22 | junit-jupiter
23 | 5.7.0
24 | test
25 |
26 |
27 | org.junit.jupiter
28 | junit-jupiter-engine
29 | 5.7.0
30 | test
31 |
32 |
33 |
34 |
35 |
36 | org.apache.maven.plugins
37 | maven-surefire-plugin
38 | 2.22.2
39 |
40 |
41 |
42 |
--------------------------------------------------------------------------------
/katas-java/fizz-buzz/src/main/java/.gitkeep:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Codesai/curso-tdd-java/f83760bed518d309def1e019e43f11b7014c706f/katas-java/fizz-buzz/src/main/java/.gitkeep
--------------------------------------------------------------------------------
/katas-java/fizz-buzz/src/test/java/FizzBuzzTest.java:
--------------------------------------------------------------------------------
1 | import static org.junit.jupiter.api.Assertions.assertTrue;
2 |
3 | import org.junit.jupiter.api.Test;
4 |
5 | public class FizzBuzzTest {
6 |
7 | @Test
8 | public void fix_me_and_rename_me() {
9 | assertTrue(false);
10 | }
11 | }
12 |
--------------------------------------------------------------------------------
/katas-java/inspiration-of-the-day/Makefile:
--------------------------------------------------------------------------------
1 | help:
2 | @grep -E '^[^:]+:.*?## .*$$' $(MAKEFILE_LIST) | grep -v grep | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-30s\033[0m %s\n", $$1, $$2}' | sort
3 |
4 | mutant-tests: ## run mutation tests
5 | mvn test-compile org.pitest:pitest-maven:mutationCoverage
6 |
7 | mutant-report: ## show mutation tests report
8 | firefox target/pit-reports/
9 |
10 | coverage: ## run coverage tests
11 | mvn clean test jacoco:report
12 |
13 | coverage-report: ## show coverage tests report
14 | firefox target/site/jacoco/index.html
15 |
--------------------------------------------------------------------------------
/katas-java/inspiration-of-the-day/README.md:
--------------------------------------------------------------------------------
1 | Inspiration of the day
2 | ================
3 |
4 | Problem Description
5 | -------------------
6 |
7 | You are to write a service that, every time it gets executed,
8 | connects to a web service that returns a list of quotes
9 | containing a word chosen by a manager,
10 | then it randomly selects one quote from the list
11 | and sends it by WhatsApp to a random employee
12 | so that that employee gets inspired and motivated by the manager.
13 |
14 |
15 | ### Constraints
16 |
17 | The entry point of the service only has this public method: `void inspireSomeone(String word);`
--------------------------------------------------------------------------------
/katas-java/inspiration-of-the-day/pom.xml:
--------------------------------------------------------------------------------
1 |
3 | 4.0.0
4 | com.codesai.katas-java
5 | inspiration-of-the-day
6 | 0.0.1-SNAPSHOT
7 |
8 |
9 | 11
10 | 11
11 |
12 |
13 |
14 |
15 | org.hamcrest
16 | hamcrest
17 | 2.2
18 | test
19 |
20 |
21 | org.junit.jupiter
22 | junit-jupiter
23 | 5.7.0
24 | test
25 |
26 |
27 | org.junit.jupiter
28 | junit-jupiter-engine
29 | 5.7.0
30 | test
31 |
32 |
33 | org.mockito
34 | mockito-core
35 | 3.6.28
36 | test
37 |
38 |
39 |
40 |
41 |
42 |
43 | org.apache.maven.plugins
44 | maven-surefire-plugin
45 | 2.22.2
46 |
47 |
48 |
49 | org.jacoco
50 | jacoco-maven-plugin
51 | 0.8.12
52 |
53 |
54 |
55 | prepare-agent
56 |
57 |
58 |
59 | report
60 | prepare-package
61 |
62 | report
63 |
64 |
65 |
66 |
67 |
68 |
69 | org.pitest
70 | pitest-maven
71 | 1.15.2
72 |
73 |
74 | org.pitest
75 | pitest-junit5-plugin
76 | 1.2.1
77 |
78 |
79 |
80 |
81 | ALL
82 |
83 | false
84 |
85 |
86 |
87 |
88 |
89 |
90 |
--------------------------------------------------------------------------------
/katas-java/inspiration-of-the-day/src/main/java/inspiration/.keep:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Codesai/curso-tdd-java/f83760bed518d309def1e019e43f11b7014c706f/katas-java/inspiration-of-the-day/src/main/java/inspiration/.keep
--------------------------------------------------------------------------------
/katas-java/inspiration-of-the-day/src/test/java/unit_tests/DailyInspirationTest.java:
--------------------------------------------------------------------------------
1 | package unit_tests;
2 |
3 | import org.junit.jupiter.api.Test;
4 |
5 | import static org.hamcrest.MatcherAssert.assertThat;
6 | import static org.hamcrest.Matchers.is;
7 |
8 |
9 | public class DailyInspirationTest {
10 |
11 | @Test
12 | public void fix_me_and_rename_me() {
13 | assertThat(false, is(true));
14 | }
15 | }
16 |
--------------------------------------------------------------------------------
/katas-java/luhn-test/README.md:
--------------------------------------------------------------------------------
1 | ### Luhn test
2 |
3 | The Luhn test is used by some credit card companies to distinguish valid credit card numbers from what could be a random selection of digits.
4 |
5 | Those companies using credit card numbers that can be validated by the Luhn test have numbers that pass the following test:
6 |
7 | * Reverse the order of the digits in the number.
8 | * Take the first, third, ... and every other odd digit in the reversed digits and sum them to form the partial sum s1
9 | * Taking the second, fourth ... and every other even digit in the reversed digits:
10 | * Multiply each digit by two and sum the digits if the answer is greater than nine to form partial sums for the even digits
11 | * Sum the partial sums of the even digits to form s2.
12 | * If s1 + s2 ends in zero then the original number is in the form of a valid credit card number as verified by the Luhn test.
13 |
14 | ```
15 | > For example, if the trial number is 49927398716:
16 | >
17 | > 1. Reverse the digits:
18 | > 61789372994
19 | >
20 | > 2. The odd digits
21 | > Sum them
22 | > 6 + 7 + 9 + 7 + 9 + 4 = 42 = s1
23 | >
24 | > 3. The even digits:
25 | > 1, 8, 3, 2, 9
26 | > a.Multiply each one of them by 2:
27 | > 2, 16, 6, 4, 18
28 | > b. Sum the digits of each multiplication:
29 | > 2, (1 + 6), 6, 4, (1+8) -> 2, 7, 6, 4, 9
30 | > c. Sum the results of the previous operation:
31 | > 2 + 7 + 6 + 4 + 9 = 28 = s2
32 | >
33 | > 4. Finally compute s1 + s2 = 70
34 | > If the result ends in zero, it means that the digits pass the Luhn test
35 | > In the case of 49927398716 the result is 70 so it passes the Lunh test.
--------------------------------------------------------------------------------
/katas-java/luhn-test/pom.xml:
--------------------------------------------------------------------------------
1 |
3 | 4.0.0
4 | com.codesai.katas-java
5 | luhn-test
6 | 0.0.1-SNAPSHOT
7 |
8 |
9 | 11
10 | 11
11 |
12 |
13 |
14 |
15 | org.hamcrest
16 | hamcrest
17 | 2.2
18 | test
19 |
20 |
21 | org.junit.jupiter
22 | junit-jupiter
23 | 5.7.0
24 | test
25 |
26 |
27 | org.junit.jupiter
28 | junit-jupiter-engine
29 | 5.7.0
30 | test
31 |
32 |
33 |
34 |
35 |
36 | org.apache.maven.plugins
37 | maven-surefire-plugin
38 | 2.22.2
39 |
40 |
41 |
42 |
--------------------------------------------------------------------------------
/katas-java/luhn-test/src/main/java/.gitkeep:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Codesai/curso-tdd-java/f83760bed518d309def1e019e43f11b7014c706f/katas-java/luhn-test/src/main/java/.gitkeep
--------------------------------------------------------------------------------
/katas-java/luhn-test/src/test/java/LuhnTestTest.java:
--------------------------------------------------------------------------------
1 | import static org.junit.jupiter.api.Assertions.assertTrue;
2 |
3 | import org.junit.jupiter.api.Test;
4 |
5 | public class LuhnTestTest {
6 |
7 | @Test
8 | public void fix_me_and_rename_me() {
9 | assertTrue(false);
10 | }
11 | }
12 |
--------------------------------------------------------------------------------
/katas-java/ohce/Makefile:
--------------------------------------------------------------------------------
1 | help:
2 | @grep -E '^[^:]+:.*?## .*$$' $(MAKEFILE_LIST) | grep -v grep | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-30s\033[0m %s\n", $$1, $$2}' | sort
3 |
4 | mutant-tests: ## run mutation tests
5 | mvn test-compile org.pitest:pitest-maven:mutationCoverage
6 |
7 | mutant-report: ## show mutation tests report
8 | firefox target/pit-reports/
9 |
10 | coverage: ## run coverage tests
11 | mvn clean test jacoco:report
12 |
13 | coverage-report: ## show coverage tests report
14 | firefox target/site/jacoco/index.html
15 |
--------------------------------------------------------------------------------
/katas-java/ohce/README.md:
--------------------------------------------------------------------------------
1 | # Ohce Kata
2 |
3 | ## Goal
4 | A short and simple exercise to practice outside-in TDD using test doubles.
5 |
6 | ## Problem Statement For Kata
7 | Originally Posted At https://codesai.com/posts/2016/05/ohce-kata
8 |
9 | ### Your task
10 | ohce is a console application that echoes the reverse of what you input through the console.
11 | Even though it seems a silly application, ohce knows a thing or two.
12 |
13 | - When you start oche, it greets you differently depending on the current time, but only in Spanish:
14 | - Between 20 and 6 hours, ohce will greet you saying: ¡Buenas noches < your name >!
15 | - Between 6 and 12 hours, ohce will greet you saying: ¡Buenos días < your name >!
16 | - Between 12 and 20 hours, ohce will greet you saying: ¡Buenas tardes < your name >!
17 | - When you introduce a palindrome, ohce likes it and after reverse-echoing it, it adds ¡Bonita palabra!
18 | - ohce knows when to stop, you just have to write Stop! and it'll answer Adios < your name > and end.
19 |
20 | This is an example of using ohce during the morning
21 | ```
22 | $ ohce Pedro
23 | > ¡Buenos días Pedro!
24 | $ hola
25 | > aloh
26 | $ oto
27 | > oto
28 | > ¡Bonita palabra!
29 | $ stop
30 | > pots
31 | $ Stop!
32 | > Adios Pedro
33 | ```
34 |
35 | ### Constraints:
36 |
37 | The only public method in the entry point will be: `void run(String userName);`, it will start the application.
38 |
--------------------------------------------------------------------------------
/katas-java/ohce/pom.xml:
--------------------------------------------------------------------------------
1 |
3 | 4.0.0
4 | com.codesai.katas-java
5 | ohce
6 | 0.0.1-SNAPSHOT
7 |
8 |
9 | 11
10 | 11
11 |
12 |
13 |
14 |
15 | org.hamcrest
16 | hamcrest
17 | 2.2
18 | test
19 |
20 |
21 | org.junit.jupiter
22 | junit-jupiter
23 | 5.7.0
24 | test
25 |
26 |
27 | org.junit.jupiter
28 | junit-jupiter-engine
29 | 5.7.0
30 | test
31 |
32 |
33 | org.mockito
34 | mockito-core
35 | 3.6.28
36 | test
37 |
38 |
39 |
40 |
41 |
42 |
43 | org.apache.maven.plugins
44 | maven-surefire-plugin
45 | 2.22.2
46 |
47 |
48 |
49 | org.jacoco
50 | jacoco-maven-plugin
51 | 0.8.12
52 |
53 |
54 |
55 | prepare-agent
56 |
57 |
58 |
59 | report
60 | prepare-package
61 |
62 | report
63 |
64 |
65 |
66 |
67 |
68 |
69 | org.pitest
70 | pitest-maven
71 | 1.15.2
72 |
73 |
74 | org.pitest
75 | pitest-junit5-plugin
76 | 1.2.1
77 |
78 |
79 |
80 |
81 | ALL
82 |
83 | false
84 |
85 |
86 |
87 |
88 |
89 |
90 |
--------------------------------------------------------------------------------
/katas-java/ohce/src/main/java/ohce/.keep:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Codesai/curso-tdd-java/f83760bed518d309def1e019e43f11b7014c706f/katas-java/ohce/src/main/java/ohce/.keep
--------------------------------------------------------------------------------
/katas-java/ohce/src/test/java/unit_tests/OhceTest.java:
--------------------------------------------------------------------------------
1 | package unit_tests;
2 |
3 | import org.junit.jupiter.api.Test;
4 |
5 | import static org.hamcrest.MatcherAssert.assertThat;
6 | import static org.hamcrest.Matchers.is;
7 |
8 |
9 | public class OhceTest {
10 |
11 | @Test
12 | public void fix_me_and_rename_me() {
13 | assertThat(false, is(true));
14 | }
15 | }
16 |
--------------------------------------------------------------------------------
/katas-java/password-validator/Makefile:
--------------------------------------------------------------------------------
1 | help:
2 | @grep -E '^[^:]+:.*?## .*$$' $(MAKEFILE_LIST) | grep -v grep | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-30s\033[0m %s\n", $$1, $$2}' | sort
3 |
4 | mutant-tests: ## run mutation tests
5 | mvn test-compile org.pitest:pitest-maven:mutationCoverage
6 |
7 | mutant-report: ## show mutation tests report
8 | firefox target/pit-reports/
9 |
10 | coverage: ## run coverage tests
11 | mvn clean test jacoco:report
12 |
13 | coverage-report: ## show coverage tests report
14 | firefox target/site/jacoco/index.html
15 |
--------------------------------------------------------------------------------
/katas-java/password-validator/README.md:
--------------------------------------------------------------------------------
1 | # Goal
2 | We want to ensure that our users' passwords have the following rules:
3 |
4 | - Have more than 8 characters
5 | - Contains a capital letter
6 | - Contains a lowercase
7 | - Contains a number
8 | - Contains an underscore
9 |
10 | # Key
11 | This kata shows the importance of:
12 |
13 | * Selecting good examples
14 |
15 | * Selecting the test order
16 |
17 | * Having good assertions (testing only one thing and being always true)
18 |
--------------------------------------------------------------------------------
/katas-java/password-validator/pom.xml:
--------------------------------------------------------------------------------
1 |
3 | 4.0.0
4 | com.codesai.katas-java
5 | password-validator
6 | 0.0.1-SNAPSHOT
7 |
8 |
9 | 11
10 | 11
11 |
12 |
13 |
14 |
15 | org.hamcrest
16 | hamcrest
17 | 2.2
18 | test
19 |
20 |
21 | org.junit.jupiter
22 | junit-jupiter
23 | 5.7.0
24 | test
25 |
26 |
27 | org.junit.jupiter
28 | junit-jupiter-engine
29 | 5.7.0
30 | test
31 |
32 |
33 |
34 |
35 |
36 |
37 | org.apache.maven.plugins
38 | maven-surefire-plugin
39 | 2.22.2
40 |
41 |
42 |
43 | org.jacoco
44 | jacoco-maven-plugin
45 | 0.8.12
46 |
47 |
48 |
49 | prepare-agent
50 |
51 |
52 |
53 | report
54 | prepare-package
55 |
56 | report
57 |
58 |
59 |
60 |
61 |
62 |
63 | org.pitest
64 | pitest-maven
65 | 1.15.2
66 |
67 |
68 | org.pitest
69 | pitest-junit5-plugin
70 | 1.2.1
71 |
72 |
73 |
74 |
75 | ALL
76 |
77 | false
78 |
79 |
80 |
81 |
82 |
83 |
84 |
--------------------------------------------------------------------------------
/katas-java/password-validator/src/main/java/password_validation/.gitkeep:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Codesai/curso-tdd-java/f83760bed518d309def1e019e43f11b7014c706f/katas-java/password-validator/src/main/java/password_validation/.gitkeep
--------------------------------------------------------------------------------
/katas-java/password-validator/src/test/java/password_validation/PasswordValidatorTest.java:
--------------------------------------------------------------------------------
1 | package password_validation;
2 |
3 | import static org.junit.jupiter.api.Assertions.assertFalse;
4 |
5 | import org.junit.jupiter.api.Test;
6 |
7 | public class PasswordValidatorTest {
8 |
9 | @Test
10 | public void fix_me_and_rename() {
11 | assertFalse(true);
12 | }
13 | }
14 |
--------------------------------------------------------------------------------
/katas-java/tire-pressure-variation/Makefile:
--------------------------------------------------------------------------------
1 | help:
2 | @grep -E '^[^:]+:.*?## .*$$' $(MAKEFILE_LIST) | grep -v grep | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-30s\033[0m %s\n", $$1, $$2}' | sort
3 |
4 | mutant-tests: ## run mutation tests
5 | mvn test-compile org.pitest:pitest-maven:mutationCoverage
6 |
7 | mutant-report: ## show mutation tests report
8 | firefox target/pit-reports/
9 |
10 | coverage: ## run coverage tests
11 | mvn clean test jacoco:report
12 |
13 | coverage-report: ## show coverage tests report
14 | firefox target/site/jacoco/index.html
15 |
--------------------------------------------------------------------------------
/katas-java/tire-pressure-variation/README.md:
--------------------------------------------------------------------------------
1 | # Tire Pressure Monitoring System Variation
2 |
3 | [Requirements](https://gist.github.com/trikitrok/e0dccffff284511e736a53a59d853e31)
4 |
5 | ### Constraints.
6 |
7 | Aside from its constructor this is the only public method of the `Alarm` class:
8 |
9 | `void check()`
10 |
11 | `Alarm` cannot have any accessor methods to see its state, and all its fields must be private.
12 |
13 | ### Tools
14 |
15 | [Use of test doubles with Mockito](https://gist.github.com/trikitrok/1573df976f090f46f3b188646de8b3be)
16 |
--------------------------------------------------------------------------------
/katas-java/tire-pressure-variation/pom.xml:
--------------------------------------------------------------------------------
1 |
3 | 4.0.0
4 | tire-pressure-monitoring-system-variation
5 | tire-pressure-monitoring-system-variation
6 | 0.0.1-SNAPSHOT
7 |
8 | 11
9 | 11
10 |
11 |
12 |
13 |
14 | org.hamcrest
15 | hamcrest
16 | 2.2
17 | test
18 |
19 |
20 | org.junit.jupiter
21 | junit-jupiter
22 | 5.7.0
23 | test
24 |
25 |
26 | org.junit.jupiter
27 | junit-jupiter-engine
28 | 5.7.0
29 | test
30 |
31 |
32 | org.mockito
33 | mockito-core
34 | 3.6.28
35 | test
36 |
37 |
38 |
39 |
40 |
41 |
42 | org.apache.maven.plugins
43 | maven-surefire-plugin
44 | 2.22.2
45 |
46 |
47 |
48 | org.jacoco
49 | jacoco-maven-plugin
50 | 0.8.12
51 |
52 |
53 |
54 | prepare-agent
55 |
56 |
57 |
58 | report
59 | prepare-package
60 |
61 | report
62 |
63 |
64 |
65 |
66 |
67 |
68 | org.pitest
69 | pitest-maven
70 | 1.15.2
71 |
72 |
73 | org.pitest
74 | pitest-junit5-plugin
75 | 1.2.1
76 |
77 |
78 |
79 |
80 | ALL
81 |
82 | false
83 |
84 |
85 |
86 |
87 |
88 |
--------------------------------------------------------------------------------
/katas-java/tire-pressure-variation/src/main/java/.keep:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Codesai/curso-tdd-java/f83760bed518d309def1e019e43f11b7014c706f/katas-java/tire-pressure-variation/src/main/java/.keep
--------------------------------------------------------------------------------
/katas-java/tire-pressure-variation/src/test/java/unit_tests/AlarmTest.java:
--------------------------------------------------------------------------------
1 | package unit_tests;
2 |
3 | import static org.hamcrest.MatcherAssert.assertThat;
4 | import static org.hamcrest.Matchers.is;
5 |
6 | import org.junit.jupiter.api.Test;
7 |
8 | public class AlarmTest {
9 |
10 | @Test
11 | public void fix_me_and_rename_ne() {
12 | assertThat(true, is(false));
13 | }
14 | }
15 |
16 |
--------------------------------------------------------------------------------