├── .gitignore
├── README.md
├── amber
├── .gitignore
├── README.md
├── img
│ ├── java22-arrival.png
│ └── project-amber-timeline.png
├── pom.xml
├── src
│ ├── main
│ │ └── java
│ │ │ └── com
│ │ │ └── example
│ │ │ ├── Sandbox.java
│ │ │ ├── collectionFactoryMethods
│ │ │ └── ImageConverter.java
│ │ │ ├── fileMismatch
│ │ │ └── FileEqualsChecker.java
│ │ │ ├── files
│ │ │ └── FileService.java
│ │ │ ├── httpClient
│ │ │ └── TodoRepository.java
│ │ │ ├── indent
│ │ │ ├── NoIndentTextFormatter.java
│ │ │ └── TextBlockFormatter.java
│ │ │ ├── optionalOrElseThrow
│ │ │ ├── DataProvider.java
│ │ │ └── DataService.java
│ │ │ ├── patternMatchingForInstanceof
│ │ │ ├── Shape.java
│ │ │ ├── ShapeDisplayNameResolver.java
│ │ │ ├── withDisplayName
│ │ │ │ ├── Circle.java
│ │ │ │ ├── DisplayNamed.java
│ │ │ │ └── Pentagon.java
│ │ │ └── withNameShapes
│ │ │ │ ├── Named.java
│ │ │ │ ├── Square.java
│ │ │ │ └── Triangle.java
│ │ │ ├── record
│ │ │ └── Car.java
│ │ │ ├── sealed
│ │ │ ├── Animal.java
│ │ │ ├── Dog.java
│ │ │ ├── Elephant.java
│ │ │ ├── GermanShepherd.java
│ │ │ ├── Human.java
│ │ │ ├── Mammal.java
│ │ │ └── Reptile.java
│ │ │ ├── streamToList
│ │ │ └── EvenNumberFilter.java
│ │ │ ├── stringMethods
│ │ │ └── StringService.java
│ │ │ ├── switchExpressions
│ │ │ ├── Day.java
│ │ │ └── DayService.java
│ │ │ ├── teeing
│ │ │ ├── employee
│ │ │ │ └── EmployeeService.java
│ │ │ └── event
│ │ │ │ └── ParticipationService.java
│ │ │ ├── textBlock
│ │ │ └── HtmlCode.java
│ │ │ ├── transform
│ │ │ ├── ImportedCSVTextProcessor.java
│ │ │ └── PalindromeChecker.java
│ │ │ ├── unmodifiableCollections
│ │ │ ├── MyService.java
│ │ │ └── Some3rdService.java
│ │ │ └── var
│ │ │ └── Student.java
│ └── test
│ │ └── java
│ │ └── com
│ │ └── example
│ │ ├── EnvironmentSetupTest.java
│ │ ├── collectionFactoryMethods
│ │ └── ImageConverterTest.java
│ │ ├── fileMismatch
│ │ └── FileEqualsCheckerTest.java
│ │ ├── files
│ │ └── FileServiceTest.java
│ │ ├── httpClient
│ │ └── TodoRepositoryTest.java
│ │ ├── indent
│ │ ├── NoIndentTextFormatterTest.java
│ │ └── TextBlockFormatterTest.java
│ │ ├── optionalOrElseThrow
│ │ └── DataServiceTest.java
│ │ ├── patternMatchingForInstanceof
│ │ └── PatternMatchingForInstanceofTest.java
│ │ ├── record
│ │ └── CarTest.java
│ │ ├── sealed
│ │ └── AnimalTreeTest.java
│ │ ├── streamToList
│ │ └── EvenNumberFilterTest.java
│ │ ├── stringMethods
│ │ └── StringServiceTest.java
│ │ ├── switchExpressions
│ │ └── DayServiceTest.java
│ │ ├── teeing
│ │ ├── employee
│ │ │ └── EmployeeServiceTest.java
│ │ └── event
│ │ │ └── ParticipationServiceTest.java
│ │ ├── textBlock
│ │ └── HtmlCodeTest.java
│ │ ├── transform
│ │ ├── ImportedCSVTextProcessorTest.java
│ │ └── PalindromeCheckerTest.java
│ │ ├── unmodifiableCollections
│ │ └── MyServiceTest.java
│ │ └── var
│ │ └── StudentTest.java
└── tmp
│ └── java-versions-cheat-sheet-happycoders.eu-v22.0.3.pdf
├── bdd
├── .gitignore
├── .mvn
│ └── wrapper
│ │ ├── maven-wrapper.jar
│ │ └── maven-wrapper.properties
├── docs
│ ├── bdd-snippets.md
│ ├── bdd-vs-tdd.png
│ └── bdd.md
├── mvnw
├── mvnw.cmd
├── pom.xml
└── src
│ ├── main
│ └── java
│ │ └── com
│ │ └── example
│ │ ├── FizzBuzzProblem.java
│ │ └── MyStack.java
│ └── test
│ ├── java
│ └── com
│ │ └── example
│ │ └── bdd
│ │ ├── DatatableExamplStepDefinitions.java
│ │ ├── ExampleStepDefinitions.java
│ │ ├── FizzBuzzProblemStepDefinitions.java
│ │ ├── RunCucumberTest.java
│ │ └── StackStepDefinition.java
│ └── resources
│ └── bdd
│ ├── datatable.feature
│ ├── example.feature
│ ├── fizzbuzzproblem.feature
│ └── stack.feature
├── clean-code
├── .gitignore
├── README.md
├── ZZPJ2024-clean_code_solid.pdf
├── pom.xml
└── src
│ ├── main
│ └── java
│ │ └── pl
│ │ └── zzpj
│ │ ├── cleancode
│ │ └── doit.java
│ │ └── solid
│ │ ├── dip
│ │ ├── driver
│ │ │ ├── solution
│ │ │ │ ├── Driver.java
│ │ │ │ ├── RacingCar.java
│ │ │ │ └── Vehicle.java
│ │ │ └── violation
│ │ │ │ ├── Driver.java
│ │ │ │ ├── LimousineCar.java
│ │ │ │ └── RacingCar.java
│ │ └── weathertracker
│ │ │ ├── solution
│ │ │ └── TODO.txt
│ │ │ └── violation
│ │ │ ├── Emailer.java
│ │ │ ├── Phone.java
│ │ │ └── WeatherTracker.java
│ │ ├── isp
│ │ ├── contactbook
│ │ │ ├── solution
│ │ │ │ └── TODO.txt
│ │ │ └── violation
│ │ │ │ ├── Contact.java
│ │ │ │ ├── Dialler.java
│ │ │ │ ├── Emailer.java
│ │ │ │ └── InterfaceSegregationPrincipleBAD.java
│ │ └── switcher
│ │ │ ├── solution
│ │ │ ├── CameraSwitch.java
│ │ │ ├── Car.java
│ │ │ ├── Drone.java
│ │ │ ├── EngineSwitch.java
│ │ │ ├── RadioSwitch.java
│ │ │ └── Vehicle.java
│ │ │ └── violation
│ │ │ ├── Car.java
│ │ │ ├── Drone.java
│ │ │ ├── Switches.java
│ │ │ └── Vehicle.java
│ │ ├── lsp
│ │ ├── shape
│ │ │ └── TODO.txt
│ │ └── vehiclemovement
│ │ │ ├── solution
│ │ │ ├── Car.java
│ │ │ ├── Gear.java
│ │ │ ├── Plane.java
│ │ │ └── Vehicle.java
│ │ │ └── violation
│ │ │ ├── Car.java
│ │ │ ├── Gear.java
│ │ │ ├── Plane.java
│ │ │ └── Vehicle.java
│ │ ├── ocp
│ │ ├── greeter
│ │ │ ├── solution
│ │ │ │ ├── CasualPersonality.java
│ │ │ │ ├── FormalPersonality.java
│ │ │ │ ├── Greeter.java
│ │ │ │ ├── IntimatePersonality.java
│ │ │ │ └── Personality.java
│ │ │ └── violation
│ │ │ │ └── Greeter.java
│ │ ├── usa
│ │ │ ├── solution
│ │ │ │ └── TODO.txt
│ │ │ └── violation
│ │ │ │ └── USASpeedLimitFines.java
│ │ └── vehicle
│ │ │ ├── solution
│ │ │ ├── Comfort.java
│ │ │ ├── DrivingMode.java
│ │ │ ├── Economy.java
│ │ │ ├── EventHandler.java
│ │ │ ├── Sport.java
│ │ │ └── Vehicle.java
│ │ │ └── violation
│ │ │ ├── DrivingMode.java
│ │ │ ├── EventHandler.java
│ │ │ └── Vehicle.java
│ │ └── srp
│ │ ├── book
│ │ ├── solution
│ │ │ └── TODO.txt
│ │ └── violation
│ │ │ └── BookAndPrinter.java
│ │ └── vehicle
│ │ ├── solution
│ │ ├── FuelPump.java
│ │ ├── Refualable.java
│ │ └── Vehicle.java
│ │ └── violation
│ │ └── Vehicle.java
│ └── test
│ └── java
│ └── .keep
├── intellij
├── README.md
└── grupy
│ └── README.md
├── intro
├── Git-Maven-GithubActions.md
├── ZZPJ2021-maven.pdf
├── jdk21-mint.png
└── maven-helpful-snippets.md
├── microservices-world
├── README.md
├── TrainTripEcoSystem
│ ├── .gitignore
│ ├── .mvn
│ │ └── wrapper
│ │ │ └── maven-wrapper.properties
│ ├── mvnw
│ ├── mvnw.cmd
│ ├── pom.xml
│ └── src
│ │ ├── main
│ │ ├── java
│ │ │ └── com
│ │ │ │ └── zzpj
│ │ │ │ └── TrainTripEcoSystem
│ │ │ │ └── TrainTripEcoSystemApplication.java
│ │ └── resources
│ │ │ └── application.properties
│ │ └── test
│ │ └── java
│ │ └── com
│ │ └── zzpj
│ │ └── TrainTripEcoSystem
│ │ └── TrainTripEcoSystemApplicationTests.java
├── TrainTripManagerService
│ ├── .gitignore
│ ├── .mvn
│ │ └── wrapper
│ │ │ └── maven-wrapper.properties
│ ├── api
│ │ └── train-api.yml
│ ├── mvnw
│ ├── mvnw.cmd
│ ├── pom.xml
│ └── src
│ │ ├── main
│ │ ├── java
│ │ │ └── com
│ │ │ │ └── zzpj
│ │ │ │ └── TrainTripManagerService
│ │ │ │ └── TrainTripManagerServiceApplication.java
│ │ └── resources
│ │ │ └── application.properties
│ │ └── test
│ │ └── java
│ │ └── com
│ │ └── zzpj
│ │ └── TrainTripManagerService
│ │ └── TrainTripManagerServiceApplicationTests.java
├── TrainTripOrganizerService
│ ├── .gitignore
│ ├── .mvn
│ │ └── wrapper
│ │ │ └── maven-wrapper.properties
│ ├── api
│ │ └── train-api.yml
│ ├── mvnw
│ ├── mvnw.cmd
│ ├── pom.xml
│ └── src
│ │ ├── main
│ │ ├── java
│ │ │ └── com
│ │ │ │ └── zzpj
│ │ │ │ └── TrainTripOrganizerService
│ │ │ │ └── TrainTripOrganizerServiceApplication.java
│ │ └── resources
│ │ │ └── application.properties
│ │ └── test
│ │ └── java
│ │ └── com
│ │ └── zzpj
│ │ └── TrainTripOrganizerService
│ │ └── TrainTripOrganizerServiceApplicationTests.java
├── TrainTripUsersAdapter
│ ├── .gitignore
│ ├── .mvn
│ │ └── wrapper
│ │ │ └── maven-wrapper.properties
│ ├── mvnw
│ ├── mvnw.cmd
│ ├── pom.xml
│ └── src
│ │ ├── main
│ │ ├── java
│ │ │ └── com
│ │ │ │ └── zzpj
│ │ │ │ └── TrainTripUsersAdapter
│ │ │ │ └── TrainTripUsersAdapterApplication.java
│ │ └── resources
│ │ │ └── application.properties
│ │ └── test
│ │ └── java
│ │ └── com
│ │ └── zzpj
│ │ └── TrainTripUsersAdapter
│ │ └── TrainTripUsersAdapterApplicationTests.java
├── TrainTripsConfigServer
│ ├── .gitignore
│ ├── .mvn
│ │ └── wrapper
│ │ │ └── maven-wrapper.properties
│ ├── mvnw
│ ├── mvnw.cmd
│ ├── pom.xml
│ └── src
│ │ ├── main
│ │ ├── java
│ │ │ └── com
│ │ │ │ └── zzpj
│ │ │ │ └── TrainTripsConfigServer
│ │ │ │ └── TrainTripsConfigServerApplication.java
│ │ └── resources
│ │ │ └── application.properties
│ │ └── test
│ │ └── java
│ │ └── com
│ │ └── zzpj
│ │ └── TrainTripsConfigServer
│ │ └── TrainTripsConfigServerApplicationTests.java
└── train-api-example.yml
├── spring-security
├── .gitignore
├── pom.xml
└── src
│ ├── main
│ ├── java
│ │ └── com
│ │ │ └── example
│ │ │ └── demo
│ │ │ ├── SecurityDemoApplication.java
│ │ │ ├── config
│ │ │ └── SecurityConfig.java
│ │ │ ├── controller
│ │ │ ├── TokenProviderController.java
│ │ │ └── UsersController.java
│ │ │ ├── model
│ │ │ ├── dao
│ │ │ │ └── UserDao.java
│ │ │ └── dto
│ │ │ │ └── UserDto.java
│ │ │ └── service
│ │ │ └── UsersService.java
│ └── resources
│ │ ├── application.properties
│ │ └── cert
│ │ ├── cert.key
│ │ └── cert.pub
│ └── test
│ └── java
│ └── com
│ └── example
│ └── demo
│ └── SecurityDemoApplicationTests.java
└── spring
├── .gitignore
├── .mvn
└── wrapper
│ ├── maven-wrapper.jar
│ └── maven-wrapper.properties
├── ZZPJ2024-springboot.pdf
├── mvnw
├── mvnw.cmd
├── pom.xml
├── readme.md
└── src
├── main
├── java
│ └── com
│ │ └── zzpj
│ │ └── EventManager
│ │ ├── EventConfig.java
│ │ ├── EventExceptionHandler.java
│ │ ├── EventManagerApplication.java
│ │ ├── controller
│ │ └── EventController.java
│ │ ├── model
│ │ ├── Event.java
│ │ └── EventErrorResponse.java
│ │ ├── repository
│ │ └── EventRepository.java
│ │ └── service
│ │ └── EventService.java
└── resources
│ └── application.properties
└── test
└── java
└── com
└── zzpj
└── EventManager
└── EventManagerApplicationTests.java
/.gitignore:
--------------------------------------------------------------------------------
1 | /.idea/
2 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | ## PŁ: Zaawansowane Zagadnienia Programowania w Javie - Edycja 2024
2 |
3 | ### Prowadzący
4 |
5 | - dr inż. Łukasz Chomątek (lukasz.chomatek@p.lodz.pl)
6 | - mgr inż. Michal Dubel (michal.dubel.500@guest.p.lodz.pl priv: michal.dubel@ttpsc.pl)
7 | - mgr inż. Zbyszko Natkanski (zbyszko.natkanski.500@guest.p.lodz.pl priv: zbyszkonatkanski@gmail.com)
8 |
9 | ### Organizacja zajęć
10 |
11 | - Krótki wykład – przedstawienie problemu, rozwiązania lub technologii
12 | - Live coding
13 | - Ćwiczenia praktyczne
14 |
15 | ### Ramowy plan zajęć
16 |
17 | Lp | Temat | Data | Prowadzący | Uwagi
18 | ----|---------------------------------------------|------------|------------|--------------------------------------------------------------------------------------------------------
19 | 1 | Wprowadzenie: Git/Maven/Github (Actions) | 28.02.2024 | ZN+MD | [Materiały na zajęcia](https://github.com/zzpj/pl-java2024/blob/main/intro/Git-Maven-GithubActions.md)
20 | 2 | IntelliJ Wizards | 6.03.2024 | MD |
21 | 3 | Unit Testing | 13.03.2024 | ZN+ŁCh | Testy parametryczne (Junit5) + Mocki (JMockito) + Cucumber-BDD
22 | 4 | Project concept | 20.03.2024 | ZN+MD+ŁCh | Zapisy na sloty czasowe są dostępne na platformie WIKAMP
23 | 5 | JDK Updates 8-21 | 27.03.2024 | ZN |
24 | 6 | LM Studio (AI w Javie) | 10.04.2024 | ŁCh |
25 | 7 | Spring 101 | 17.04.2024 | ZN |
26 | 8 | Spring 102 | 24.04.2024 | AK (MD) |
27 | 9 | Clean Code + SOLID + Statyczna analiza kodu | 8.05.2024 | ZN + ŁCh |
28 | 10 | Współbieżność | 15.05.2024 | ŁCh |
29 | 11 | Middle project check | 22.05.2024 | ZN+MD+ŁCh | Zapisy na sloty czasowe są dostępne na platformie WIKAMP
30 | 12 | Microservices Basis | 29.05.2024 | ZN |
31 | 13 | Microservices Advanced | 5.06.2024 | ZN |
32 | 14 | Testy mutacyjne | 12.06.2024 | MD |
33 | 15 | Final project check | 19.06.2024 | ZN+MD+ŁCh | Zapisy na sloty czasowe są dostępne na platformie WIKAMP
34 |
35 |
36 | ### Zaliczenie
37 |
38 | - Projekt grupowy (3-6 osób)
39 | - Elementy podlegające ocenie w projekcie grupowym:
40 | - Testy
41 | - Współpraca z Git/Github/CI(wedle uznania, proponowane: Github Actions)/IDE
42 | - Clean code
43 | - Programowanie funkcyjne
44 | - Wzorce projektowe
45 | - Użycie dodatkowych funkcjonalności spoza prezentowanych tematów (przykład: integracja z rozwiązaniem chmurowym np.
46 | deployment na publicznej chmurze)
47 | - Integracja z zewnętrznym zasobem po REST
48 | - Aktywność w realizacji projektu (PR, commity, githubowy pulse, board projektowy)
49 | - ...
50 | - *UI, UX nie mają znaczenia!*
51 | - *Unikać typowych aplikacji CRUD*
52 | - Aktywność i realizacja zadań z prezentowanego tematu (+0.5 do oceny końcowej)
53 |
54 | ### Linki
55 |
56 | https://p.lodz.pl/studenci/podzial-roku-akademickiego
57 |
--------------------------------------------------------------------------------
/amber/.gitignore:
--------------------------------------------------------------------------------
1 | target/
2 | !.mvn/wrapper/maven-wrapper.jar
3 | !**/src/main/**/target/
4 | !**/src/test/**/target/
5 |
6 | ### IntelliJ IDEA ###
7 | .idea/modules.xml
8 | .idea/jarRepositories.xml
9 | .idea/compiler.xml
10 | .idea/libraries/
11 | *.iws
12 | *.iml
13 | *.ipr
14 |
15 | ### Eclipse ###
16 | .apt_generated
17 | .classpath
18 | .factorypath
19 | .project
20 | .settings
21 | .springBeans
22 | .sts4-cache
23 |
24 | ### NetBeans ###
25 | /nbproject/private/
26 | /nbbuild/
27 | /dist/
28 | /nbdist/
29 | /.nb-gradle/
30 | build/
31 | !**/src/main/**/build/
32 | !**/src/test/**/build/
33 |
34 | ### VS Code ###
35 | .vscode/
36 |
37 | ### Mac OS ###
38 | .DS_Store
39 | /.idea/
40 |
--------------------------------------------------------------------------------
/amber/img/java22-arrival.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/zzpj/pl-java2024/b3607327e97ffb15868a519cb595df959329c5f8/amber/img/java22-arrival.png
--------------------------------------------------------------------------------
/amber/img/project-amber-timeline.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/zzpj/pl-java2024/b3607327e97ffb15868a519cb595df959329c5f8/amber/img/project-amber-timeline.png
--------------------------------------------------------------------------------
/amber/pom.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 | 4.0.0
6 |
7 | com.example
8 | amber
9 | 1.0-SNAPSHOT
10 |
11 |
12 | 21
13 | 21
14 |
15 |
16 |
17 |
18 | org.junit.jupiter
19 | junit-jupiter-engine
20 | 5.10.2
21 | test
22 |
23 |
24 | org.junit.jupiter
25 | junit-jupiter-params
26 | 5.10.2
27 | test
28 |
29 |
30 | org.projectlombok
31 | lombok
32 | 1.18.32
33 | provided
34 |
35 |
36 |
37 |
--------------------------------------------------------------------------------
/amber/src/main/java/com/example/Sandbox.java:
--------------------------------------------------------------------------------
1 | package com.example;
2 |
3 | public class Sandbox {
4 | public static void main(String[] args) {
5 | }
6 | }
--------------------------------------------------------------------------------
/amber/src/main/java/com/example/collectionFactoryMethods/ImageConverter.java:
--------------------------------------------------------------------------------
1 | package com.example.collectionFactoryMethods;
2 |
3 | import java.util.Set;
4 | import java.util.TreeSet;
5 |
6 | public class ImageConverter {
7 | private final String JPG_FILE_KEY = "jpg";
8 | private final String PNG_FILE_KEY = "png";
9 | private final String BMP_FILE_KEY = "bmp";
10 |
11 |
12 | public Set getAvailableFileKeys() {
13 | // TODO: implement here
14 | // return immutable set of file keys
15 |
16 | return new TreeSet<>();
17 | }
18 | }
19 |
--------------------------------------------------------------------------------
/amber/src/main/java/com/example/fileMismatch/FileEqualsChecker.java:
--------------------------------------------------------------------------------
1 | package com.example.fileMismatch;
2 |
3 | import java.io.IOException;
4 | import java.nio.file.Path;
5 |
6 | public class FileEqualsChecker {
7 |
8 | boolean isFileEquals(Path path1, Path path2) throws IOException {
9 | // TODO: implement here
10 | return false;
11 | }
12 | }
13 |
--------------------------------------------------------------------------------
/amber/src/main/java/com/example/files/FileService.java:
--------------------------------------------------------------------------------
1 | package com.example.files;
2 |
3 | import java.io.IOException;
4 | import java.nio.file.Path;
5 |
6 | public class FileService {
7 |
8 | boolean isFileContainsText(Path path, String searchingText) throws IOException {
9 | // TODO: implement here
10 | // read file content and return true if searchingText found
11 |
12 | return false;
13 | }
14 | }
15 |
--------------------------------------------------------------------------------
/amber/src/main/java/com/example/httpClient/TodoRepository.java:
--------------------------------------------------------------------------------
1 | package com.example.httpClient;
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 TodoRepository {
11 |
12 | String getTodo() throws URISyntaxException, IOException, InterruptedException {
13 | // TODO: implement here
14 | // use HttpResponse.BodyHandlers.ofString() handler
15 | // return response body
16 |
17 | return "";
18 | }
19 |
20 | }
21 |
--------------------------------------------------------------------------------
/amber/src/main/java/com/example/indent/NoIndentTextFormatter.java:
--------------------------------------------------------------------------------
1 | package com.example.indent;
2 |
3 | public class NoIndentTextFormatter {
4 |
5 | String noIndentText(String text) {
6 | // TODO: implement here
7 | // remove indent
8 |
9 | return "";
10 | }
11 | }
12 |
--------------------------------------------------------------------------------
/amber/src/main/java/com/example/indent/TextBlockFormatter.java:
--------------------------------------------------------------------------------
1 | package com.example.indent;
2 |
3 | public class TextBlockFormatter {
4 | private final int CODE_TEXT_BLOCK_INDENT = 4;
5 |
6 | String formatLinesToCodeBlockIndent(String code) {
7 | // TODO: implement here
8 | // use CODE_TEXT_BLOCK_INDENT as padding value
9 |
10 | return "";
11 | }
12 | }
13 |
--------------------------------------------------------------------------------
/amber/src/main/java/com/example/optionalOrElseThrow/DataProvider.java:
--------------------------------------------------------------------------------
1 | package com.example.optionalOrElseThrow;
2 |
3 | import java.util.Optional;
4 |
5 | public class DataProvider {
6 |
7 | // do not change
8 | Optional getUsername(int id) {
9 | return id < 3
10 | ? Optional.empty()
11 | : Optional.of("user-" + id);
12 | }
13 |
14 | }
15 |
--------------------------------------------------------------------------------
/amber/src/main/java/com/example/optionalOrElseThrow/DataService.java:
--------------------------------------------------------------------------------
1 | package com.example.optionalOrElseThrow;
2 |
3 | public class DataService {
4 | DataProvider dataProvider = new DataProvider();
5 |
6 | String getUsername(int id) {
7 | // TODO: implement here
8 | // get username from DataProvider.
9 | // Return value or throw exception if there is no value
10 |
11 | return "";
12 | }
13 | }
14 |
--------------------------------------------------------------------------------
/amber/src/main/java/com/example/patternMatchingForInstanceof/Shape.java:
--------------------------------------------------------------------------------
1 | package com.example.patternMatchingForInstanceof;
2 |
3 | public class Shape {
4 | }
5 |
--------------------------------------------------------------------------------
/amber/src/main/java/com/example/patternMatchingForInstanceof/ShapeDisplayNameResolver.java:
--------------------------------------------------------------------------------
1 | package com.example.patternMatchingForInstanceof;
2 |
3 | public class ShapeDisplayNameResolver {
4 |
5 | public String resolveShape(Shape shape) {
6 | // TODO: implement here with pattern matching for instanceof usage
7 |
8 |
9 | return "";
10 | }
11 | }
12 |
13 | // TIP: shape can be DisplayNamed or Named
14 | // if shape is DisplayNamed use getDisplayName method
15 | // if shape is Named use getName method and format it to expected display string
16 |
--------------------------------------------------------------------------------
/amber/src/main/java/com/example/patternMatchingForInstanceof/withDisplayName/Circle.java:
--------------------------------------------------------------------------------
1 | package com.example.patternMatchingForInstanceof.withDisplayName;
2 |
3 | import com.example.patternMatchingForInstanceof.Shape;
4 |
5 | public class Circle extends Shape implements DisplayNamed {
6 | @Override
7 | public String getDisplayName() {
8 | return "This is circle name!";
9 | }
10 | }
11 |
--------------------------------------------------------------------------------
/amber/src/main/java/com/example/patternMatchingForInstanceof/withDisplayName/DisplayNamed.java:
--------------------------------------------------------------------------------
1 | package com.example.patternMatchingForInstanceof.withDisplayName;
2 |
3 | public interface DisplayNamed {
4 |
5 | String getDisplayName();
6 | }
7 |
--------------------------------------------------------------------------------
/amber/src/main/java/com/example/patternMatchingForInstanceof/withDisplayName/Pentagon.java:
--------------------------------------------------------------------------------
1 | package com.example.patternMatchingForInstanceof.withDisplayName;
2 |
3 | import com.example.patternMatchingForInstanceof.Shape;
4 |
5 | public class Pentagon extends Shape implements DisplayNamed {
6 | @Override
7 | public String getDisplayName() {
8 | return "This is pentagon name!";
9 | }
10 | }
11 |
--------------------------------------------------------------------------------
/amber/src/main/java/com/example/patternMatchingForInstanceof/withNameShapes/Named.java:
--------------------------------------------------------------------------------
1 | package com.example.patternMatchingForInstanceof.withNameShapes;
2 |
3 | public interface Named {
4 | String getName();
5 | }
6 |
--------------------------------------------------------------------------------
/amber/src/main/java/com/example/patternMatchingForInstanceof/withNameShapes/Square.java:
--------------------------------------------------------------------------------
1 | package com.example.patternMatchingForInstanceof.withNameShapes;
2 |
3 | import com.example.patternMatchingForInstanceof.Shape;
4 |
5 | public class Square extends Shape implements Named {
6 | @Override
7 | public String getName() {
8 | return "square";
9 | }
10 | }
11 |
--------------------------------------------------------------------------------
/amber/src/main/java/com/example/patternMatchingForInstanceof/withNameShapes/Triangle.java:
--------------------------------------------------------------------------------
1 | package com.example.patternMatchingForInstanceof.withNameShapes;
2 |
3 | import com.example.patternMatchingForInstanceof.Shape;
4 |
5 | public class Triangle extends Shape implements Named{
6 | @Override
7 | public String getName() {
8 | return "triangle";
9 | }
10 | }
11 |
--------------------------------------------------------------------------------
/amber/src/main/java/com/example/record/Car.java:
--------------------------------------------------------------------------------
1 | package com.example.record;
2 |
3 | // TODO: implement here
4 | // change this class to record
5 | // throw IllegalArgumentException when capacity in negative while creating
6 | public class Car {
7 |
8 |
9 | public Car(String make, int capacity) {
10 |
11 | }
12 |
13 | public String make() {
14 | return "";
15 | }
16 |
17 | public int capacity() {
18 | return 0;
19 | }
20 | }
21 |
--------------------------------------------------------------------------------
/amber/src/main/java/com/example/sealed/Animal.java:
--------------------------------------------------------------------------------
1 | package com.example.sealed;
2 |
3 | public class Animal {
4 | }
5 |
--------------------------------------------------------------------------------
/amber/src/main/java/com/example/sealed/Dog.java:
--------------------------------------------------------------------------------
1 | package com.example.sealed;
2 |
3 | public class Dog {
4 | }
5 |
--------------------------------------------------------------------------------
/amber/src/main/java/com/example/sealed/Elephant.java:
--------------------------------------------------------------------------------
1 | package com.example.sealed;
2 |
3 | public class Elephant {
4 | }
5 |
--------------------------------------------------------------------------------
/amber/src/main/java/com/example/sealed/GermanShepherd.java:
--------------------------------------------------------------------------------
1 | package com.example.sealed;
2 |
3 | public class GermanShepherd {
4 | }
5 |
--------------------------------------------------------------------------------
/amber/src/main/java/com/example/sealed/Human.java:
--------------------------------------------------------------------------------
1 | package com.example.sealed;
2 |
3 | public class Human {
4 | }
5 |
--------------------------------------------------------------------------------
/amber/src/main/java/com/example/sealed/Mammal.java:
--------------------------------------------------------------------------------
1 | package com.example.sealed;
2 |
3 | public class Mammal {
4 | }
5 |
--------------------------------------------------------------------------------
/amber/src/main/java/com/example/sealed/Reptile.java:
--------------------------------------------------------------------------------
1 | package com.example.sealed;
2 |
3 | public class Reptile {
4 | }
5 |
--------------------------------------------------------------------------------
/amber/src/main/java/com/example/streamToList/EvenNumberFilter.java:
--------------------------------------------------------------------------------
1 | package com.example.streamToList;
2 |
3 | import java.util.List;
4 |
5 | public class EvenNumberFilter {
6 |
7 | List getEvenNumbers(List allNumbers) {
8 | // TODO: implement here
9 | // return only even numbers from input list
10 | // 1. transform list to Stream
11 | // 2. filter by Stream::filter method
12 | // 3. collect to list
13 |
14 |
15 | return allNumbers;
16 | }
17 | }
18 |
--------------------------------------------------------------------------------
/amber/src/main/java/com/example/stringMethods/StringService.java:
--------------------------------------------------------------------------------
1 | package com.example.stringMethods;
2 |
3 | import java.util.List;
4 |
5 | public class StringService {
6 |
7 | List getOnlyNotBlankStrings(List input) {
8 | // TODO: implement here
9 |
10 | return input;
11 | }
12 |
13 | List getStrippedTextLines(String text) {
14 | // TODO: implement here
15 | // split text to lines and strip
16 | return null;
17 | }
18 |
19 | List extendFoundStringByRepeatSomeTimes(List list, String searchedText, int nTimesRepeat) {
20 | // TODO: implement here
21 | // search for searchedText in a list. Change this string by repeat n times if found
22 | return list;
23 | }
24 | }
25 |
--------------------------------------------------------------------------------
/amber/src/main/java/com/example/switchExpressions/Day.java:
--------------------------------------------------------------------------------
1 | package com.example.switchExpressions;
2 |
3 | public enum Day {
4 |
5 | SUNDAY, MONDAY, TUESDAY,
6 | WEDNESDAY, THURSDAY, FRIDAY, SATURDAY;
7 | }
8 |
--------------------------------------------------------------------------------
/amber/src/main/java/com/example/switchExpressions/DayService.java:
--------------------------------------------------------------------------------
1 | package com.example.switchExpressions;
2 |
3 | public class DayService {
4 |
5 | int getDayNumberOfLettersForWorkday(Day day) {
6 | // TODO: implement here
7 | // return number of letters for working days or throw exception for the other
8 |
9 | return 0;
10 | }
11 | }
12 |
--------------------------------------------------------------------------------
/amber/src/main/java/com/example/teeing/employee/EmployeeService.java:
--------------------------------------------------------------------------------
1 | package com.example.teeing.employee;
2 |
3 | import java.util.List;
4 |
5 |
6 | class Employee {
7 | private double salary;
8 |
9 | public Employee(double salary) {
10 | this.salary = salary;
11 | }
12 |
13 | public double getSalary() {
14 | return salary;
15 | }
16 | }
17 |
18 | public class EmployeeService {
19 |
20 | double getAvgEmployeeSalary(List employees) {
21 | // TODO: implement here
22 | // use List::stream method
23 |
24 | return 0.0;
25 | }
26 | }
27 |
--------------------------------------------------------------------------------
/amber/src/main/java/com/example/teeing/event/ParticipationService.java:
--------------------------------------------------------------------------------
1 | package com.example.teeing.event;
2 |
3 | import java.util.Collections;
4 | import java.util.List;
5 |
6 | class Guest {
7 | private final String name;
8 | private boolean participating;
9 | private Integer participantsNumber;
10 |
11 | public Guest(String name, boolean participating,
12 | Integer participantsNumber) {
13 | this.name = name;
14 | this.participating = participating;
15 | this.participantsNumber = participantsNumber;
16 | }
17 |
18 | public String getName() {
19 | return name;
20 | }
21 |
22 | public boolean isParticipating() {
23 | return participating;
24 | }
25 |
26 | public Integer getParticipantsNumber() {
27 | return participantsNumber;
28 | }
29 | }
30 |
31 | class EventParticipation {
32 | private final List guestNameList;
33 | private final Integer totalNumberOfParticipants;
34 |
35 | public EventParticipation(List guestNameList,
36 | Integer totalNumberOfParticipants) {
37 | this.guestNameList = guestNameList;
38 | this.totalNumberOfParticipants = totalNumberOfParticipants;
39 | }
40 |
41 | public List getGuestNameList() {
42 | return guestNameList;
43 | }
44 |
45 | public Integer getTotalNumberOfParticipants() {
46 | return totalNumberOfParticipants;
47 | }
48 |
49 | }
50 |
51 | public class ParticipationService {
52 |
53 | EventParticipation processEventGuests(List guests) {
54 | // TODO: implement here
55 | // return EventParticipation with sum of all participants and names of participants, who will attend
56 |
57 | // TIP
58 | // collector1: use Collectors.filtering for filtering ony attend guests,
59 | // then collect theirs names to list (use Collectors.mapping)
60 | // collector2: return sum of all participants
61 |
62 |
63 | return new EventParticipation(Collections.emptyList(), 0);
64 | }
65 | }
66 |
--------------------------------------------------------------------------------
/amber/src/main/java/com/example/textBlock/HtmlCode.java:
--------------------------------------------------------------------------------
1 | package com.example.textBlock;
2 |
3 | public class HtmlCode {
4 | String getHtml() {
5 | // TODO: implement here
6 | // rewrite using text block
7 |
8 | return "\n" +
9 | "\n" +
10 | " \n" +
11 | " \n" +
12 | " My test page\n" +
13 | " \n" +
14 | " \n" +
15 | "
\n" +
16 | " \n" +
17 | "\n";
18 | }
19 | }
20 |
--------------------------------------------------------------------------------
/amber/src/main/java/com/example/transform/ImportedCSVTextProcessor.java:
--------------------------------------------------------------------------------
1 | package com.example.transform;
2 |
3 | public class ImportedCSVTextProcessor {
4 |
5 | String process(String line) {
6 | // TODO: implement here
7 | // 1. replace "," with space
8 | // 2. remove "none"
9 | // 3. remove white spaces from start and end
10 | // 4. add "-done" at the end
11 | // 5. to uppercase
12 |
13 | return "";
14 | }
15 | }
16 |
--------------------------------------------------------------------------------
/amber/src/main/java/com/example/transform/PalindromeChecker.java:
--------------------------------------------------------------------------------
1 | package com.example.transform;
2 |
3 | public class PalindromeChecker {
4 |
5 | boolean isPalindrome(String text) {
6 | // TODO: implement here
7 | // TIP: you can use StringBuilder.reverse method
8 |
9 |
10 | return false;
11 | }
12 | }
13 |
--------------------------------------------------------------------------------
/amber/src/main/java/com/example/unmodifiableCollections/MyService.java:
--------------------------------------------------------------------------------
1 | package com.example.unmodifiableCollections;
2 |
3 | import java.util.List;
4 |
5 | public class MyService {
6 | Some3rdService some3rdService = new Some3rdService();
7 |
8 | public List getUnmodifiableListByCollector() {
9 | // TODO: implement here
10 | // copy list by stream and Collectors.toUnmodifiableList
11 |
12 | return some3rdService.getList();
13 | }
14 |
15 | public List getUnmodifiableListByCopy() {
16 | // TODO: implement here
17 | // copy list by static copyOf method
18 |
19 | return some3rdService.getList();
20 | }
21 | }
22 |
--------------------------------------------------------------------------------
/amber/src/main/java/com/example/unmodifiableCollections/Some3rdService.java:
--------------------------------------------------------------------------------
1 | package com.example.unmodifiableCollections;
2 |
3 | import java.util.ArrayList;
4 | import java.util.List;
5 |
6 | public class Some3rdService {
7 |
8 | // return modifiable list by default. Do not change.
9 | public List getList() {
10 | List list = new ArrayList<>();
11 | list.add(1);
12 | list.add(2);
13 | list.add(3);
14 | list.add(4);
15 | return list;
16 | }
17 | }
18 |
--------------------------------------------------------------------------------
/amber/src/main/java/com/example/var/Student.java:
--------------------------------------------------------------------------------
1 | package com.example.var;
2 |
3 | import java.math.BigDecimal;
4 | import java.math.RoundingMode;
5 | import java.util.ArrayList;
6 | import java.util.List;
7 |
8 | public class Student {
9 | private final Integer[] marks;
10 |
11 | public Student(Integer[] marks) {
12 | this.marks = marks;
13 | }
14 |
15 | public Integer getNumberOfMarks() {
16 | return marks.length;
17 | }
18 |
19 | // TODO: implement here
20 | // rewrite code using var from JDK 10
21 |
22 | public Integer getTotalSumOfMarks() {
23 | Integer sum = 0;
24 | for (Integer mark : marks) {
25 | sum += mark;
26 | }
27 | return sum;
28 | }
29 |
30 | public BigDecimal getAverageOfMarks() {
31 | Integer sum = getTotalSumOfMarks();
32 | return new BigDecimal(sum)
33 | .divide(new BigDecimal(marks.length), 3, RoundingMode.UP);
34 | }
35 |
36 | public Integer getMaximumMark() {
37 | Integer max = Integer.MIN_VALUE;
38 | for (Integer mark : marks) {
39 | if (mark > max) {
40 | max = mark;
41 | }
42 | }
43 | return max;
44 | }
45 |
46 | public Integer getMinimumMark() {
47 | Integer min = Integer.MAX_VALUE;
48 | for (Integer mark : marks) {
49 | if (mark < min) {
50 | min = mark;
51 | }
52 | }
53 | return min;
54 | }
55 |
56 | public List getDistinctMarks() {
57 | List distinctMarks = new ArrayList<>();
58 |
59 | for (Integer mark : marks) {
60 | if (!distinctMarks.contains(mark)) {
61 | distinctMarks.add(mark);
62 | }
63 | }
64 | return distinctMarks;
65 | }
66 | }
67 |
--------------------------------------------------------------------------------
/amber/src/test/java/com/example/EnvironmentSetupTest.java:
--------------------------------------------------------------------------------
1 | package com.example;
2 |
3 | import org.junit.jupiter.api.Test;
4 |
5 | import static org.junit.jupiter.api.Assertions.assertEquals;
6 |
7 | public class EnvironmentSetupTest {
8 |
9 | @Test
10 | void shouldRunOnJava22() {
11 | int feature = Runtime.version().feature();
12 | assertEquals(22, feature);
13 | }
14 | }
15 |
--------------------------------------------------------------------------------
/amber/src/test/java/com/example/collectionFactoryMethods/ImageConverterTest.java:
--------------------------------------------------------------------------------
1 | package com.example.collectionFactoryMethods;
2 |
3 | import org.junit.jupiter.api.Test;
4 |
5 | import java.util.Set;
6 |
7 | import static org.junit.jupiter.api.Assertions.assertEquals;
8 | import static org.junit.jupiter.api.Assertions.assertThrows;
9 |
10 | class ImageConverterTest {
11 |
12 | @Test
13 | void shouldReturnImmutableFileKeysList() {
14 | ImageConverter sut = new ImageConverter();
15 |
16 | Set result = sut.getAvailableFileKeys();
17 |
18 | assertEquals(3, result.size());
19 | assertThrows(UnsupportedOperationException.class, () -> {
20 | result.add("gif");
21 | });
22 | }
23 | }
24 |
--------------------------------------------------------------------------------
/amber/src/test/java/com/example/fileMismatch/FileEqualsCheckerTest.java:
--------------------------------------------------------------------------------
1 | package com.example.fileMismatch;
2 |
3 | import org.junit.jupiter.api.Test;
4 |
5 | import java.io.IOException;
6 | import java.nio.file.Files;
7 | import java.nio.file.Path;
8 |
9 | import static org.junit.jupiter.api.Assertions.*;
10 |
11 | class FileEqualsCheckerTest {
12 | FileEqualsChecker checker = new FileEqualsChecker();
13 |
14 | @Test
15 | void shouldReturnTrueIfFilesAreEquals() throws IOException {
16 | Path path1 = Files.createTempFile("text1", ".txt");
17 | Files.writeString(path1,"value1");
18 |
19 | Path path2 = Files.createTempFile("text2", ".txt");
20 | Files.writeString(path2,"value1");
21 |
22 |
23 | boolean result = checker.isFileEquals(path1, path2);
24 |
25 | assertTrue(result);
26 | }
27 | @Test
28 | void shouldReturnFalseIfFilesAreNotEquals() throws IOException {
29 | Path path1 = Files.createTempFile("text1", ".txt");
30 | Files.writeString(path1,"value1");
31 |
32 | Path path2 = Files.createTempFile("text2", ".txt");
33 | Files.writeString(path2,"value2");
34 |
35 |
36 | boolean result = checker.isFileEquals(path1, path2);
37 |
38 | assertFalse(result);
39 | }
40 | }
41 |
--------------------------------------------------------------------------------
/amber/src/test/java/com/example/files/FileServiceTest.java:
--------------------------------------------------------------------------------
1 | package com.example.files;
2 |
3 | import org.junit.jupiter.api.Test;
4 |
5 | import java.io.IOException;
6 | import java.nio.file.Files;
7 | import java.nio.file.Path;
8 |
9 | import static org.junit.jupiter.api.Assertions.*;
10 |
11 | class FileServiceTest {
12 |
13 | @Test
14 | void shouldReturnFalseIfNotFound() throws IOException {
15 | FileService service = new FileService();
16 | Path filePath = Files.writeString(Files.createTempFile("file", ".txt"), "Sample text");
17 |
18 | boolean result = service.isFileContainsText(filePath, "not found");
19 |
20 | assertFalse(result);
21 | }
22 |
23 | @Test
24 | void shouldReturnTrueIfFound() throws IOException {
25 | FileService service = new FileService();
26 | Path filePath = Files.writeString(Files.createTempFile("file", ".txt"), "Sample text ");
27 |
28 | boolean result = service.isFileContainsText(filePath, "Sample text");
29 |
30 | assertTrue(result);
31 | }
32 | }
33 |
--------------------------------------------------------------------------------
/amber/src/test/java/com/example/httpClient/TodoRepositoryTest.java:
--------------------------------------------------------------------------------
1 | package com.example.httpClient;
2 |
3 | import org.junit.jupiter.api.Test;
4 |
5 | import java.io.IOException;
6 | import java.net.URISyntaxException;
7 |
8 | import static org.junit.jupiter.api.Assertions.*;
9 |
10 | class TodoRepositoryTest {
11 |
12 | @Test
13 | void getTodo() throws URISyntaxException, IOException, InterruptedException {
14 | TodoRepository repository = new TodoRepository();
15 |
16 | String result = repository.getTodo();
17 | assertEquals("{\n" +
18 | " \"userId\": 1,\n" +
19 | " \"id\": 1,\n" +
20 | " \"title\": \"delectus aut autem\",\n" +
21 | " \"completed\": false\n" +
22 | "}", result);
23 | }
24 | }
25 |
--------------------------------------------------------------------------------
/amber/src/test/java/com/example/indent/NoIndentTextFormatterTest.java:
--------------------------------------------------------------------------------
1 | package com.example.indent;
2 |
3 | import org.junit.jupiter.api.Test;
4 |
5 | import static org.junit.jupiter.api.Assertions.*;
6 |
7 | class NoIndentTextFormatterTest {
8 |
9 | NoIndentTextFormatter noIndentTextFormatter = new NoIndentTextFormatter();
10 |
11 | @Test
12 | void noIndentText() {
13 | String text = " some code with big\n indent\n";
14 |
15 | String result = noIndentTextFormatter.noIndentText(text);
16 |
17 | assertEquals("some code with big\nindent\n", result);
18 | }
19 | }
20 |
--------------------------------------------------------------------------------
/amber/src/test/java/com/example/indent/TextBlockFormatterTest.java:
--------------------------------------------------------------------------------
1 | package com.example.indent;
2 |
3 | import org.junit.jupiter.api.Test;
4 |
5 | import static org.junit.jupiter.api.Assertions.*;
6 |
7 | class TextBlockFormatterTest {
8 | TextBlockFormatter textBlockFormatter = new TextBlockFormatter();
9 |
10 | @Test
11 | void formatLinesToCodeBlockIndent() {
12 | String text = "Code line 1\nCode line 2\nCode line 3\n";
13 |
14 |
15 | String result = textBlockFormatter.formatLinesToCodeBlockIndent(text);
16 |
17 | assertEquals(
18 | " Code line 1\n" +
19 | " Code line 2\n" +
20 | " Code line 3\n",
21 | result);
22 | }
23 | }
24 |
--------------------------------------------------------------------------------
/amber/src/test/java/com/example/optionalOrElseThrow/DataServiceTest.java:
--------------------------------------------------------------------------------
1 | package com.example.optionalOrElseThrow;
2 |
3 | import org.junit.jupiter.api.Test;
4 |
5 | import java.util.NoSuchElementException;
6 |
7 | import static org.junit.jupiter.api.Assertions.*;
8 |
9 | class DataServiceTest {
10 | DataService dataService = new DataService();
11 |
12 |
13 | @Test
14 | void shouldReturnUsernameForIdGreaterThan3() {
15 | String username = dataService.getUsername(4);
16 |
17 | assertEquals("user-4", username);
18 | }
19 |
20 | @Test
21 | void shouldThrowExceptionForIdLessThan3() {
22 |
23 | assertThrows(NoSuchElementException.class, () -> {
24 | dataService.getUsername(1);
25 | });
26 | }
27 | }
28 |
--------------------------------------------------------------------------------
/amber/src/test/java/com/example/patternMatchingForInstanceof/PatternMatchingForInstanceofTest.java:
--------------------------------------------------------------------------------
1 | package com.example.patternMatchingForInstanceof;
2 |
3 | import com.example.patternMatchingForInstanceof.withDisplayName.Circle;
4 | import com.example.patternMatchingForInstanceof.withDisplayName.Pentagon;
5 | import com.example.patternMatchingForInstanceof.withNameShapes.Square;
6 | import com.example.patternMatchingForInstanceof.withNameShapes.Triangle;
7 | import org.junit.jupiter.api.Test;
8 |
9 | import static org.junit.jupiter.api.Assertions.assertEquals;
10 |
11 | public class PatternMatchingForInstanceofTest {
12 | private ShapeDisplayNameResolver sut = new ShapeDisplayNameResolver();
13 |
14 | @Test
15 | void shouldProvideCircleShapeDisplayName() {
16 | ShapeDisplayNameResolver sut = new ShapeDisplayNameResolver();
17 | Circle circle = new Circle();
18 |
19 | String result = sut.resolveShape(circle);
20 |
21 | assertEquals("This is circle name!", result);
22 | }
23 |
24 | @Test
25 | void shouldProvideSquareShapeDisplayName() {
26 | ShapeDisplayNameResolver sut = new ShapeDisplayNameResolver();
27 | Square square = new Square();
28 |
29 | String result = sut.resolveShape(square);
30 |
31 | assertEquals("This is square name!", result);
32 | }
33 |
34 | @Test
35 | void shouldProvideTriangleShapeDisplayName() {
36 | ShapeDisplayNameResolver sut = new ShapeDisplayNameResolver();
37 | Triangle triangle = new Triangle();
38 |
39 | String result = sut.resolveShape(triangle);
40 |
41 | assertEquals("This is triangle name!", result);
42 | }
43 | @Test
44 | void shouldProvidePentagonShapeDisplayName() {
45 | ShapeDisplayNameResolver sut = new ShapeDisplayNameResolver();
46 | Pentagon pentagon = new Pentagon();
47 |
48 | String result = sut.resolveShape(pentagon);
49 |
50 | assertEquals("This is pentagon name!", result);
51 | }
52 | }
53 |
--------------------------------------------------------------------------------
/amber/src/test/java/com/example/record/CarTest.java:
--------------------------------------------------------------------------------
1 | package com.example.record;
2 |
3 | import org.junit.jupiter.api.Test;
4 |
5 | import static org.junit.jupiter.api.Assertions.*;
6 |
7 | class CarTest {
8 |
9 | @Test
10 | void shouldSaveMarkAndCapacity() {
11 | Car car = new Car("Fiat", 1400);
12 |
13 | assertEquals("Fiat", car.make());
14 | assertEquals(1400, car.capacity());
15 | }
16 |
17 | @Test
18 | void shouldThrowExceptionForNegativeCapacityValue() {
19 |
20 | assertThrows(IllegalArgumentException.class, () -> {
21 | new Car("Fiat", -2);
22 | });
23 | }
24 | }
25 |
--------------------------------------------------------------------------------
/amber/src/test/java/com/example/sealed/AnimalTreeTest.java:
--------------------------------------------------------------------------------
1 | package com.example.sealed;
2 |
3 | import org.junit.jupiter.api.Test;
4 |
5 | import java.lang.reflect.Modifier;
6 |
7 | import static org.junit.jupiter.api.Assertions.assertTrue;
8 |
9 |
10 | public class AnimalTreeTest {
11 |
12 | /*
13 | How Animal tree inheritance should look:
14 | Animal ---
15 | |
16 | |--- Reptile
17 | |--- Mammal ---
18 | |
19 | |--- Elephant
20 | |--- Human
21 | |--- Dog ---
22 | |
23 | |--- GermanShepherd
24 |
25 | Requirements:
26 | * Only Reptile and Mammal can extend Animal
27 | * Any class can extend Mammal.
28 | * There is no way to extend GermanShepherd
29 | */
30 |
31 | @Test
32 | void shouldReptileIsChildOfAnimal() {
33 | Object reptile = new Reptile();
34 |
35 | assertTrue(reptile instanceof Animal);
36 | }
37 |
38 | @Test
39 | void shouldMammalIsChildOfAnimal() {
40 | Object object = new Mammal();
41 | assertTrue(object instanceof Animal);
42 | }
43 |
44 | @Test
45 | void shouldElephantIsChildOfMammal() {
46 | Object object = new Elephant();
47 | assertTrue(object instanceof Mammal);
48 | }
49 |
50 | @Test
51 | void shouldHumanIsChildOfMammal() {
52 | Object object = new Human();
53 | assertTrue(object instanceof Mammal);
54 | }
55 |
56 | @Test
57 | void shouldDogIsChildOfMammal() {
58 | Object object = new Dog();
59 | assertTrue(object instanceof Mammal);
60 | }
61 |
62 | @Test
63 | void shouldGermanShepherdIsChildOfDog() {
64 | Object object = new GermanShepherd();
65 | assertTrue(object instanceof Dog);
66 | }
67 |
68 | @Test
69 | void shouldGermanShepherdIsFinal() {
70 | Object object = new GermanShepherd();
71 | assertTrue(Modifier.isFinal(GermanShepherd.class.getModifiers()));
72 | }
73 | }
74 |
75 |
76 |
77 |
78 |
79 |
80 |
81 |
82 |
83 |
84 |
85 |
86 |
87 |
88 |
89 |
90 |
91 |
92 |
93 |
94 |
95 |
96 |
97 |
98 |
99 |
100 |
101 |
102 |
103 |
104 |
105 |
106 |
107 |
108 |
109 |
110 |
111 |
112 |
113 |
114 |
115 |
116 |
117 |
118 |
119 |
120 |
121 |
122 |
123 |
124 |
125 |
126 |
127 |
128 | /*
129 | SOLUTION:
130 | public sealed class Animal permits Mammal, Reptile
131 | public class Dog extends Mammal
132 | public class Elephant extends Mammal
133 | public final class GermanShepherd extends Dog
134 | public class Human extends Mammal
135 | public non-sealed class Mammal extends Animal
136 | public non-sealed class Reptile extends Animal
137 | */
138 |
--------------------------------------------------------------------------------
/amber/src/test/java/com/example/streamToList/EvenNumberFilterTest.java:
--------------------------------------------------------------------------------
1 | package com.example.streamToList;
2 |
3 | import org.junit.jupiter.api.Test;
4 |
5 | import java.util.List;
6 |
7 | import static org.junit.jupiter.api.Assertions.assertEquals;
8 |
9 | public class EvenNumberFilterTest {
10 | @Test
11 | void shouldReturnOnlyEvenNumbers() {
12 |
13 | EvenNumberFilter sut = new EvenNumberFilter();
14 |
15 | List result = sut.getEvenNumbers(List.of(1, 2, 3, 4, 5, 6, 7, 8, 9));
16 |
17 | assertEquals(List.of(2, 4, 6, 8), result);
18 | }
19 | }
20 |
--------------------------------------------------------------------------------
/amber/src/test/java/com/example/stringMethods/StringServiceTest.java:
--------------------------------------------------------------------------------
1 | package com.example.stringMethods;
2 |
3 | import org.junit.jupiter.api.Test;
4 |
5 | import java.util.Arrays;
6 | import java.util.List;
7 |
8 | import static org.junit.jupiter.api.Assertions.assertEquals;
9 |
10 | class StringServiceTest {
11 | StringService sut = new StringService();
12 |
13 | @Test
14 | void shouldGetOnlyNotBlankStrings() {
15 | List input = Arrays.
16 | asList(
17 | "text1",
18 | "----",
19 | "",
20 | " ",
21 | " A ",
22 | "\n ",
23 | " \r"
24 | );
25 | List result = sut.getOnlyNotBlankStrings(input);
26 |
27 | assertEquals(Arrays.asList("text1", "----", " A "), result);
28 | }
29 |
30 | @Test
31 | void shouldGetStrippedTextLines() {
32 | String lorem = " Lorem ipsum dolor sit amet \n" +
33 | " consectetur \n a\ndipiscing elit.\r" +
34 | "Mauris sed diam eleifend rhoncus sem non rhoncus velit.\n";
35 | List result = sut.getStrippedTextLines(lorem);
36 |
37 | assertEquals(Arrays.asList("Lorem ipsum dolor sit amet","consectetur","a", "dipiscing elit.", "Mauris sed diam eleifend rhoncus sem non rhoncus velit."), result);
38 | }
39 |
40 | @Test
41 | void shouldExtendByRepeatFoundStringSomeTimes() {
42 |
43 | List input = Arrays.asList("some", "example", "string", "list");
44 |
45 | List result = sut.extendFoundStringByRepeatSomeTimes(input,"list", 3);
46 |
47 | assertEquals(Arrays.asList("some", "example", "string", "listlistlist"), result);
48 | }
49 | }
50 |
--------------------------------------------------------------------------------
/amber/src/test/java/com/example/switchExpressions/DayServiceTest.java:
--------------------------------------------------------------------------------
1 | package com.example.switchExpressions;
2 |
3 | import org.junit.jupiter.api.Test;
4 |
5 | import static org.junit.jupiter.api.Assertions.assertEquals;
6 | import static org.junit.jupiter.api.Assertions.assertThrows;
7 |
8 | class DayServiceTest {
9 | DayService dayService = new DayService();
10 |
11 | @Test
12 | void shouldReturnProperValueForMonday() {
13 | int result = dayService.getDayNumberOfLettersForWorkday(Day.MONDAY);
14 |
15 | assertEquals(6, result);
16 | }
17 |
18 | @Test
19 | void shouldReturnProperValueForTuesday() {
20 | int result = dayService.getDayNumberOfLettersForWorkday(Day.TUESDAY);
21 |
22 | assertEquals(7, result);
23 | }
24 |
25 | @Test
26 | void shouldReturnProperValueForThursday() {
27 | int result = dayService.getDayNumberOfLettersForWorkday(Day.THURSDAY);
28 |
29 | assertEquals(8, result);
30 | }
31 |
32 | @Test
33 | void shouldReturnProperValueForWednesday() {
34 | int result = dayService.getDayNumberOfLettersForWorkday(Day.WEDNESDAY);
35 |
36 | assertEquals(9, result);
37 | }
38 |
39 | @Test
40 | void shouldThrowExceptionForNonWorkingDay() {
41 |
42 | assertThrows(IllegalStateException.class, () -> {
43 | dayService.getDayNumberOfLettersForWorkday(Day.SUNDAY);
44 | });
45 | }
46 | }
47 |
--------------------------------------------------------------------------------
/amber/src/test/java/com/example/teeing/employee/EmployeeServiceTest.java:
--------------------------------------------------------------------------------
1 | package com.example.teeing.employee;
2 |
3 | import org.junit.jupiter.api.Test;
4 |
5 | import java.util.List;
6 |
7 | import static org.junit.jupiter.api.Assertions.assertEquals;
8 |
9 | class EmployeeServiceTest {
10 | EmployeeService employeeService = new EmployeeService();
11 |
12 | @Test
13 | void getAvgEmployeeSalary() {
14 |
15 | List employees = List.of(
16 | new Employee(10),
17 | new Employee(20),
18 | new Employee(30),
19 | new Employee(40),
20 | new Employee(50)
21 | );
22 |
23 | double result = employeeService.getAvgEmployeeSalary(employees);
24 |
25 | assertEquals(30.0, result);
26 | }
27 | }
28 |
--------------------------------------------------------------------------------
/amber/src/test/java/com/example/teeing/event/ParticipationServiceTest.java:
--------------------------------------------------------------------------------
1 | package com.example.teeing.event;
2 |
3 | import org.junit.jupiter.api.Test;
4 |
5 | import java.util.Arrays;
6 | import java.util.List;
7 |
8 | import static org.junit.jupiter.api.Assertions.*;
9 |
10 | class ParticipationServiceTest {
11 |
12 | @Test
13 | void processEventGuests() {
14 | List guests = List.of(
15 | new Guest("name1", true, 10),
16 | new Guest("name2", false, 2),
17 | new Guest("name3", true, 5)
18 | );
19 | ParticipationService participationService = new ParticipationService();
20 | EventParticipation eventParticipation = participationService.processEventGuests(guests);
21 |
22 | assertEquals(eventParticipation.getGuestNameList(), Arrays.asList("name1", "name3"));
23 | assertEquals(17, eventParticipation.getTotalNumberOfParticipants());
24 | }
25 | }
26 |
--------------------------------------------------------------------------------
/amber/src/test/java/com/example/textBlock/HtmlCodeTest.java:
--------------------------------------------------------------------------------
1 | package com.example.textBlock;
2 |
3 | import org.junit.jupiter.api.Test;
4 |
5 | import static org.junit.jupiter.api.Assertions.*;
6 |
7 | class HtmlCodeTest {
8 |
9 | @Test
10 | void getHtml() {
11 | HtmlCode htmlCode = new HtmlCode();
12 |
13 | String result = htmlCode.getHtml();
14 |
15 | assertEquals("\n" +
16 | "\n" +
17 | " \n" +
18 | " \n" +
19 | " My test page\n" +
20 | " \n" +
21 | " \n" +
22 | "
\n" +
23 | " \n" +
24 | "\n", result);
25 | }
26 | }
27 |
--------------------------------------------------------------------------------
/amber/src/test/java/com/example/transform/ImportedCSVTextProcessorTest.java:
--------------------------------------------------------------------------------
1 | package com.example.transform;
2 |
3 | import org.junit.jupiter.api.Test;
4 |
5 | import static org.junit.jupiter.api.Assertions.assertEquals;
6 |
7 | class ImportedCSVTextProcessorTest {
8 |
9 | @Test
10 | void process() {
11 | ImportedCSVTextProcessor sut = new ImportedCSVTextProcessor();
12 |
13 | String result = sut.process("\n \nLorem,Ipsum,is, simply,dummy,text none,of, the ,printing,and,typesetting,industry., Lorem,Ipsum,has,");
14 |
15 | assertEquals("LOREM IPSUM IS SIMPLY DUMMY TEXT OF THE PRINTING AND TYPESETTING INDUSTRY. LOREM IPSUM HAS-DONE", result
16 | );
17 |
18 | }
19 | }
20 |
--------------------------------------------------------------------------------
/amber/src/test/java/com/example/transform/PalindromeCheckerTest.java:
--------------------------------------------------------------------------------
1 | package com.example.transform;
2 |
3 | import org.junit.jupiter.api.Test;
4 | import org.junit.jupiter.params.ParameterizedTest;
5 | import org.junit.jupiter.params.provider.ValueSource;
6 |
7 | import static org.junit.jupiter.api.Assertions.*;
8 |
9 | class PalindromeCheckerTest {
10 |
11 | PalindromeChecker checker = new PalindromeChecker();
12 |
13 | @ParameterizedTest
14 | @ValueSource(strings = {"zaraz","kajak","anna","sedes","mam", "ala","radar"})
15 | void shouldReturnTrueForPalindrome(String text) {
16 | boolean result = checker.isPalindrome(text);
17 |
18 | assertTrue(result);
19 | }
20 |
21 | @Test
22 | void shouldReturnFalseForNonPalindrome() {
23 | boolean result = checker.isPalindrome("Programowanie");
24 |
25 | assertFalse(result);
26 | }
27 | }
28 |
--------------------------------------------------------------------------------
/amber/src/test/java/com/example/unmodifiableCollections/MyServiceTest.java:
--------------------------------------------------------------------------------
1 | package com.example.unmodifiableCollections;
2 |
3 | import org.junit.jupiter.api.Test;
4 |
5 | import java.util.List;
6 |
7 | import static org.junit.jupiter.api.Assertions.*;
8 |
9 | class MyServiceTest {
10 | MyService myService = new MyService();
11 |
12 |
13 | @Test
14 | void getUnmodifiableListByCollector() {
15 | List result = myService.getUnmodifiableListByCollector();
16 |
17 | assertThrows(UnsupportedOperationException.class, () -> {
18 | result.add(5);
19 | });
20 | }
21 |
22 | @Test
23 | void getUnmodifiableListByCopy() {
24 | List result = myService.getUnmodifiableListByCopy();
25 |
26 | assertThrows(UnsupportedOperationException.class, () -> {
27 | result.add(5);
28 | });
29 |
30 | }
31 | }
32 |
--------------------------------------------------------------------------------
/amber/src/test/java/com/example/var/StudentTest.java:
--------------------------------------------------------------------------------
1 | package com.example.var;
2 |
3 | import org.junit.jupiter.api.Test;
4 |
5 | import java.math.BigDecimal;
6 | import java.util.Arrays;
7 | import java.util.List;
8 |
9 | import static org.junit.jupiter.api.Assertions.assertEquals;
10 |
11 | public class StudentTest {
12 |
13 | Student sut = new Student(new Integer[]{2, 2, 3, 3, 3, 4, 4});
14 |
15 | @Test
16 | void shouldGetNumberOfMarks() {
17 | Integer result = sut.getNumberOfMarks();
18 |
19 | assertEquals(7, result);
20 | }
21 |
22 | @Test
23 | void shouldGetTotalSumOfMarks() {
24 | Integer result = sut.getTotalSumOfMarks();
25 |
26 | assertEquals(21, result);
27 | }
28 |
29 | @Test
30 | void shouldGetAverageOfMarks() {
31 | BigDecimal result = sut.getAverageOfMarks();
32 |
33 | assertEquals(3, result.intValue());
34 | }
35 |
36 | @Test
37 | void shouldGetMaximumMark() {
38 | Integer result = sut.getMaximumMark();
39 | assertEquals(4, result.intValue());
40 | }
41 |
42 | @Test
43 | void shouldGetMinimumMark() {
44 | Integer result = sut.getMinimumMark();
45 |
46 | assertEquals(2, result.intValue());
47 | }
48 |
49 | @Test
50 | void shouldGetDistinctMarks() {
51 | List result = sut.getDistinctMarks();
52 |
53 | assertEquals(Arrays.asList(2, 3, 4), result);
54 | }
55 | }
56 |
--------------------------------------------------------------------------------
/amber/tmp/java-versions-cheat-sheet-happycoders.eu-v22.0.3.pdf:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/zzpj/pl-java2024/b3607327e97ffb15868a519cb595df959329c5f8/amber/tmp/java-versions-cheat-sheet-happycoders.eu-v22.0.3.pdf
--------------------------------------------------------------------------------
/bdd/.gitignore:
--------------------------------------------------------------------------------
1 | # Maven
2 | target/
3 |
4 | # Ignore Gradle GUI config
5 | gradle-app.setting
6 |
7 | # Eclipse
8 | /.classpath
9 | /.settings/
10 | /.project
11 | /bin/
12 |
13 | # IntelliJ
14 | .idea
15 | *.iml
16 | *.ipr
17 | *.iws
18 |
19 | # Misc
20 | *.log
21 |
--------------------------------------------------------------------------------
/bdd/.mvn/wrapper/maven-wrapper.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/zzpj/pl-java2024/b3607327e97ffb15868a519cb595df959329c5f8/bdd/.mvn/wrapper/maven-wrapper.jar
--------------------------------------------------------------------------------
/bdd/.mvn/wrapper/maven-wrapper.properties:
--------------------------------------------------------------------------------
1 | distributionUrl=https://repo1.maven.org/maven2/org/apache/maven/apache-maven/3.5.0/apache-maven-3.5.0-bin.zip
--------------------------------------------------------------------------------
/bdd/docs/bdd-vs-tdd.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/zzpj/pl-java2024/b3607327e97ffb15868a519cb595df959329c5f8/bdd/docs/bdd-vs-tdd.png
--------------------------------------------------------------------------------
/bdd/docs/bdd.md:
--------------------------------------------------------------------------------
1 | # Behaviour Driven Development
2 |
3 | ## Definicja
4 | * Behavior-Driven Development (BDD) polega na tworzeniu oprogramowania poprzez opisywanie pewnego zachowania z perspektywy jego użytkowników
5 | * BDD to proces wytwarzania oprogramowania, w którym dokumentacja i testy są pisane w języku naturalnym. Jest integralną częścią całego cyklu wytwarzania oprogramowania.
6 | * Funkcjonalność oprogramowania powinna być opisana w języku **Gherkin** jeszcze na etapie zbierania wymagań i analizy, a następnie wykorzystywana w fazie projektowania i implementacji.
7 |
8 | # TDD vs BDD
9 | * w TDD rozwój oprogramowania opiera się tu na testach napisanych dla jeszcze nieistniejących funkcjonalności, podczas gdy BDD ma na celu wykorzystanie zrozumiałego
10 | dla wszystkich nawet osób bez wiedzy technicznej języka
11 | * TDD jest dla dewelopera, BDD dla klienta (i/lub analityka, product owner'a)
12 | 
13 |
14 |
15 | ## Idealny scenariusz współpracy analityka biznesowego oraz dewelopera i/lub testera
16 | Rozpoczynając testy manualne, tester opiera się na istniejącej dokumentacji, która w jasny sposób pokazuje mu warunki początkowe, wszystkie niezbędne akcje i ich finał.
17 | Następnie na jej podstawie tworzone są testy automatyczne z zachowaniem języka naturalnego. Tester lub deweloper otrzymuje zadanie do przetestowania manualnego/napisania
18 | testu automatycznego i dzięki czytelnej formie zapisu wie, czym ma się zająć. W teorii, interpretacja zadania nie powinna być problemem.
19 |
20 | ## Zalety BDD
21 | Odpowiednio skonstruowana dokumentacja:
22 |
23 | ````gherkin
24 | Scenario: User add article
25 | Given User is logged in
26 | When User add new article
27 | Then Article should be displayed
28 | ````
29 | wykorzystująca język naturalny, dostępna dla wszystkich członków projektu, może wspierając rozwój aplikacji na różnych etapach.
30 | Można omawiać ją na spotkaniach przed implementacją oraz w jej trakcie, a następnie wykorzystać w testach automatycznych i raportach.
31 | Jest przydatna dla osób bez wiedzy technicznej (np. osoba z biznesu), którzy mają wgląd czy zadane ścieżki biznesowe są pokryte przez testy automatyczne, a rozwój aplikacji idzie w dobrą stronę.
32 |
33 | [](https://youtu.be/fX2altB4AME)
34 |
35 | ## Wady i błędy w wykorzystaniu BDD
36 | * Biznes nie dostarcza gotowych scenariuszy w formie „Given, When, Then”
37 | * Scenariusz testów jest tworzony po czasie
38 | * Biznes nie jest zainteresowany treścią testów
39 |
40 | ## Linki
41 | * [Cucumber](https://cucumber.io/docs/cucumber/)
42 |
--------------------------------------------------------------------------------
/bdd/mvnw.cmd:
--------------------------------------------------------------------------------
1 | @REM ----------------------------------------------------------------------------
2 | @REM Licensed to the Apache Software Foundation (ASF) under one
3 | @REM or more contributor license agreements. See the NOTICE file
4 | @REM distributed with this work for additional information
5 | @REM regarding copyright ownership. The ASF licenses this file
6 | @REM to you under the Apache License, Version 2.0 (the
7 | @REM "License"); you may not use this file except in compliance
8 | @REM with the License. You may obtain a copy of the License at
9 | @REM
10 | @REM http://www.apache.org/licenses/LICENSE-2.0
11 | @REM
12 | @REM Unless required by applicable law or agreed to in writing,
13 | @REM software distributed under the License is distributed on an
14 | @REM "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15 | @REM KIND, either express or implied. See the License for the
16 | @REM specific language governing permissions and limitations
17 | @REM under the License.
18 | @REM ----------------------------------------------------------------------------
19 |
20 | @REM ----------------------------------------------------------------------------
21 | @REM Maven2 Start Up Batch script
22 | @REM
23 | @REM Required ENV vars:
24 | @REM JAVA_HOME - location of a JDK home dir
25 | @REM
26 | @REM Optional ENV vars
27 | @REM M2_HOME - location of maven2's installed home dir
28 | @REM MAVEN_BATCH_ECHO - set to 'on' to enable the echoing of the batch commands
29 | @REM MAVEN_BATCH_PAUSE - set to 'on' to wait for a key stroke before ending
30 | @REM MAVEN_OPTS - parameters passed to the Java VM when running Maven
31 | @REM e.g. to debug Maven itself, use
32 | @REM set MAVEN_OPTS=-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=8000
33 | @REM MAVEN_SKIP_RC - flag to disable loading of mavenrc files
34 | @REM ----------------------------------------------------------------------------
35 |
36 | @REM Begin all REM lines with '@' in case MAVEN_BATCH_ECHO is 'on'
37 | @echo off
38 | @REM enable echoing my setting MAVEN_BATCH_ECHO to 'on'
39 | @if "%MAVEN_BATCH_ECHO%" == "on" echo %MAVEN_BATCH_ECHO%
40 |
41 | @REM set %HOME% to equivalent of $HOME
42 | if "%HOME%" == "" (set "HOME=%HOMEDRIVE%%HOMEPATH%")
43 |
44 | @REM Execute a user defined script before this one
45 | if not "%MAVEN_SKIP_RC%" == "" goto skipRcPre
46 | @REM check for pre script, once with legacy .bat ending and once with .cmd ending
47 | if exist "%HOME%\mavenrc_pre.bat" call "%HOME%\mavenrc_pre.bat"
48 | if exist "%HOME%\mavenrc_pre.cmd" call "%HOME%\mavenrc_pre.cmd"
49 | :skipRcPre
50 |
51 | @setlocal
52 |
53 | set ERROR_CODE=0
54 |
55 | @REM To isolate internal variables from possible post scripts, we use another setlocal
56 | @setlocal
57 |
58 | @REM ==== START VALIDATION ====
59 | if not "%JAVA_HOME%" == "" goto OkJHome
60 |
61 | echo.
62 | echo Error: JAVA_HOME not found in your environment. >&2
63 | echo Please set the JAVA_HOME variable in your environment to match the >&2
64 | echo location of your Java installation. >&2
65 | echo.
66 | goto error
67 |
68 | :OkJHome
69 | if exist "%JAVA_HOME%\bin\java.exe" goto init
70 |
71 | echo.
72 | echo Error: JAVA_HOME is set to an invalid directory. >&2
73 | echo JAVA_HOME = "%JAVA_HOME%" >&2
74 | echo Please set the JAVA_HOME variable in your environment to match the >&2
75 | echo location of your Java installation. >&2
76 | echo.
77 | goto error
78 |
79 | @REM ==== END VALIDATION ====
80 |
81 | :init
82 |
83 | @REM Find the project base dir, i.e. the directory that contains the folder ".mvn".
84 | @REM Fallback to current working directory if not found.
85 |
86 | set MAVEN_PROJECTBASEDIR=%MAVEN_BASEDIR%
87 | IF NOT "%MAVEN_PROJECTBASEDIR%"=="" goto endDetectBaseDir
88 |
89 | set EXEC_DIR=%CD%
90 | set WDIR=%EXEC_DIR%
91 | :findBaseDir
92 | IF EXIST "%WDIR%"\.mvn goto baseDirFound
93 | cd ..
94 | IF "%WDIR%"=="%CD%" goto baseDirNotFound
95 | set WDIR=%CD%
96 | goto findBaseDir
97 |
98 | :baseDirFound
99 | set MAVEN_PROJECTBASEDIR=%WDIR%
100 | cd "%EXEC_DIR%"
101 | goto endDetectBaseDir
102 |
103 | :baseDirNotFound
104 | set MAVEN_PROJECTBASEDIR=%EXEC_DIR%
105 | cd "%EXEC_DIR%"
106 |
107 | :endDetectBaseDir
108 |
109 | IF NOT EXIST "%MAVEN_PROJECTBASEDIR%\.mvn\jvm.config" goto endReadAdditionalConfig
110 |
111 | @setlocal EnableExtensions EnableDelayedExpansion
112 | for /F "usebackq delims=" %%a in ("%MAVEN_PROJECTBASEDIR%\.mvn\jvm.config") do set JVM_CONFIG_MAVEN_PROPS=!JVM_CONFIG_MAVEN_PROPS! %%a
113 | @endlocal & set JVM_CONFIG_MAVEN_PROPS=%JVM_CONFIG_MAVEN_PROPS%
114 |
115 | :endReadAdditionalConfig
116 |
117 | SET MAVEN_JAVA_EXE="%JAVA_HOME%\bin\java.exe"
118 |
119 | set WRAPPER_JAR="%MAVEN_PROJECTBASEDIR%\.mvn\wrapper\maven-wrapper.jar"
120 | set WRAPPER_LAUNCHER=org.apache.maven.wrapper.MavenWrapperMain
121 |
122 | %MAVEN_JAVA_EXE% %JVM_CONFIG_MAVEN_PROPS% %MAVEN_OPTS% %MAVEN_DEBUG_OPTS% -classpath %WRAPPER_JAR% "-Dmaven.multiModuleProjectDirectory=%MAVEN_PROJECTBASEDIR%" %WRAPPER_LAUNCHER% %MAVEN_CONFIG% %*
123 | if ERRORLEVEL 1 goto error
124 | goto end
125 |
126 | :error
127 | set ERROR_CODE=1
128 |
129 | :end
130 | @endlocal & set ERROR_CODE=%ERROR_CODE%
131 |
132 | if not "%MAVEN_SKIP_RC%" == "" goto skipRcPost
133 | @REM check for post script, once with legacy .bat ending and once with .cmd ending
134 | if exist "%HOME%\mavenrc_post.bat" call "%HOME%\mavenrc_post.bat"
135 | if exist "%HOME%\mavenrc_post.cmd" call "%HOME%\mavenrc_post.cmd"
136 | :skipRcPost
137 |
138 | @REM pause the script if MAVEN_BATCH_PAUSE is set to 'on'
139 | if "%MAVEN_BATCH_PAUSE%" == "on" pause
140 |
141 | if "%MAVEN_TERMINATE_CMD%" == "on" exit %ERROR_CODE%
142 |
143 | exit /B %ERROR_CODE%
144 |
--------------------------------------------------------------------------------
/bdd/pom.xml:
--------------------------------------------------------------------------------
1 |
2 |
4 | 4.0.0
5 |
6 | com.example
7 | unit-and-bdd
8 | 1.0-SNAPSHOT
9 |
10 |
11 | UTF-8
12 | 17
13 | 5.9.2
14 | 3.9.0
15 | 3.0.0-M8
16 | 7.11.1
17 | 1.18.26
18 |
19 |
20 |
21 |
22 |
23 | io.cucumber
24 | cucumber-bom
25 | ${cucumber.version}
26 | pom
27 | import
28 |
29 |
30 | org.junit
31 | junit-bom
32 | ${junit.platform.version}
33 | pom
34 | import
35 |
36 |
37 |
38 |
39 |
40 |
41 | io.cucumber
42 | cucumber-java
43 | test
44 |
45 |
46 | io.cucumber
47 | cucumber-junit-platform-engine
48 | test
49 |
50 |
51 | org.junit.platform
52 | junit-platform-suite
53 | test
54 |
55 |
56 | org.junit.jupiter
57 | junit-jupiter
58 | test
59 |
60 |
61 |
62 | org.projectlombok
63 | lombok
64 | ${lombok.version}
65 | provided
66 |
67 |
68 | org.seleniumhq.selenium
69 | selenium-java
70 | 4.8.0
71 |
72 |
73 |
74 |
75 |
76 |
77 | maven-compiler-plugin
78 | ${maven.compiler.plugin.version}
79 |
80 | ${java.version}
81 | ${java.version}
82 |
83 |
84 |
85 | maven-surefire-plugin
86 | ${maven.surefire.plugin.version}
87 |
88 |
89 | **/Test*.java
90 | **/*Test.java
91 | **/*Tests.java
92 | **/*TestCase.java
93 |
94 |
95 |
96 |
97 |
98 |
99 |
100 |
101 |
--------------------------------------------------------------------------------
/bdd/src/main/java/com/example/FizzBuzzProblem.java:
--------------------------------------------------------------------------------
1 | package com.example;
2 |
3 | public class FizzBuzzProblem {
4 |
5 | public String getFizzBuzzNumber(int number) {
6 | if (number % 15 == 0) {
7 | return "FizzBuzz";
8 | } else if (number % 5 == 0) {
9 | return "Buzz";
10 | } else if (number % 3 == 0) {
11 | return "Fizz";
12 | }
13 | return String.valueOf(number);
14 | }
15 | }
16 |
--------------------------------------------------------------------------------
/bdd/src/main/java/com/example/MyStack.java:
--------------------------------------------------------------------------------
1 | package com.example;
2 |
3 | import java.util.*;
4 |
5 | public class MyStack {
6 |
7 | private Deque stack;
8 |
9 | public MyStack() {
10 | this.stack = new ArrayDeque<>();
11 | }
12 |
13 | public void push(T t) {
14 | stack.push(t);
15 | }
16 |
17 | public T pop() {
18 | return stack.pop();
19 | }
20 |
21 | public T top() {
22 | return stack.peek();
23 | }
24 |
25 | public int size() {
26 | return stack.size();
27 | }
28 |
29 | public boolean isEmpty() {
30 | return size() == 0;
31 | }
32 |
33 | }
34 |
--------------------------------------------------------------------------------
/bdd/src/test/java/com/example/bdd/DatatableExamplStepDefinitions.java:
--------------------------------------------------------------------------------
1 | package com.example.bdd;
2 |
3 | import io.cucumber.datatable.*;
4 | import io.cucumber.java.DataTableType;
5 | import io.cucumber.java.en.*;
6 |
7 | import java.time.*;
8 | import java.time.format.*;
9 | import java.util.*;
10 | import java.util.regex.*;
11 |
12 | import static org.junit.jupiter.api.Assertions.*;
13 |
14 | public class DatatableExamplStepDefinitions {
15 |
16 | List userInfos;
17 |
18 | @Given("user info data table")
19 | public void userInfoDataTable(List userInfos) {
20 | // List> lists = dataTable.asLists();
21 | // List