├── .gitignore ├── 1.1_intro └── hello-programming │ └── src │ └── Main.java ├── 1.2_programming └── variables │ └── src │ └── Main.java ├── 2.1_data └── bonus │ └── src │ ├── MainV1.java │ ├── MainV2.java │ ├── MainV3.java │ ├── MainV4.java │ ├── MainV5.java │ └── MainV6.java ├── 2.2_methods └── src │ ├── BonusService.java │ └── Main.java ├── 2.3_maven-junit ├── bonus-calculator │ ├── pom.xml │ └── src │ │ ├── main │ │ └── java │ │ │ ├── BonusService.java │ │ │ └── Main.java │ │ └── test │ │ └── java │ │ └── BonusServiceTest.java ├── bonus-handmade │ └── src │ │ ├── BonusService.java │ │ └── Main.java └── xml.md ├── 2.4_params ├── bonus-calculator │ ├── pom.xml │ └── src │ │ ├── main │ │ └── java │ │ │ └── ru │ │ │ └── netology │ │ │ └── bonus │ │ │ ├── BonusService.java │ │ │ └── Main.java │ │ └── test │ │ └── java │ │ └── ru │ │ └── netology │ │ └── bonus │ │ └── BonusServiceTest.java └── statistics │ ├── pom.xml │ └── src │ ├── main │ └── java │ │ └── ru │ │ └── netology │ │ └── statistic │ │ └── StatisticsService.java │ └── test │ └── java │ └── ru │ └── netology │ └── statistic │ └── StatisticsServiceTest.java ├── 2.5_ci ├── .github │ └── workflows │ │ └── maven.yml ├── .gitignore ├── pom.xml └── src │ ├── main │ └── java │ │ └── ru │ │ └── netology │ │ └── statistic │ │ └── StatisticsService.java │ └── test │ └── java │ └── ru │ └── netology │ └── statistic │ └── StatisticsServiceTest.java ├── 3.1_oop1 └── smart-house │ ├── pom.xml │ └── src │ ├── main │ └── java │ │ └── ru │ │ └── netology │ │ ├── Conditioner.java │ │ └── ConditionerAdvanced.java │ └── test │ └── java │ └── ru │ └── netology │ ├── ConditionerAdvancedTest.java │ └── ConditionerTest.java ├── 3.2_oop2 └── principles │ ├── pom.xml │ └── src │ └── main │ └── java │ └── ru │ └── netology │ ├── domain │ ├── Conditioner.java │ └── Movie.java │ └── manager │ ├── MainPageManager.java │ └── MovieManager.java ├── 3.3_state ├── pom.xml └── src │ ├── main │ └── java │ │ └── ru │ │ └── netology │ │ └── domain │ │ ├── constructor │ │ ├── field │ │ └── Conditioner.java │ │ └── lombok │ │ └── Conditioner.java │ └── test │ └── java │ └── ru │ └── netology │ └── domain │ ├── constructor │ └── field │ └── ConditionerTest.java ├── 3.4_dependency ├── cart-server │ ├── .gitignore │ ├── .mvn │ │ └── wrapper │ │ │ ├── MavenWrapperDownloader.java │ │ │ ├── maven-wrapper.jar │ │ │ └── maven-wrapper.properties │ ├── mvnw │ ├── mvnw.cmd │ ├── pom.xml │ └── src │ │ ├── main │ │ ├── java │ │ │ └── ru │ │ │ │ └── netology │ │ │ │ └── cartserver │ │ │ │ ├── CartServerApplication.java │ │ │ │ ├── controller │ │ │ │ └── CartController.java │ │ │ │ ├── domain │ │ │ │ └── PurchaseItem.java │ │ │ │ ├── repository │ │ │ │ └── CartRepository.java │ │ │ │ └── service │ │ │ │ └── CartService.java │ │ └── resources │ │ │ └── application.properties │ │ └── test │ │ └── java │ │ └── ru │ │ └── netology │ │ └── cartserver │ │ └── CartServerApplicationTests.java ├── cart-with-mocks │ ├── pom.xml │ └── src │ │ ├── main │ │ └── java │ │ │ └── ru │ │ │ └── netology │ │ │ ├── Main.java │ │ │ ├── domain │ │ │ └── PurchaseItem.java │ │ │ ├── manager │ │ │ └── CartManager.java │ │ │ └── repository │ │ │ └── CartRepository.java │ │ └── test │ │ └── java │ │ └── ru │ │ └── netology │ │ └── manager │ │ └── CartManagerTestNonEmpty.java └── cart │ ├── pom.xml │ └── src │ ├── main │ └── java │ │ └── ru │ │ └── netology │ │ ├── domain │ │ └── PurchaseItem.java │ │ └── manager │ │ └── CartManager.java │ └── test │ └── java │ └── ru │ └── netology │ └── manager │ ├── CartManagerTestNonEmpty.java │ └── CartManagerTestNonEmptyWithSetup.java ├── 3.5_inheritance ├── lombok-inheritance │ ├── pom.xml │ └── src │ │ └── main │ │ └── java │ │ └── ru │ │ └── netology │ │ └── domain │ │ ├── Book.java │ │ └── Product.java ├── products │ ├── pom.xml │ └── src │ │ ├── main │ │ └── java │ │ │ └── ru │ │ │ └── netology │ │ │ ├── domain │ │ │ ├── Book.java │ │ │ ├── MFU.java │ │ │ ├── Product.java │ │ │ └── TShirt.java │ │ │ └── repository │ │ │ └── ProductRepository.java │ │ └── test │ │ └── java │ │ └── ru │ │ └── netology │ │ ├── domain │ │ ├── BookTest.java │ │ └── ProductTest.java │ │ └── repository │ │ └── ProductRepositoryTest.java ├── reflection-sample │ ├── pom.xml │ └── src │ │ └── test │ │ └── java │ │ └── ru │ │ └── netology │ │ ├── DemoTest.java │ │ └── Launcher.java └── static-sample │ ├── pom.xml │ └── src │ ├── main │ └── java │ │ └── ru │ │ └── netology │ │ └── Main.java │ └── test │ └── java │ └── ru │ └── netology │ └── SampleTest.java ├── 4.1_exceptions ├── exception-types │ ├── pom.xml │ └── src │ │ ├── main │ │ └── java │ │ │ ├── Main.java │ │ │ ├── exception │ │ │ ├── CheckedException.java │ │ │ └── UncheckedException.java │ │ │ └── service │ │ │ └── Service.java │ │ └── test │ │ └── java │ │ └── service │ │ └── ServiceTest.java └── exceptions │ ├── pom.xml │ └── src │ └── main │ └── java │ └── ru │ └── netology │ ├── Main.java │ ├── domain │ └── PurchaseItem.java │ ├── manager │ └── CartManager.java │ └── repository │ └── CartRepository.java ├── 4.2_interfaces ├── mfu │ ├── pom.xml │ └── src │ │ └── main │ │ └── java │ │ └── ru │ │ └── netology │ │ ├── Printer.java │ │ ├── Scanner.java │ │ ├── domain │ │ └── Document.java │ │ ├── hp │ │ ├── LJ1210.java │ │ └── LJProM283.java │ │ └── service │ │ └── OfficeService.java └── sorting │ ├── pom.xml │ └── src │ ├── main │ └── java │ │ └── ru │ │ └── netology │ │ ├── container │ │ ├── Box.java │ │ └── GenericBox.java │ │ └── domain │ │ └── Product.java │ └── test │ └── java │ └── ru │ └── netology │ ├── MathTest.java │ ├── container │ ├── BoxTest.java │ └── GenericBoxTest.java │ └── domain │ └── ProductsTest.java ├── 4.3_collections └── collections │ ├── pom.xml │ └── src │ ├── main │ └── java │ │ └── ru │ │ └── netology │ │ ├── domain │ │ ├── Book.java │ │ └── Product.java │ │ ├── generic │ │ ├── ParametrizedMethod.java │ │ └── ParametrizedType.java │ │ └── repository │ │ └── ProductRepository.java │ └── test │ └── java │ └── ru │ └── netology │ └── repository │ ├── CRUDRepositoryTest.java │ ├── ProductRepositoryTest.java │ └── ProductRepositoryTestWithListOf.java └── README.md /.gitignore: -------------------------------------------------------------------------------- 1 | Thumbs.db* 2 | .DS_Store 3 | HELP.md 4 | .gradle 5 | build/ 6 | target/ 7 | 8 | ### STS ### 9 | .apt_generated 10 | .classpath 11 | .factorypath 12 | .project 13 | .settings 14 | .springBeans 15 | .sts4-cache 16 | 17 | ### IntelliJ IDEA ### 18 | .idea 19 | *.iws 20 | *.iml 21 | *.ipr 22 | out/ 23 | 24 | ### NetBeans ### 25 | /nbproject/private/ 26 | /nbbuild/ 27 | /dist/ 28 | /nbdist/ 29 | /.nb-gradle/ 30 | 31 | ### VS Code ### 32 | .vscode/ 33 | 34 | ### Package Files ### 35 | *.jar 36 | *.war 37 | *.nar 38 | *.ear 39 | *.zip 40 | *.tar.gz 41 | *.rar 42 | 43 | ### Node ### 44 | node_modules/ 45 | -------------------------------------------------------------------------------- /1.1_intro/hello-programming/src/Main.java: -------------------------------------------------------------------------------- 1 | public class Main { 2 | public static void main(String[] args) { 3 | System.out.println("Hello programming!"); 4 | } 5 | } 6 | -------------------------------------------------------------------------------- /1.2_programming/variables/src/Main.java: -------------------------------------------------------------------------------- 1 | public class Main { 2 | public static void main(String[] args) { 3 | int price = 150; 4 | int count = 5; 5 | int total = price * count; 6 | System.out.println(total); 7 | } 8 | } 9 | 10 | -------------------------------------------------------------------------------- /2.1_data/bonus/src/MainV1.java: -------------------------------------------------------------------------------- 1 | public class MainV1 { 2 | public static void main(String[] args) { 3 | boolean registered = true; 4 | float amount = 1000.60F; 5 | float percent = 0.03F; 6 | 7 | float bonus = amount * percent; 8 | System.out.println(bonus); 9 | } 10 | } -------------------------------------------------------------------------------- /2.1_data/bonus/src/MainV2.java: -------------------------------------------------------------------------------- 1 | public class MainV2 { 2 | public static void main(String[] args) { 3 | boolean registered = true; 4 | long amount = 100060; 5 | int percent = 3; 6 | 7 | long bonus = amount / 100 * percent / 100; 8 | System.out.println(bonus); 9 | } 10 | } 11 | 12 | -------------------------------------------------------------------------------- /2.1_data/bonus/src/MainV3.java: -------------------------------------------------------------------------------- 1 | public class MainV3 { 2 | public static void main(String[] args) { 3 | boolean registered = true; 4 | long amount = 100060; 5 | int percent = 3; 6 | 7 | long bonus = amount * percent / 100 / 100; 8 | System.out.println(bonus); 9 | } 10 | } 11 | 12 | -------------------------------------------------------------------------------- /2.1_data/bonus/src/MainV4.java: -------------------------------------------------------------------------------- 1 | public class MainV4 { 2 | public static void main(String[] args) { 3 | boolean registered = true; 4 | int percent; 5 | if (registered) { 6 | percent = 3; 7 | } else { 8 | percent = 1; 9 | } 10 | long amount = 100060; 11 | long bonus = amount * percent / 100 / 100; 12 | System.out.println(bonus); 13 | } 14 | } 15 | 16 | 17 | 18 | -------------------------------------------------------------------------------- /2.1_data/bonus/src/MainV5.java: -------------------------------------------------------------------------------- 1 | public class MainV5 { 2 | public static void main(String[] args) { 3 | boolean registered = true; 4 | int percent; 5 | if (registered) { 6 | percent = 3; 7 | } else { 8 | percent = 1; 9 | } 10 | long amount = 100060; 11 | long bonus = amount * percent / 100 / 100; 12 | long limit = 500; 13 | if (bonus > limit) { 14 | bonus = limit; 15 | } 16 | System.out.println(bonus); 17 | } 18 | } 19 | 20 | 21 | -------------------------------------------------------------------------------- /2.1_data/bonus/src/MainV6.java: -------------------------------------------------------------------------------- 1 | public class MainV6 { 2 | public static void main(String[] args) { 3 | boolean registered = true; 4 | int percent = registered ? 3 : 1; 5 | long amount = 100060; 6 | long bonus = amount * percent / 100 / 100; 7 | long limit = 500; 8 | if (bonus > limit) { 9 | bonus = limit; 10 | } 11 | System.out.println(bonus); 12 | } 13 | } 14 | 15 | 16 | -------------------------------------------------------------------------------- /2.2_methods/src/BonusService.java: -------------------------------------------------------------------------------- 1 | public class BonusService { 2 | public long calculate(long amount, boolean registered) { 3 | int percent = registered ? 3 : 1; 4 | long bonus = amount * percent / 100 / 100; 5 | long limit = 500; 6 | if (bonus > limit) { 7 | bonus = limit; 8 | } 9 | return bonus; 10 | } 11 | } 12 | 13 | 14 | -------------------------------------------------------------------------------- /2.2_methods/src/Main.java: -------------------------------------------------------------------------------- 1 | public class Main { 2 | public static void main(String[] args) { 3 | BonusService service = new BonusService(); 4 | 5 | long bonusBelowLimitForRegistered = service.calculate(1000_60, true); 6 | System.out.println(bonusBelowLimitForRegistered); 7 | 8 | long bonusOverLimitForRegistered = service.calculate(1_000_000_60, true); 9 | System.out.println(bonusOverLimitForRegistered); 10 | 11 | long bonusBelowLimitForUnRegistered = service.calculate(1000_60, false); 12 | System.out.println(bonusBelowLimitForUnRegistered); 13 | 14 | long bonusOverLimitForUnRegistered = service.calculate(1_000_000_60, true); 15 | System.out.println(bonusOverLimitForUnRegistered); 16 | } 17 | } 18 | 19 | -------------------------------------------------------------------------------- /2.3_maven-junit/bonus-calculator/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 4.0.0 6 | 7 | ru.netology 8 | bonus-calculator 9 | 1.0-SNAPSHOT 10 | 11 | 12 | 11 13 | 11 14 | UTF-8 15 | 16 | 17 | 18 | 19 | org.junit.jupiter 20 | junit-jupiter 21 | 5.4.2 22 | test 23 | 24 | 25 | 26 | 27 | 28 | 29 | org.apache.maven.plugins 30 | maven-surefire-plugin 31 | 2.22.2 32 | 33 | 34 | 35 | 36 | 37 | 38 | -------------------------------------------------------------------------------- /2.3_maven-junit/bonus-calculator/src/main/java/BonusService.java: -------------------------------------------------------------------------------- 1 | public class BonusService { 2 | public long calculate(long amount, boolean registered) { 3 | int percent = registered ? 3 : 1; 4 | long bonus = amount * percent / 100 / 100; 5 | long limit = 500; 6 | if (bonus > limit) { 7 | bonus = limit; 8 | } 9 | return bonus; 10 | } 11 | } 12 | 13 | 14 | -------------------------------------------------------------------------------- /2.3_maven-junit/bonus-calculator/src/main/java/Main.java: -------------------------------------------------------------------------------- 1 | public class Main { 2 | public static void main(String[] args) { 3 | BonusService service = new BonusService(); 4 | 5 | // подготавливаем данные: 6 | long amount = 1000_60; 7 | boolean registered = true; 8 | long expected = 30; 9 | 10 | // вызываем целевой метод: 11 | long actual = service.calculate(amount, registered); 12 | 13 | // производим проверку (сравниваем ожидаемый и фактический): 14 | // если true - то PASS 15 | // если false - то FAIL 16 | boolean passed = expected == actual; 17 | 18 | // выводим результат 19 | System.out.println(passed); 20 | } 21 | } 22 | 23 | -------------------------------------------------------------------------------- /2.3_maven-junit/bonus-calculator/src/test/java/BonusServiceTest.java: -------------------------------------------------------------------------------- 1 | import static org.junit.jupiter.api.Assertions.*; 2 | 3 | class BonusServiceTest { 4 | 5 | @org.junit.jupiter.api.Test 6 | void shouldCalculateForRegisteredAndUnderLimit() { 7 | BonusService service = new BonusService(); 8 | 9 | // подготавливаем данные: 10 | long amount = 1000_60; 11 | boolean registered = true; 12 | long expected = 30; 13 | 14 | // вызываем целевой метод: 15 | long actual = service.calculate(amount, registered); 16 | 17 | // производим проверку (сравниваем ожидаемый и фактический): 18 | assertEquals(expected, actual); 19 | } 20 | 21 | @org.junit.jupiter.api.Test 22 | void shouldCalculateForRegisteredAndOverLimit() { 23 | BonusService service = new BonusService(); 24 | 25 | // подготавливаем данные: 26 | long amount = 1_000_000_60; 27 | boolean registered = true; 28 | long expected = 500; 29 | 30 | // вызываем целевой метод: 31 | long actual = service.calculate(amount, registered); 32 | 33 | // производим проверку (сравниваем ожидаемый и фактический): 34 | assertEquals(expected, actual); 35 | } 36 | } 37 | 38 | -------------------------------------------------------------------------------- /2.3_maven-junit/bonus-handmade/src/BonusService.java: -------------------------------------------------------------------------------- 1 | public class BonusService { 2 | public long calculate(long amount, boolean registered) { 3 | int percent = registered ? 3 : 1; 4 | long bonus = amount * percent / 100 / 100; 5 | long limit = 500; 6 | if (bonus > limit) { 7 | bonus = limit; 8 | } 9 | return bonus; 10 | } 11 | } 12 | 13 | 14 | -------------------------------------------------------------------------------- /2.3_maven-junit/bonus-handmade/src/Main.java: -------------------------------------------------------------------------------- 1 | public class Main { 2 | public static void main(String[] args) { 3 | BonusService service = new BonusService(); 4 | 5 | // подготавливаем данные: 6 | long amount = 1000_60; 7 | boolean registered = true; 8 | long expected = 30; 9 | 10 | // вызываем целевой метод: 11 | long actual = service.calculate(amount, registered); 12 | 13 | // производим проверку (сравниваем ожидаемый и фактический): 14 | // если true - то PASS 15 | // если false - то FAIL 16 | boolean passed = expected == actual; 17 | 18 | // выводим результат 19 | System.out.println(passed); 20 | } 21 | } 22 | 23 | -------------------------------------------------------------------------------- /2.3_maven-junit/xml.md: -------------------------------------------------------------------------------- 1 | # XML 2 | 3 | XML расшифровывается как eXtensible Markup Language (расширяемый язык разметки) - специальный язык, созданный для обмена структурированной информацией. 4 | 5 | В нашем с вами случае, мы чаще всего будем встречаться с ним в виде файла `pom.xml`, в котором описана объектная модель нашего Maven проекта. 6 | 7 | XML документ начинается с объявления, которое выглядит следующим образом: 8 | ```xml 9 | 10 | ``` 11 | 12 | Это означает, что наш документ использует стандарт 1.0 и написан в кодировке UTF-8. 13 | 14 | Далее документ состоит из тегов. 15 | 16 | Тег - это специальный структурный элемент, который состоит из 4 частей: 17 | 1. Открывающий тег `` 18 | 1. Закрывающий тег `` 19 | 1. Атрибуты (пишутся только в открывающем теге): ``, при этом значения пишутся в кавычках 20 | 1. Содержимого (пишется между открывающим и закрывающим тегом) 21 | 22 | Возникает ключевой вопрос: откуда берутся теги, атрибуты и т.д.? Где это написано? 23 | 24 | На самом деле, к xml-документу обычно идёт XSD (Xml Schema Definition), он и определяет правила: 25 | - какие теги можно использовать 26 | - какие атрибуты есть у тегов 27 | - какие теги какое содержимое могут иметь 28 | 29 | Для Maven схема располагается по адресу: http://maven.apache.org/xsd/maven-4.0.0.xsd 30 | 31 | И для тега `project` там написано следующее: 32 | ```xml 33 | 34 | 35 | 3.0.0+ 36 | 37 | The <project> element is the root of the descriptor. The following table lists all of the possible child elements. 38 | 39 | 40 | 41 | ``` 42 | 43 | Далее описан тип `Model`: 44 | ```xml 45 | 46 | 47 | 3.0.0+ 48 | 49 | The <project> element is the root of the descriptor. The following table lists all of the possible child elements. 50 | 51 | 52 | 53 | 54 | 55 | 4.0.0+ 56 | 57 | Declares to which version of project descriptor this POM conforms. 58 | 59 | 60 | 61 | ... 62 | 63 | 64 | 3.0.0+ 65 | 66 | A universally unique identifier for a project. It is normal to use a fully-qualified package name to distinguish it from other projects with a similar name (eg. org.apache.maven). 67 | 68 | 69 | 70 | 71 | 72 | 3.0.0+ 73 | 74 | The identifier for this artifact that is unique within the group given by the group ID. An artifact is something that is either produced or used by a project. Examples of artifacts produced by Maven for a project include: JARs, source and binary distributions, and WARs. 75 | 76 | 77 | 78 | 79 | 80 | 4.0.0+ 81 | 82 | The current version of the artifact produced by this project. 83 | 84 | 85 | 86 | ... 87 | 88 | ``` 89 | 90 | Что это значит для нас? 91 | 1. Неплохо бы приучить себя читать такие определения (т.к. именно в них написано, что, для чего и как) 92 | 1. Нельзя просто так взять, скопировать "кусок xml" и подставить куда угодно (т.к. правилами жёстко регламентируется, что, куда и когда можно подставлять) 93 | 94 | Поэтому внимательно относитесь к тому, как именно вы оформляете xml-документ (следите за тем, чтобы это было сделано так же, как в лекции). 95 | -------------------------------------------------------------------------------- /2.4_params/bonus-calculator/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 4.0.0 6 | 7 | ru.netology 8 | bonus-calculator 9 | 1.0-SNAPSHOT 10 | 11 | 12 | 11 13 | 11 14 | UTF-8 15 | 16 | 17 | 18 | 19 | org.junit.jupiter 20 | junit-jupiter 21 | 5.4.2 22 | test 23 | 24 | 25 | 26 | 27 | 28 | 29 | org.apache.maven.plugins 30 | maven-surefire-plugin 31 | 2.22.2 32 | 33 | 34 | 35 | 36 | 37 | 38 | -------------------------------------------------------------------------------- /2.4_params/bonus-calculator/src/main/java/ru/netology/bonus/BonusService.java: -------------------------------------------------------------------------------- 1 | package ru.netology.bonus; 2 | 3 | public class BonusService { 4 | public long calculate(long amount, boolean registered) { 5 | int percent = registered ? 3 : 1; 6 | long bonus = amount * percent / 100 / 100; 7 | long limit = 500; 8 | if (bonus > limit) { 9 | bonus = limit; 10 | } 11 | return bonus; 12 | } 13 | } 14 | 15 | 16 | -------------------------------------------------------------------------------- /2.4_params/bonus-calculator/src/main/java/ru/netology/bonus/Main.java: -------------------------------------------------------------------------------- 1 | package ru.netology.bonus; 2 | 3 | public class Main { 4 | public static void main(String[] args) { } 5 | } 6 | 7 | -------------------------------------------------------------------------------- /2.4_params/bonus-calculator/src/test/java/ru/netology/bonus/BonusServiceTest.java: -------------------------------------------------------------------------------- 1 | package ru.netology.bonus; 2 | 3 | import org.junit.jupiter.params.ParameterizedTest; 4 | import org.junit.jupiter.params.provider.CsvSource; 5 | 6 | import static org.junit.jupiter.api.Assertions.assertEquals; 7 | 8 | class BonusServiceTest { 9 | @ParameterizedTest 10 | @CsvSource( 11 | value={ 12 | "'registered user, bonus under limit',100060,true,30", 13 | "'registered user, bonus over limit',100000060,true,500" 14 | } 15 | ) 16 | void shouldCalculate(String test, long amount, boolean registered, long expected) { 17 | BonusService service = new BonusService(); 18 | 19 | // вызываем целевой метод: 20 | long actual = service.calculate(amount, registered); 21 | 22 | // производим проверку (сравниваем ожидаемый и фактический): 23 | assertEquals(expected, actual); 24 | } 25 | } 26 | 27 | -------------------------------------------------------------------------------- /2.4_params/statistics/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 4.0.0 6 | 7 | ru.netology 8 | statistics 9 | 1.0-SNAPSHOT 10 | 11 | 12 | 11 13 | 11 14 | UTF-8 15 | 16 | 17 | 18 | 19 | org.junit.jupiter 20 | junit-jupiter 21 | 5.4.2 22 | test 23 | 24 | 25 | 26 | 27 | 28 | 29 | org.apache.maven.plugins 30 | maven-surefire-plugin 31 | 2.22.2 32 | 33 | 34 | 35 | 36 | 37 | 38 | -------------------------------------------------------------------------------- /2.4_params/statistics/src/main/java/ru/netology/statistic/StatisticsService.java: -------------------------------------------------------------------------------- 1 | package ru.netology.statistic; 2 | 3 | public class StatisticsService { 4 | public long calculateSum(long[] purchases) { 5 | long sum = 0; 6 | for (long purchase : purchases) { 7 | // аналог sum = sum + purchase; 8 | sum += purchase; 9 | } 10 | return sum; 11 | } 12 | 13 | public long findMax(long[] purchases) { 14 | long currentMax = purchases[0]; 15 | for (long purchase : purchases) { 16 | if (currentMax < purchase) { 17 | currentMax = purchase; 18 | } 19 | } 20 | return currentMax; 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /2.4_params/statistics/src/test/java/ru/netology/statistic/StatisticsServiceTest.java: -------------------------------------------------------------------------------- 1 | package ru.netology.statistic; 2 | 3 | import org.junit.jupiter.api.Test; 4 | 5 | import static org.junit.jupiter.api.Assertions.*; 6 | 7 | class StatisticsServiceTest { 8 | @Test 9 | void calculateSum() { 10 | StatisticsService service = new StatisticsService(); 11 | 12 | long[] purchases = {1_000, 2_000, 500, 5_000, 2_000}; 13 | long expected = 10_500; 14 | 15 | long actual = service.calculateSum(purchases); 16 | 17 | assertEquals(expected, actual); 18 | } 19 | 20 | @Test 21 | void findMax() { 22 | StatisticsService service = new StatisticsService(); 23 | 24 | long[] purchases = {1_000, 2_000, 500, 5_000, 2_000}; 25 | long expected = 5_000; 26 | 27 | long actual = service.findMax(purchases); 28 | 29 | assertEquals(expected, actual); 30 | } 31 | } -------------------------------------------------------------------------------- /2.5_ci/.github/workflows/maven.yml: -------------------------------------------------------------------------------- 1 | name: Java CI # как называется Workflow 2 | 3 | on: [push] # когда срабатывает (на push) 4 | 5 | jobs: # какие задачи делаем 6 | build: # сборка 7 | runs-on: ubuntu-latest # на какой ОС запускаем 8 | 9 | steps: # какие шаги выполняем 10 | - uses: actions/checkout@v2 # выкачиваем репо 11 | - name: Set up JDK 11 12 | uses: actions/setup-java@v1 # устанавливаем JDK 13 | with: 14 | java-version: 11 # версия для установки 15 | - name: Build with Maven 16 | run: mvn -B -e verify # запускаем Maven 17 | -------------------------------------------------------------------------------- /2.5_ci/.gitignore: -------------------------------------------------------------------------------- 1 | Thumbs.db* 2 | .DS_Store* 3 | HELP.md 4 | .gradle 5 | build/ 6 | target/ 7 | 8 | ### STS ### 9 | .apt_generated 10 | .classpath 11 | .factorypath 12 | .project 13 | .settings 14 | .springBeans 15 | .sts4-cache 16 | 17 | ### IntelliJ IDEA ### 18 | .idea 19 | *.iws 20 | *.iml 21 | *.ipr 22 | out/ 23 | 24 | ### NetBeans ### 25 | /nbproject/private/ 26 | /nbbuild/ 27 | /dist/ 28 | /nbdist/ 29 | /.nb-gradle/ 30 | 31 | ### VS Code ### 32 | .vscode/ 33 | 34 | ### Package Files ### 35 | *.jar 36 | *.war 37 | *.nar 38 | *.ear 39 | *.zip 40 | *.tar.gz 41 | *.rar 42 | 43 | ### Exclusions ### 44 | !gradle/wrapper/gradle-wrapper.jar 45 | !.mvn/wrapper/maven-wrapper.jar 46 | !**/src/main/** 47 | !**/src/test/** -------------------------------------------------------------------------------- /2.5_ci/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 4.0.0 6 | 7 | ru.netology 8 | statistics 9 | 1.0-SNAPSHOT 10 | 11 | 12 | 11 13 | 11 14 | UTF-8 15 | 16 | 17 | 18 | 19 | org.junit.jupiter 20 | junit-jupiter 21 | 5.4.2 22 | test 23 | 24 | 25 | 26 | 27 | 28 | 29 | org.apache.maven.plugins 30 | maven-surefire-plugin 31 | 2.22.2 32 | 33 | true 34 | 35 | 36 | 37 | org.jacoco 38 | jacoco-maven-plugin 39 | 0.8.5 40 | 41 | 42 | prepare-agent 43 | initialize 44 | 45 | prepare-agent 46 | 47 | 48 | 49 | report 50 | verify 51 | 52 | report 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | -------------------------------------------------------------------------------- /2.5_ci/src/main/java/ru/netology/statistic/StatisticsService.java: -------------------------------------------------------------------------------- 1 | package ru.netology.statistic; 2 | 3 | public class StatisticsService { 4 | /** 5 | * Calculate index of max income 6 | * 7 | * @param incomes - array of incomes 8 | * @return - index of first max value 9 | */ 10 | public long findMax(long[] incomes) { 11 | long current_max_index = 0; 12 | long current_max = incomes[0]; 13 | for (long income : incomes) 14 | if (current_max < income) 15 | current_max = income; 16 | return current_max; 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /2.5_ci/src/test/java/ru/netology/statistic/StatisticsServiceTest.java: -------------------------------------------------------------------------------- 1 | package ru.netology.statistic; 2 | 3 | import org.junit.jupiter.api.Test; 4 | 5 | import static org.junit.jupiter.api.Assertions.*; 6 | 7 | class StatisticsServiceTest { 8 | 9 | @Test 10 | void findMax() { 11 | StatisticsService service = new StatisticsService(); 12 | 13 | long[] incomesInBillions = {12, 5, 8, 4, 5, 3, 8, 6, 11, 11, 12}; 14 | long expected = 12; 15 | 16 | long actual = service.findMax(incomesInBillions); 17 | 18 | assertEquals(expected, actual); 19 | } 20 | } -------------------------------------------------------------------------------- /3.1_oop1/smart-house/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 4.0.0 6 | 7 | ru.netology 8 | smart-house 9 | 1.0-SNAPSHOT 10 | 11 | 12 | 11 13 | 11 14 | UTF-8 15 | 16 | 17 | 18 | 19 | org.junit.jupiter 20 | junit-jupiter 21 | 5.4.2 22 | test 23 | 24 | 25 | 26 | 27 | 28 | 29 | org.apache.maven.plugins 30 | maven-surefire-plugin 31 | 2.22.2 32 | 33 | 34 | 35 | 36 | -------------------------------------------------------------------------------- /3.1_oop1/smart-house/src/main/java/ru/netology/Conditioner.java: -------------------------------------------------------------------------------- 1 | package ru.netology; 2 | 3 | public class Conditioner { 4 | String name; 5 | int maxTemperature; 6 | int minTemperature; 7 | int currentTemperature; 8 | boolean on; 9 | } 10 | 11 | 12 | -------------------------------------------------------------------------------- /3.1_oop1/smart-house/src/main/java/ru/netology/ConditionerAdvanced.java: -------------------------------------------------------------------------------- 1 | package ru.netology; 2 | 3 | public class ConditionerAdvanced { 4 | private String name; 5 | private int maxTemperature; 6 | private int minTemperature; 7 | private int currentTemperature; 8 | private boolean on; 9 | 10 | public String getName() { 11 | return name; 12 | } 13 | 14 | public void setName(String name) { 15 | this.name = name; 16 | } 17 | 18 | public int getMaxTemperature() { 19 | return maxTemperature; 20 | } 21 | 22 | public void setMaxTemperature(int maxTemperature) { 23 | this.maxTemperature = maxTemperature; 24 | } 25 | 26 | public int getMinTemperature() { 27 | return minTemperature; 28 | } 29 | 30 | public void setMinTemperature(int minTemperature) { 31 | this.minTemperature = minTemperature; 32 | } 33 | 34 | public int getCurrentTemperature() { 35 | return currentTemperature; 36 | } 37 | 38 | public void setCurrentTemperature(int currentTemperature) { 39 | if (currentTemperature > maxTemperature) { 40 | return; 41 | } 42 | if (currentTemperature < minTemperature) { 43 | return; 44 | } 45 | // здесь уверены, что все проверки прошли 46 | this.currentTemperature = currentTemperature; 47 | } 48 | 49 | // public void setCurrentTemperature(int currentTemperature) { 50 | // if (currentTemperature <= maxTemperature) { 51 | // if (currentTemperature >= minTemperature) { 52 | // this.currentTemperature = currentTemperature; 53 | // } 54 | // } 55 | // } 56 | 57 | public boolean isOn() { 58 | return on; 59 | } 60 | 61 | public void setOn(boolean on) { 62 | this.on = on; 63 | } 64 | } 65 | 66 | 67 | -------------------------------------------------------------------------------- /3.1_oop1/smart-house/src/test/java/ru/netology/ConditionerAdvancedTest.java: -------------------------------------------------------------------------------- 1 | package ru.netology; 2 | 3 | import org.junit.jupiter.api.Test; 4 | 5 | import static org.junit.jupiter.api.Assertions.*; 6 | 7 | class ConditionerAdvancedTest { 8 | @Test 9 | public void shouldGetAndSet() { 10 | ConditionerAdvanced conditioner = new ConditionerAdvanced(); 11 | String expected = "Кондишн"; 12 | 13 | assertNull(conditioner.getName()); 14 | conditioner.setName(expected); 15 | assertEquals(expected, conditioner.getName()); 16 | } 17 | } -------------------------------------------------------------------------------- /3.1_oop1/smart-house/src/test/java/ru/netology/ConditionerTest.java: -------------------------------------------------------------------------------- 1 | package ru.netology; 2 | 3 | import org.junit.jupiter.api.Disabled; 4 | import org.junit.jupiter.api.Test; 5 | 6 | import static org.junit.jupiter.api.Assertions.*; 7 | 8 | class ConditionerTest { 9 | @Test 10 | public void shouldCreate() { 11 | Conditioner conditioner = new Conditioner(); 12 | } 13 | 14 | @Test 15 | public void shouldInitFieldToZeroValues() { 16 | Conditioner conditioner = new Conditioner(); 17 | assertNull(conditioner.name); 18 | assertEquals(0, conditioner.maxTemperature); 19 | assertEquals(0, conditioner.minTemperature); 20 | assertEquals(0, conditioner.currentTemperature); 21 | assertFalse(conditioner.on); 22 | } 23 | 24 | @Test 25 | @Disabled 26 | public void shouldThrowNPE() { 27 | Conditioner conditioner = new Conditioner(); 28 | assertEquals(0, conditioner.name.length()); 29 | } 30 | 31 | @Test 32 | public void shouldChangeFields() { 33 | Conditioner conditioner = new Conditioner(); 34 | assertEquals(0, conditioner.currentTemperature); 35 | conditioner.currentTemperature = -100; 36 | assertEquals(-100, conditioner.currentTemperature); 37 | } 38 | } -------------------------------------------------------------------------------- /3.2_oop2/principles/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 4.0.0 6 | 7 | ru.netology 8 | principles 9 | 1.0-SNAPSHOT 10 | 11 | 12 | 11 13 | 11 14 | UTF-8 15 | 16 | 17 | 18 | 19 | org.junit.jupiter 20 | junit-jupiter 21 | 5.4.2 22 | test 23 | 24 | 25 | 26 | 27 | 28 | 29 | org.apache.maven.plugins 30 | maven-surefire-plugin 31 | 2.22.2 32 | 33 | 34 | 35 | 36 | 37 | -------------------------------------------------------------------------------- /3.2_oop2/principles/src/main/java/ru/netology/domain/Conditioner.java: -------------------------------------------------------------------------------- 1 | package ru.netology.domain; 2 | 3 | public class Conditioner { 4 | private int id; 5 | private String name = "noname"; 6 | private int maxTemperature = 30; 7 | private int minTemperature = 15; 8 | private int currentTemperature = 20; 9 | private boolean on; 10 | 11 | public int getId() { 12 | return id; 13 | } 14 | 15 | public void setId(int id) { 16 | this.id = id; 17 | } 18 | 19 | public String getName() { 20 | return name; 21 | } 22 | 23 | public void setName(String name) { 24 | this.name = name; 25 | } 26 | 27 | public int getMaxTemperature() { 28 | return maxTemperature; 29 | } 30 | 31 | public void setMaxTemperature(int maxTemperature) { 32 | this.maxTemperature = maxTemperature; 33 | } 34 | 35 | public int getMinTemperature() { 36 | return minTemperature; 37 | } 38 | 39 | public void setMinTemperature(int minTemperature) { 40 | this.minTemperature = minTemperature; 41 | } 42 | 43 | public int getCurrentTemperature() { 44 | return currentTemperature; 45 | } 46 | 47 | public void setCurrentTemperature(int currentTemperature) { 48 | this.currentTemperature = currentTemperature; 49 | } 50 | 51 | public boolean isOn() { 52 | return on; 53 | } 54 | 55 | public void setOn(boolean on) { 56 | this.on = on; 57 | } 58 | } 59 | -------------------------------------------------------------------------------- /3.2_oop2/principles/src/main/java/ru/netology/domain/Movie.java: -------------------------------------------------------------------------------- 1 | package ru.netology.domain; 2 | 3 | public class Movie { 4 | private String id; 5 | private String imageUrl; 6 | private String name; 7 | private String genre; 8 | 9 | public String getId() { 10 | return id; 11 | } 12 | 13 | public void setId(String id) { 14 | this.id = id; 15 | } 16 | 17 | public String getImageUrl() { 18 | return imageUrl; 19 | } 20 | 21 | public void setImageUrl(String imageUrl) { 22 | this.imageUrl = imageUrl; 23 | } 24 | 25 | public String getName() { 26 | return name; 27 | } 28 | 29 | public void setName(String name) { 30 | this.name = name; 31 | } 32 | 33 | public String getGenre() { 34 | return genre; 35 | } 36 | 37 | public void setGenre(String genre) { 38 | this.genre = genre; 39 | } 40 | } 41 | 42 | 43 | -------------------------------------------------------------------------------- /3.2_oop2/principles/src/main/java/ru/netology/manager/MainPageManager.java: -------------------------------------------------------------------------------- 1 | package ru.netology.manager; 2 | 3 | import ru.netology.domain.Movie; 4 | 5 | public class MainPageManager { 6 | private MovieManager movieManager; 7 | 8 | /** 9 | * Main Page generation 10 | */ 11 | public String generate() { 12 | Movie[] movies = movieManager.getMoviesForFeed(); 13 | // TODO: add logic 14 | for (Movie movie : movies) { 15 | String block = movie.getGenre(); 16 | } 17 | return null; 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /3.2_oop2/principles/src/main/java/ru/netology/manager/MovieManager.java: -------------------------------------------------------------------------------- 1 | package ru.netology.manager; 2 | 3 | import ru.netology.domain.Movie; 4 | 5 | public class MovieManager { 6 | private Movie[] movies; 7 | 8 | public Movie[] getMoviesForFeed() { 9 | // TODO: add logic 10 | return null; 11 | } 12 | } 13 | 14 | -------------------------------------------------------------------------------- /3.3_state/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 4.0.0 6 | 7 | ru.netology 8 | smart-house 9 | 1.0-SNAPSHOT 10 | 11 | 12 | 13 | 11 14 | 11 15 | UTF-8 16 | 17 | 18 | 19 | 20 | org.projectlombok 21 | lombok 22 | 1.18.12 23 | provided 24 | 25 | 26 | org.junit.jupiter 27 | junit-jupiter 28 | 5.4.2 29 | test 30 | 31 | 32 | 33 | 34 | 35 | 36 | org.apache.maven.plugins 37 | maven-surefire-plugin 38 | 2.22.2 39 | 40 | 41 | 42 | 43 | -------------------------------------------------------------------------------- /3.3_state/src/main/java/ru/netology/domain/constructor/Conditioner.java: -------------------------------------------------------------------------------- 1 | package ru.netology.domain.constructor; 2 | 3 | public class Conditioner { 4 | private int id; 5 | private String name = "noname"; 6 | private int maxTemperature = 30; 7 | private int minTemperature = 15; 8 | private int currentTemperature = 22; 9 | private boolean on; 10 | 11 | public Conditioner() { 12 | } 13 | 14 | public Conditioner( 15 | int id, 16 | String name, 17 | int maxTemperature, 18 | int minTemperature, 19 | int currentTemperature, 20 | boolean on 21 | ) { 22 | this.id = id; 23 | this.name = name; 24 | this.maxTemperature = maxTemperature; 25 | this.minTemperature = minTemperature; 26 | this.currentTemperature = currentTemperature; 27 | this.on = on; 28 | } 29 | 30 | public int getId() { 31 | return id; 32 | } 33 | 34 | public void setId(int id) { 35 | this.id = id; 36 | } 37 | 38 | public String getName() { 39 | return name; 40 | } 41 | 42 | public void setName(String name) { 43 | this.name = name; 44 | } 45 | 46 | public int getMaxTemperature() { 47 | return maxTemperature; 48 | } 49 | 50 | public void setMaxTemperature(int maxTemperature) { 51 | this.maxTemperature = maxTemperature; 52 | } 53 | 54 | public int getMinTemperature() { 55 | return minTemperature; 56 | } 57 | 58 | public void setMinTemperature(int minTemperature) { 59 | this.minTemperature = minTemperature; 60 | } 61 | 62 | public int getCurrentTemperature() { 63 | return currentTemperature; 64 | } 65 | 66 | public void setCurrentTemperature(int currentTemperature) { 67 | this.currentTemperature = currentTemperature; 68 | } 69 | 70 | public boolean isOn() { 71 | return on; 72 | } 73 | 74 | public void setOn(boolean on) { 75 | this.on = on; 76 | } 77 | } 78 | -------------------------------------------------------------------------------- /3.3_state/src/main/java/ru/netology/domain/field/Conditioner.java: -------------------------------------------------------------------------------- 1 | package ru.netology.domain.field; 2 | 3 | public class Conditioner { 4 | private int id; 5 | private String name = "noname"; 6 | private int maxTemperature = 30; 7 | private int minTemperature = 15; 8 | private int currentTemperature = 22; 9 | // private int currentTemperature = (maxTemperature + minTemperature) / 2; 10 | private boolean on; 11 | 12 | public int getId() { 13 | return id; 14 | } 15 | 16 | public void setId(int id) { 17 | this.id = id; 18 | } 19 | 20 | public String getName() { 21 | return name; 22 | } 23 | 24 | public void setName(String name) { 25 | this.name = name; 26 | } 27 | 28 | public int getMaxTemperature() { 29 | return maxTemperature; 30 | } 31 | 32 | public void setMaxTemperature(int maxTemperature) { 33 | this.maxTemperature = maxTemperature; 34 | } 35 | 36 | public int getMinTemperature() { 37 | return minTemperature; 38 | } 39 | 40 | public void setMinTemperature(int minTemperature) { 41 | this.minTemperature = minTemperature; 42 | } 43 | 44 | public int getCurrentTemperature() { 45 | return currentTemperature; 46 | } 47 | 48 | public void setCurrentTemperature(int currentTemperature) { 49 | this.currentTemperature = currentTemperature; 50 | } 51 | 52 | public boolean isOn() { 53 | return on; 54 | } 55 | 56 | public void setOn(boolean on) { 57 | this.on = on; 58 | } 59 | } 60 | -------------------------------------------------------------------------------- /3.3_state/src/main/java/ru/netology/domain/lombok/Conditioner.java: -------------------------------------------------------------------------------- 1 | package ru.netology.domain.lombok; 2 | 3 | 4 | import lombok.AllArgsConstructor; 5 | import lombok.Data; 6 | import lombok.NoArgsConstructor; 7 | 8 | @NoArgsConstructor 9 | @AllArgsConstructor 10 | @Data 11 | public class Conditioner { 12 | private int id; 13 | private String name = "noname"; 14 | private int maxTemperature = 30; 15 | private int minTemperature = 15; 16 | private int currentTemperature = 22; 17 | private boolean on; 18 | } 19 | -------------------------------------------------------------------------------- /3.3_state/src/test/java/ru/netology/domain/constructor/ConditionerTest.java: -------------------------------------------------------------------------------- 1 | package ru.netology.domain.constructor; 2 | 3 | import org.junit.jupiter.api.Test; 4 | 5 | import static org.junit.jupiter.api.Assertions.*; 6 | 7 | class ConditionerTest { 8 | @Test 9 | public void shouldUseConstructor() { 10 | Conditioner conditioner = new Conditioner( 11 | 1, 12 | "Winter Cold", 13 | 30, 14 | 10, 15 | 29, 16 | true 17 | ); 18 | assertEquals(29, conditioner.getCurrentTemperature()); 19 | } 20 | 21 | @Test 22 | public void shouldUseNoArgsConstructor() { 23 | Conditioner conditioner = new Conditioner(); 24 | assertEquals(22, conditioner.getCurrentTemperature()); 25 | } 26 | } 27 | 28 | -------------------------------------------------------------------------------- /3.3_state/src/test/java/ru/netology/domain/field/ConditionerTest.java: -------------------------------------------------------------------------------- 1 | package ru.netology.domain.field; 2 | 3 | import org.junit.jupiter.api.Test; 4 | 5 | import static org.junit.jupiter.api.Assertions.*; 6 | 7 | class ConditionerTest { 8 | @Test 9 | public void shouldInitFields() { 10 | Conditioner conditioner = new Conditioner(); 11 | 12 | assertEquals("noname", conditioner.getName()); 13 | assertEquals(30, conditioner.getMaxTemperature()); 14 | assertEquals(15, conditioner.getMinTemperature()); 15 | assertEquals(22, conditioner.getCurrentTemperature()); 16 | } 17 | } -------------------------------------------------------------------------------- /3.4_dependency/cart-server/.gitignore: -------------------------------------------------------------------------------- 1 | HELP.md 2 | target/ 3 | !.mvn/wrapper/maven-wrapper.jar 4 | !**/src/main/**/target/ 5 | !**/src/test/**/target/ 6 | 7 | ### STS ### 8 | .apt_generated 9 | .classpath 10 | .factorypath 11 | .project 12 | .settings 13 | .springBeans 14 | .sts4-cache 15 | 16 | ### IntelliJ IDEA ### 17 | .idea 18 | *.iws 19 | *.iml 20 | *.ipr 21 | 22 | ### NetBeans ### 23 | /nbproject/private/ 24 | /nbbuild/ 25 | /dist/ 26 | /nbdist/ 27 | /.nb-gradle/ 28 | build/ 29 | !**/src/main/**/build/ 30 | !**/src/test/**/build/ 31 | 32 | ### VS Code ### 33 | .vscode/ 34 | -------------------------------------------------------------------------------- /3.4_dependency/cart-server/.mvn/wrapper/MavenWrapperDownloader.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2007-present the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * https://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | import java.net.*; 18 | import java.io.*; 19 | import java.nio.channels.*; 20 | import java.util.Properties; 21 | 22 | public class MavenWrapperDownloader { 23 | 24 | private static final String WRAPPER_VERSION = "0.5.6"; 25 | /** 26 | * Default URL to download the maven-wrapper.jar from, if no 'downloadUrl' is provided. 27 | */ 28 | private static final String DEFAULT_DOWNLOAD_URL = "https://repo.maven.apache.org/maven2/io/takari/maven-wrapper/" 29 | + WRAPPER_VERSION + "/maven-wrapper-" + WRAPPER_VERSION + ".jar"; 30 | 31 | /** 32 | * Path to the maven-wrapper.properties file, which might contain a downloadUrl property to 33 | * use instead of the default one. 34 | */ 35 | private static final String MAVEN_WRAPPER_PROPERTIES_PATH = 36 | ".mvn/wrapper/maven-wrapper.properties"; 37 | 38 | /** 39 | * Path where the maven-wrapper.jar will be saved to. 40 | */ 41 | private static final String MAVEN_WRAPPER_JAR_PATH = 42 | ".mvn/wrapper/maven-wrapper.jar"; 43 | 44 | /** 45 | * Name of the property which should be used to override the default download url for the wrapper. 46 | */ 47 | private static final String PROPERTY_NAME_WRAPPER_URL = "wrapperUrl"; 48 | 49 | public static void main(String args[]) { 50 | System.out.println("- Downloader started"); 51 | File baseDirectory = new File(args[0]); 52 | System.out.println("- Using base directory: " + baseDirectory.getAbsolutePath()); 53 | 54 | // If the maven-wrapper.properties exists, read it and check if it contains a custom 55 | // wrapperUrl parameter. 56 | File mavenWrapperPropertyFile = new File(baseDirectory, MAVEN_WRAPPER_PROPERTIES_PATH); 57 | String url = DEFAULT_DOWNLOAD_URL; 58 | if (mavenWrapperPropertyFile.exists()) { 59 | FileInputStream mavenWrapperPropertyFileInputStream = null; 60 | try { 61 | mavenWrapperPropertyFileInputStream = new FileInputStream(mavenWrapperPropertyFile); 62 | Properties mavenWrapperProperties = new Properties(); 63 | mavenWrapperProperties.load(mavenWrapperPropertyFileInputStream); 64 | url = mavenWrapperProperties.getProperty(PROPERTY_NAME_WRAPPER_URL, url); 65 | } catch (IOException e) { 66 | System.out.println("- ERROR loading '" + MAVEN_WRAPPER_PROPERTIES_PATH + "'"); 67 | } finally { 68 | try { 69 | if (mavenWrapperPropertyFileInputStream != null) { 70 | mavenWrapperPropertyFileInputStream.close(); 71 | } 72 | } catch (IOException e) { 73 | // Ignore ... 74 | } 75 | } 76 | } 77 | System.out.println("- Downloading from: " + url); 78 | 79 | File outputFile = new File(baseDirectory.getAbsolutePath(), MAVEN_WRAPPER_JAR_PATH); 80 | if (!outputFile.getParentFile().exists()) { 81 | if (!outputFile.getParentFile().mkdirs()) { 82 | System.out.println( 83 | "- ERROR creating output directory '" + outputFile.getParentFile().getAbsolutePath() + "'"); 84 | } 85 | } 86 | System.out.println("- Downloading to: " + outputFile.getAbsolutePath()); 87 | try { 88 | downloadFileFromURL(url, outputFile); 89 | System.out.println("Done"); 90 | System.exit(0); 91 | } catch (Throwable e) { 92 | System.out.println("- Error downloading"); 93 | e.printStackTrace(); 94 | System.exit(1); 95 | } 96 | } 97 | 98 | private static void downloadFileFromURL(String urlString, File destination) throws Exception { 99 | if (System.getenv("MVNW_USERNAME") != null && System.getenv("MVNW_PASSWORD") != null) { 100 | String username = System.getenv("MVNW_USERNAME"); 101 | char[] password = System.getenv("MVNW_PASSWORD").toCharArray(); 102 | Authenticator.setDefault(new Authenticator() { 103 | @Override 104 | protected PasswordAuthentication getPasswordAuthentication() { 105 | return new PasswordAuthentication(username, password); 106 | } 107 | }); 108 | } 109 | URL website = new URL(urlString); 110 | ReadableByteChannel rbc; 111 | rbc = Channels.newChannel(website.openStream()); 112 | FileOutputStream fos = new FileOutputStream(destination); 113 | fos.getChannel().transferFrom(rbc, 0, Long.MAX_VALUE); 114 | fos.close(); 115 | rbc.close(); 116 | } 117 | 118 | } 119 | -------------------------------------------------------------------------------- /3.4_dependency/cart-server/.mvn/wrapper/maven-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/netology-code/javaqa-code/72090ce76d5d720c70141fa6cd7b5c4ec52d6ab6/3.4_dependency/cart-server/.mvn/wrapper/maven-wrapper.jar -------------------------------------------------------------------------------- /3.4_dependency/cart-server/.mvn/wrapper/maven-wrapper.properties: -------------------------------------------------------------------------------- 1 | distributionUrl=https://repo.maven.apache.org/maven2/org/apache/maven/apache-maven/3.6.3/apache-maven-3.6.3-bin.zip 2 | wrapperUrl=https://repo.maven.apache.org/maven2/io/takari/maven-wrapper/0.5.6/maven-wrapper-0.5.6.jar 3 | -------------------------------------------------------------------------------- /3.4_dependency/cart-server/mvnw: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | # ---------------------------------------------------------------------------- 3 | # Licensed to the Apache Software Foundation (ASF) under one 4 | # or more contributor license agreements. See the NOTICE file 5 | # distributed with this work for additional information 6 | # regarding copyright ownership. The ASF licenses this file 7 | # to you under the Apache License, Version 2.0 (the 8 | # "License"); you may not use this file except in compliance 9 | # with the License. You may obtain a copy of the License at 10 | # 11 | # https://www.apache.org/licenses/LICENSE-2.0 12 | # 13 | # Unless required by applicable law or agreed to in writing, 14 | # software distributed under the License is distributed on an 15 | # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16 | # KIND, either express or implied. See the License for the 17 | # specific language governing permissions and limitations 18 | # under the License. 19 | # ---------------------------------------------------------------------------- 20 | 21 | # ---------------------------------------------------------------------------- 22 | # Maven Start Up Batch script 23 | # 24 | # Required ENV vars: 25 | # ------------------ 26 | # JAVA_HOME - location of a JDK home dir 27 | # 28 | # Optional ENV vars 29 | # ----------------- 30 | # M2_HOME - location of maven2's installed home dir 31 | # MAVEN_OPTS - parameters passed to the Java VM when running Maven 32 | # e.g. to debug Maven itself, use 33 | # set MAVEN_OPTS=-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=8000 34 | # MAVEN_SKIP_RC - flag to disable loading of mavenrc files 35 | # ---------------------------------------------------------------------------- 36 | 37 | if [ -z "$MAVEN_SKIP_RC" ]; then 38 | 39 | if [ -f /etc/mavenrc ]; then 40 | . /etc/mavenrc 41 | fi 42 | 43 | if [ -f "$HOME/.mavenrc" ]; then 44 | . "$HOME/.mavenrc" 45 | fi 46 | 47 | fi 48 | 49 | # OS specific support. $var _must_ be set to either true or false. 50 | cygwin=false 51 | darwin=false 52 | mingw=false 53 | case "$(uname)" in 54 | CYGWIN*) cygwin=true ;; 55 | MINGW*) mingw=true ;; 56 | Darwin*) 57 | darwin=true 58 | # Use /usr/libexec/java_home if available, otherwise fall back to /Library/Java/Home 59 | # See https://developer.apple.com/library/mac/qa/qa1170/_index.html 60 | if [ -z "$JAVA_HOME" ]; then 61 | if [ -x "/usr/libexec/java_home" ]; then 62 | export JAVA_HOME="$(/usr/libexec/java_home)" 63 | else 64 | export JAVA_HOME="/Library/Java/Home" 65 | fi 66 | fi 67 | ;; 68 | esac 69 | 70 | if [ -z "$JAVA_HOME" ]; then 71 | if [ -r /etc/gentoo-release ]; then 72 | JAVA_HOME=$(java-config --jre-home) 73 | fi 74 | fi 75 | 76 | if [ -z "$M2_HOME" ]; then 77 | ## resolve links - $0 may be a link to maven's home 78 | PRG="$0" 79 | 80 | # need this for relative symlinks 81 | while [ -h "$PRG" ]; do 82 | ls=$(ls -ld "$PRG") 83 | link=$(expr "$ls" : '.*-> \(.*\)$') 84 | if expr "$link" : '/.*' >/dev/null; then 85 | PRG="$link" 86 | else 87 | PRG="$(dirname "$PRG")/$link" 88 | fi 89 | done 90 | 91 | saveddir=$(pwd) 92 | 93 | M2_HOME=$(dirname "$PRG")/.. 94 | 95 | # make it fully qualified 96 | M2_HOME=$(cd "$M2_HOME" && pwd) 97 | 98 | cd "$saveddir" 99 | # echo Using m2 at $M2_HOME 100 | fi 101 | 102 | # For Cygwin, ensure paths are in UNIX format before anything is touched 103 | if $cygwin; then 104 | [ -n "$M2_HOME" ] && 105 | M2_HOME=$(cygpath --unix "$M2_HOME") 106 | [ -n "$JAVA_HOME" ] && 107 | JAVA_HOME=$(cygpath --unix "$JAVA_HOME") 108 | [ -n "$CLASSPATH" ] && 109 | CLASSPATH=$(cygpath --path --unix "$CLASSPATH") 110 | fi 111 | 112 | # For Mingw, ensure paths are in UNIX format before anything is touched 113 | if $mingw; then 114 | [ -n "$M2_HOME" ] && 115 | M2_HOME="$( ( 116 | cd "$M2_HOME" 117 | pwd 118 | ))" 119 | [ -n "$JAVA_HOME" ] && 120 | JAVA_HOME="$( ( 121 | cd "$JAVA_HOME" 122 | pwd 123 | ))" 124 | fi 125 | 126 | if [ -z "$JAVA_HOME" ]; then 127 | javaExecutable="$(which javac)" 128 | if [ -n "$javaExecutable" ] && ! [ "$(expr \"$javaExecutable\" : '\([^ ]*\)')" = "no" ]; then 129 | # readlink(1) is not available as standard on Solaris 10. 130 | readLink=$(which readlink) 131 | if [ ! $(expr "$readLink" : '\([^ ]*\)') = "no" ]; then 132 | if $darwin; then 133 | javaHome="$(dirname \"$javaExecutable\")" 134 | javaExecutable="$(cd \"$javaHome\" && pwd -P)/javac" 135 | else 136 | javaExecutable="$(readlink -f \"$javaExecutable\")" 137 | fi 138 | javaHome="$(dirname \"$javaExecutable\")" 139 | javaHome=$(expr "$javaHome" : '\(.*\)/bin') 140 | JAVA_HOME="$javaHome" 141 | export JAVA_HOME 142 | fi 143 | fi 144 | fi 145 | 146 | if [ -z "$JAVACMD" ]; then 147 | if [ -n "$JAVA_HOME" ]; then 148 | if [ -x "$JAVA_HOME/jre/sh/java" ]; then 149 | # IBM's JDK on AIX uses strange locations for the executables 150 | JAVACMD="$JAVA_HOME/jre/sh/java" 151 | else 152 | JAVACMD="$JAVA_HOME/bin/java" 153 | fi 154 | else 155 | JAVACMD="$(which java)" 156 | fi 157 | fi 158 | 159 | if [ ! -x "$JAVACMD" ]; then 160 | echo "Error: JAVA_HOME is not defined correctly." >&2 161 | echo " We cannot execute $JAVACMD" >&2 162 | exit 1 163 | fi 164 | 165 | if [ -z "$JAVA_HOME" ]; then 166 | echo "Warning: JAVA_HOME environment variable is not set." 167 | fi 168 | 169 | CLASSWORLDS_LAUNCHER=org.codehaus.plexus.classworlds.launcher.Launcher 170 | 171 | # traverses directory structure from process work directory to filesystem root 172 | # first directory with .mvn subdirectory is considered project base directory 173 | find_maven_basedir() { 174 | 175 | if [ -z "$1" ]; then 176 | echo "Path not specified to find_maven_basedir" 177 | return 1 178 | fi 179 | 180 | basedir="$1" 181 | wdir="$1" 182 | while [ "$wdir" != '/' ]; do 183 | if [ -d "$wdir"/.mvn ]; then 184 | basedir=$wdir 185 | break 186 | fi 187 | # workaround for JBEAP-8937 (on Solaris 10/Sparc) 188 | if [ -d "${wdir}" ]; then 189 | wdir=$( 190 | cd "$wdir/.." 191 | pwd 192 | ) 193 | fi 194 | # end of workaround 195 | done 196 | echo "${basedir}" 197 | } 198 | 199 | # concatenates all lines of a file 200 | concat_lines() { 201 | if [ -f "$1" ]; then 202 | echo "$(tr -s '\n' ' ' <"$1")" 203 | fi 204 | } 205 | 206 | BASE_DIR=$(find_maven_basedir "$(pwd)") 207 | if [ -z "$BASE_DIR" ]; then 208 | exit 1 209 | fi 210 | 211 | ########################################################################################## 212 | # Extension to allow automatically downloading the maven-wrapper.jar from Maven-central 213 | # This allows using the maven wrapper in projects that prohibit checking in binary data. 214 | ########################################################################################## 215 | if [ -r "$BASE_DIR/.mvn/wrapper/maven-wrapper.jar" ]; then 216 | if [ "$MVNW_VERBOSE" = true ]; then 217 | echo "Found .mvn/wrapper/maven-wrapper.jar" 218 | fi 219 | else 220 | if [ "$MVNW_VERBOSE" = true ]; then 221 | echo "Couldn't find .mvn/wrapper/maven-wrapper.jar, downloading it ..." 222 | fi 223 | if [ -n "$MVNW_REPOURL" ]; then 224 | jarUrl="$MVNW_REPOURL/io/takari/maven-wrapper/0.5.6/maven-wrapper-0.5.6.jar" 225 | else 226 | jarUrl="https://repo.maven.apache.org/maven2/io/takari/maven-wrapper/0.5.6/maven-wrapper-0.5.6.jar" 227 | fi 228 | while IFS="=" read key value; do 229 | case "$key" in wrapperUrl) 230 | jarUrl="$value" 231 | break 232 | ;; 233 | esac 234 | done <"$BASE_DIR/.mvn/wrapper/maven-wrapper.properties" 235 | if [ "$MVNW_VERBOSE" = true ]; then 236 | echo "Downloading from: $jarUrl" 237 | fi 238 | wrapperJarPath="$BASE_DIR/.mvn/wrapper/maven-wrapper.jar" 239 | if $cygwin; then 240 | wrapperJarPath=$(cygpath --path --windows "$wrapperJarPath") 241 | fi 242 | 243 | if command -v wget >/dev/null; then 244 | if [ "$MVNW_VERBOSE" = true ]; then 245 | echo "Found wget ... using wget" 246 | fi 247 | if [ -z "$MVNW_USERNAME" ] || [ -z "$MVNW_PASSWORD" ]; then 248 | wget "$jarUrl" -O "$wrapperJarPath" 249 | else 250 | wget --http-user=$MVNW_USERNAME --http-password=$MVNW_PASSWORD "$jarUrl" -O "$wrapperJarPath" 251 | fi 252 | elif command -v curl >/dev/null; then 253 | if [ "$MVNW_VERBOSE" = true ]; then 254 | echo "Found curl ... using curl" 255 | fi 256 | if [ -z "$MVNW_USERNAME" ] || [ -z "$MVNW_PASSWORD" ]; then 257 | curl -o "$wrapperJarPath" "$jarUrl" -f 258 | else 259 | curl --user $MVNW_USERNAME:$MVNW_PASSWORD -o "$wrapperJarPath" "$jarUrl" -f 260 | fi 261 | 262 | else 263 | if [ "$MVNW_VERBOSE" = true ]; then 264 | echo "Falling back to using Java to download" 265 | fi 266 | javaClass="$BASE_DIR/.mvn/wrapper/MavenWrapperDownloader.java" 267 | # For Cygwin, switch paths to Windows format before running javac 268 | if $cygwin; then 269 | javaClass=$(cygpath --path --windows "$javaClass") 270 | fi 271 | if [ -e "$javaClass" ]; then 272 | if [ ! -e "$BASE_DIR/.mvn/wrapper/MavenWrapperDownloader.class" ]; then 273 | if [ "$MVNW_VERBOSE" = true ]; then 274 | echo " - Compiling MavenWrapperDownloader.java ..." 275 | fi 276 | # Compiling the Java class 277 | ("$JAVA_HOME/bin/javac" "$javaClass") 278 | fi 279 | if [ -e "$BASE_DIR/.mvn/wrapper/MavenWrapperDownloader.class" ]; then 280 | # Running the downloader 281 | if [ "$MVNW_VERBOSE" = true ]; then 282 | echo " - Running MavenWrapperDownloader.java ..." 283 | fi 284 | ("$JAVA_HOME/bin/java" -cp .mvn/wrapper MavenWrapperDownloader "$MAVEN_PROJECTBASEDIR") 285 | fi 286 | fi 287 | fi 288 | fi 289 | ########################################################################################## 290 | # End of extension 291 | ########################################################################################## 292 | 293 | export MAVEN_PROJECTBASEDIR=${MAVEN_BASEDIR:-"$BASE_DIR"} 294 | if [ "$MVNW_VERBOSE" = true ]; then 295 | echo $MAVEN_PROJECTBASEDIR 296 | fi 297 | MAVEN_OPTS="$(concat_lines "$MAVEN_PROJECTBASEDIR/.mvn/jvm.config") $MAVEN_OPTS" 298 | 299 | # For Cygwin, switch paths to Windows format before running java 300 | if $cygwin; then 301 | [ -n "$M2_HOME" ] && 302 | M2_HOME=$(cygpath --path --windows "$M2_HOME") 303 | [ -n "$JAVA_HOME" ] && 304 | JAVA_HOME=$(cygpath --path --windows "$JAVA_HOME") 305 | [ -n "$CLASSPATH" ] && 306 | CLASSPATH=$(cygpath --path --windows "$CLASSPATH") 307 | [ -n "$MAVEN_PROJECTBASEDIR" ] && 308 | MAVEN_PROJECTBASEDIR=$(cygpath --path --windows "$MAVEN_PROJECTBASEDIR") 309 | fi 310 | 311 | # Provide a "standardized" way to retrieve the CLI args that will 312 | # work with both Windows and non-Windows executions. 313 | MAVEN_CMD_LINE_ARGS="$MAVEN_CONFIG $@" 314 | export MAVEN_CMD_LINE_ARGS 315 | 316 | WRAPPER_LAUNCHER=org.apache.maven.wrapper.MavenWrapperMain 317 | 318 | exec "$JAVACMD" \ 319 | $MAVEN_OPTS \ 320 | -classpath "$MAVEN_PROJECTBASEDIR/.mvn/wrapper/maven-wrapper.jar" \ 321 | "-Dmaven.home=${M2_HOME}" "-Dmaven.multiModuleProjectDirectory=${MAVEN_PROJECTBASEDIR}" \ 322 | ${WRAPPER_LAUNCHER} $MAVEN_CONFIG "$@" 323 | -------------------------------------------------------------------------------- /3.4_dependency/cart-server/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 https://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 Maven 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 keystroke 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 set title of command window 39 | title %0 40 | @REM enable echoing by setting MAVEN_BATCH_ECHO to 'on' 41 | @if "%MAVEN_BATCH_ECHO%" == "on" echo %MAVEN_BATCH_ECHO% 42 | 43 | @REM set %HOME% to equivalent of $HOME 44 | if "%HOME%" == "" (set "HOME=%HOMEDRIVE%%HOMEPATH%") 45 | 46 | @REM Execute a user defined script before this one 47 | if not "%MAVEN_SKIP_RC%" == "" goto skipRcPre 48 | @REM check for pre script, once with legacy .bat ending and once with .cmd ending 49 | if exist "%HOME%\mavenrc_pre.bat" call "%HOME%\mavenrc_pre.bat" 50 | if exist "%HOME%\mavenrc_pre.cmd" call "%HOME%\mavenrc_pre.cmd" 51 | :skipRcPre 52 | 53 | @setlocal 54 | 55 | set ERROR_CODE=0 56 | 57 | @REM To isolate internal variables from possible post scripts, we use another setlocal 58 | @setlocal 59 | 60 | @REM ==== START VALIDATION ==== 61 | if not "%JAVA_HOME%" == "" goto OkJHome 62 | 63 | echo. 64 | echo Error: JAVA_HOME not found in your environment. >&2 65 | echo Please set the JAVA_HOME variable in your environment to match the >&2 66 | echo location of your Java installation. >&2 67 | echo. 68 | goto error 69 | 70 | :OkJHome 71 | if exist "%JAVA_HOME%\bin\java.exe" goto init 72 | 73 | echo. 74 | echo Error: JAVA_HOME is set to an invalid directory. >&2 75 | echo JAVA_HOME = "%JAVA_HOME%" >&2 76 | echo Please set the JAVA_HOME variable in your environment to match the >&2 77 | echo location of your Java installation. >&2 78 | echo. 79 | goto error 80 | 81 | @REM ==== END VALIDATION ==== 82 | 83 | :init 84 | 85 | @REM Find the project base dir, i.e. the directory that contains the folder ".mvn". 86 | @REM Fallback to current working directory if not found. 87 | 88 | set MAVEN_PROJECTBASEDIR=%MAVEN_BASEDIR% 89 | IF NOT "%MAVEN_PROJECTBASEDIR%"=="" goto endDetectBaseDir 90 | 91 | set EXEC_DIR=%CD% 92 | set WDIR=%EXEC_DIR% 93 | :findBaseDir 94 | IF EXIST "%WDIR%"\.mvn goto baseDirFound 95 | cd .. 96 | IF "%WDIR%"=="%CD%" goto baseDirNotFound 97 | set WDIR=%CD% 98 | goto findBaseDir 99 | 100 | :baseDirFound 101 | set MAVEN_PROJECTBASEDIR=%WDIR% 102 | cd "%EXEC_DIR%" 103 | goto endDetectBaseDir 104 | 105 | :baseDirNotFound 106 | set MAVEN_PROJECTBASEDIR=%EXEC_DIR% 107 | cd "%EXEC_DIR%" 108 | 109 | :endDetectBaseDir 110 | 111 | IF NOT EXIST "%MAVEN_PROJECTBASEDIR%\.mvn\jvm.config" goto endReadAdditionalConfig 112 | 113 | @setlocal EnableExtensions EnableDelayedExpansion 114 | for /F "usebackq delims=" %%a in ("%MAVEN_PROJECTBASEDIR%\.mvn\jvm.config") do set JVM_CONFIG_MAVEN_PROPS=!JVM_CONFIG_MAVEN_PROPS! %%a 115 | @endlocal & set JVM_CONFIG_MAVEN_PROPS=%JVM_CONFIG_MAVEN_PROPS% 116 | 117 | :endReadAdditionalConfig 118 | 119 | SET MAVEN_JAVA_EXE="%JAVA_HOME%\bin\java.exe" 120 | set WRAPPER_JAR="%MAVEN_PROJECTBASEDIR%\.mvn\wrapper\maven-wrapper.jar" 121 | set WRAPPER_LAUNCHER=org.apache.maven.wrapper.MavenWrapperMain 122 | 123 | set DOWNLOAD_URL="https://repo.maven.apache.org/maven2/io/takari/maven-wrapper/0.5.6/maven-wrapper-0.5.6.jar" 124 | 125 | FOR /F "tokens=1,2 delims==" %%A IN ("%MAVEN_PROJECTBASEDIR%\.mvn\wrapper\maven-wrapper.properties") DO ( 126 | IF "%%A"=="wrapperUrl" SET DOWNLOAD_URL=%%B 127 | ) 128 | 129 | @REM Extension to allow automatically downloading the maven-wrapper.jar from Maven-central 130 | @REM This allows using the maven wrapper in projects that prohibit checking in binary data. 131 | if exist %WRAPPER_JAR% ( 132 | if "%MVNW_VERBOSE%" == "true" ( 133 | echo Found %WRAPPER_JAR% 134 | ) 135 | ) else ( 136 | if not "%MVNW_REPOURL%" == "" ( 137 | SET DOWNLOAD_URL="%MVNW_REPOURL%/io/takari/maven-wrapper/0.5.6/maven-wrapper-0.5.6.jar" 138 | ) 139 | if "%MVNW_VERBOSE%" == "true" ( 140 | echo Couldn't find %WRAPPER_JAR%, downloading it ... 141 | echo Downloading from: %DOWNLOAD_URL% 142 | ) 143 | 144 | powershell -Command "&{"^ 145 | "$webclient = new-object System.Net.WebClient;"^ 146 | "if (-not ([string]::IsNullOrEmpty('%MVNW_USERNAME%') -and [string]::IsNullOrEmpty('%MVNW_PASSWORD%'))) {"^ 147 | "$webclient.Credentials = new-object System.Net.NetworkCredential('%MVNW_USERNAME%', '%MVNW_PASSWORD%');"^ 148 | "}"^ 149 | "[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12; $webclient.DownloadFile('%DOWNLOAD_URL%', '%WRAPPER_JAR%')"^ 150 | "}" 151 | if "%MVNW_VERBOSE%" == "true" ( 152 | echo Finished downloading %WRAPPER_JAR% 153 | ) 154 | ) 155 | @REM End of extension 156 | 157 | @REM Provide a "standardized" way to retrieve the CLI args that will 158 | @REM work with both Windows and non-Windows executions. 159 | set MAVEN_CMD_LINE_ARGS=%* 160 | 161 | %MAVEN_JAVA_EXE% %JVM_CONFIG_MAVEN_PROPS% %MAVEN_OPTS% %MAVEN_DEBUG_OPTS% -classpath %WRAPPER_JAR% "-Dmaven.multiModuleProjectDirectory=%MAVEN_PROJECTBASEDIR%" %WRAPPER_LAUNCHER% %MAVEN_CONFIG% %* 162 | if ERRORLEVEL 1 goto error 163 | goto end 164 | 165 | :error 166 | set ERROR_CODE=1 167 | 168 | :end 169 | @endlocal & set ERROR_CODE=%ERROR_CODE% 170 | 171 | if not "%MAVEN_SKIP_RC%" == "" goto skipRcPost 172 | @REM check for post script, once with legacy .bat ending and once with .cmd ending 173 | if exist "%HOME%\mavenrc_post.bat" call "%HOME%\mavenrc_post.bat" 174 | if exist "%HOME%\mavenrc_post.cmd" call "%HOME%\mavenrc_post.cmd" 175 | :skipRcPost 176 | 177 | @REM pause the script if MAVEN_BATCH_PAUSE is set to 'on' 178 | if "%MAVEN_BATCH_PAUSE%" == "on" pause 179 | 180 | if "%MAVEN_TERMINATE_CMD%" == "on" exit %ERROR_CODE% 181 | 182 | exit /B %ERROR_CODE% 183 | -------------------------------------------------------------------------------- /3.4_dependency/cart-server/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 4.0.0 5 | 6 | org.springframework.boot 7 | spring-boot-starter-parent 8 | 2.4.0 9 | 10 | 11 | ru.netology 12 | cart-server 13 | 0.0.1-SNAPSHOT 14 | cart-server 15 | Cart Server 16 | 17 | 18 | 11 19 | 20 | 21 | 22 | 23 | org.springframework.boot 24 | spring-boot-starter-data-jpa 25 | 26 | 27 | org.springframework.boot 28 | spring-boot-starter-web 29 | 30 | 31 | 32 | com.h2database 33 | h2 34 | runtime 35 | 36 | 37 | org.projectlombok 38 | lombok 39 | true 40 | 41 | 42 | org.springframework.boot 43 | spring-boot-starter-test 44 | test 45 | 46 | 47 | 48 | 49 | 50 | 51 | org.springframework.boot 52 | spring-boot-maven-plugin 53 | 54 | 55 | 56 | 57 | 58 | -------------------------------------------------------------------------------- /3.4_dependency/cart-server/src/main/java/ru/netology/cartserver/CartServerApplication.java: -------------------------------------------------------------------------------- 1 | package ru.netology.cartserver; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.boot.autoconfigure.SpringBootApplication; 5 | 6 | @SpringBootApplication 7 | public class CartServerApplication { 8 | 9 | public static void main(String[] args) { 10 | SpringApplication.run(CartServerApplication.class, args); 11 | } 12 | 13 | } 14 | -------------------------------------------------------------------------------- /3.4_dependency/cart-server/src/main/java/ru/netology/cartserver/controller/CartController.java: -------------------------------------------------------------------------------- 1 | package ru.netology.cartserver.controller; 2 | 3 | import lombok.RequiredArgsConstructor; 4 | import org.springframework.web.bind.annotation.*; 5 | import ru.netology.cartserver.domain.PurchaseItem; 6 | import ru.netology.cartserver.service.CartService; 7 | 8 | @RestController 9 | @RequestMapping("/api/cart") 10 | @RequiredArgsConstructor 11 | public class CartController { 12 | private final CartService service; 13 | 14 | @PostMapping 15 | public void add(@RequestBody PurchaseItem item) { 16 | service.add(item); 17 | } 18 | 19 | @GetMapping 20 | public PurchaseItem[] getAll() { 21 | return service.getAll(); 22 | } 23 | 24 | @DeleteMapping("/{id}") 25 | public void removeById(@PathVariable int id) { 26 | service.removeById(id); 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /3.4_dependency/cart-server/src/main/java/ru/netology/cartserver/domain/PurchaseItem.java: -------------------------------------------------------------------------------- 1 | package ru.netology.cartserver.domain; 2 | 3 | import lombok.AllArgsConstructor; 4 | import lombok.Data; 5 | import lombok.NoArgsConstructor; 6 | 7 | import javax.annotation.processing.Generated; 8 | import javax.persistence.*; 9 | 10 | @NoArgsConstructor 11 | @AllArgsConstructor 12 | @Data 13 | @Entity 14 | public class PurchaseItem { 15 | @Id 16 | @GeneratedValue(strategy = GenerationType.IDENTITY) 17 | private int id; 18 | private int productId; 19 | private String productName; 20 | private int productPrice; 21 | private int count; 22 | } 23 | -------------------------------------------------------------------------------- /3.4_dependency/cart-server/src/main/java/ru/netology/cartserver/repository/CartRepository.java: -------------------------------------------------------------------------------- 1 | package ru.netology.cartserver.repository; 2 | 3 | import org.springframework.data.jpa.repository.JpaRepository; 4 | import ru.netology.cartserver.domain.PurchaseItem; 5 | 6 | public interface CartRepository extends JpaRepository {} 7 | -------------------------------------------------------------------------------- /3.4_dependency/cart-server/src/main/java/ru/netology/cartserver/service/CartService.java: -------------------------------------------------------------------------------- 1 | package ru.netology.cartserver.service; 2 | 3 | import lombok.RequiredArgsConstructor; 4 | import org.springframework.stereotype.Service; 5 | import ru.netology.cartserver.domain.PurchaseItem; 6 | import ru.netology.cartserver.repository.CartRepository; 7 | 8 | import javax.transaction.Transactional; 9 | 10 | @Service 11 | @Transactional 12 | @RequiredArgsConstructor 13 | public class CartService { 14 | private final CartRepository repository; 15 | 16 | public void add(PurchaseItem item) { 17 | repository.save(item); 18 | } 19 | 20 | public PurchaseItem[] getAll() { 21 | return repository.findAll().toArray(new PurchaseItem[]{}); 22 | } 23 | 24 | public void removeById(int id) { 25 | repository.deleteById(id); 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /3.4_dependency/cart-server/src/main/resources/application.properties: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /3.4_dependency/cart-server/src/test/java/ru/netology/cartserver/CartServerApplicationTests.java: -------------------------------------------------------------------------------- 1 | package ru.netology.cartserver; 2 | 3 | import org.junit.jupiter.api.Test; 4 | import org.springframework.boot.test.context.SpringBootTest; 5 | 6 | @SpringBootTest 7 | class CartServerApplicationTests { 8 | 9 | @Test 10 | void contextLoads() { 11 | } 12 | 13 | } 14 | -------------------------------------------------------------------------------- /3.4_dependency/cart-with-mocks/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 4.0.0 6 | 7 | ru.netology 8 | cart-with-mocks 9 | 1.0-SNAPSHOT 10 | 11 | 12 | 11 13 | 11 14 | UTF-8 15 | 16 | 17 | 18 | 19 | com.google.code.gson 20 | gson 21 | 2.8.6 22 | 23 | 24 | org.projectlombok 25 | lombok 26 | 1.18.16 27 | provided 28 | 29 | 30 | org.junit.jupiter 31 | junit-jupiter 32 | 5.7.0 33 | test 34 | 35 | 36 | org.mockito 37 | mockito-junit-jupiter 38 | 3.6.28 39 | test 40 | 41 | 42 | 43 | 44 | 45 | 46 | org.apache.maven.plugins 47 | maven-surefire-plugin 48 | 2.22.2 49 | 50 | 51 | 52 | 53 | 54 | -------------------------------------------------------------------------------- /3.4_dependency/cart-with-mocks/src/main/java/ru/netology/Main.java: -------------------------------------------------------------------------------- 1 | package ru.netology; 2 | 3 | import ru.netology.domain.PurchaseItem; 4 | import ru.netology.repository.CartRepository; 5 | 6 | import java.util.Arrays; 7 | 8 | public class Main { 9 | public static void main(String[] args) { 10 | // Just simple demo for repository with http client (use server from ../cart-server) 11 | CartRepository repository = new CartRepository("http://localhost:8080/api/cart"); 12 | System.out.println(Arrays.toString(repository.findAll())); 13 | repository.save(new PurchaseItem(1, 1, "first", 100, 2)); 14 | System.out.println(Arrays.toString(repository.findAll())); 15 | repository.removeById(1); 16 | System.out.println(Arrays.toString(repository.findAll())); 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /3.4_dependency/cart-with-mocks/src/main/java/ru/netology/domain/PurchaseItem.java: -------------------------------------------------------------------------------- 1 | package ru.netology.domain; 2 | 3 | import lombok.AllArgsConstructor; 4 | import lombok.Data; 5 | import lombok.NoArgsConstructor; 6 | 7 | @NoArgsConstructor 8 | @AllArgsConstructor 9 | @Data 10 | public class PurchaseItem { 11 | private int id; 12 | private int productId; 13 | private String productName; 14 | private int productPrice; 15 | private int count; 16 | } 17 | -------------------------------------------------------------------------------- /3.4_dependency/cart-with-mocks/src/main/java/ru/netology/manager/CartManager.java: -------------------------------------------------------------------------------- 1 | package ru.netology.manager; 2 | 3 | import ru.netology.domain.PurchaseItem; 4 | import ru.netology.repository.CartRepository; 5 | 6 | public class CartManager { 7 | private CartRepository repository; 8 | 9 | public CartManager(CartRepository repository) { 10 | this.repository = repository; 11 | } 12 | 13 | public void add(PurchaseItem item) { 14 | repository.save(item); 15 | } 16 | 17 | public PurchaseItem[] getAll() { 18 | PurchaseItem[] items = repository.findAll(); 19 | PurchaseItem[] result = new PurchaseItem[items.length]; 20 | for (int i = 0; i < result.length; i++) { 21 | int index = items.length - i - 1; 22 | result[i] = items[index]; 23 | } 24 | return result; 25 | } 26 | 27 | public void removeById(int id) { 28 | repository.removeById(id); 29 | } 30 | 31 | public int sum() { 32 | int result = 0; 33 | for (PurchaseItem item : getAll()) { 34 | result = result + item.getProductPrice() * item.getCount(); 35 | } 36 | return result; 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /3.4_dependency/cart-with-mocks/src/main/java/ru/netology/repository/CartRepository.java: -------------------------------------------------------------------------------- 1 | package ru.netology.repository; 2 | 3 | import com.google.gson.Gson; 4 | import ru.netology.domain.PurchaseItem; 5 | 6 | import java.net.URI; 7 | import java.net.http.HttpClient; 8 | import java.net.http.HttpRequest; 9 | import java.net.http.HttpResponse; 10 | 11 | public class CartRepository { 12 | private String dbUrl; 13 | private HttpClient client = HttpClient.newHttpClient(); 14 | private Gson gson = new Gson(); 15 | 16 | public CartRepository(String dbUrl) { 17 | this.dbUrl = dbUrl; 18 | } 19 | 20 | public void save(PurchaseItem item) { 21 | HttpRequest request = HttpRequest.newBuilder(URI.create(dbUrl)) 22 | .header("Content-Type", "application/json") 23 | .POST(HttpRequest.BodyPublishers.ofString(gson.toJson(item))) 24 | .build(); 25 | makeRequest(request); 26 | } 27 | 28 | public PurchaseItem[] findAll() { 29 | HttpRequest request = HttpRequest.newBuilder(URI.create(dbUrl)) 30 | .header("Accept", "application/json") 31 | .GET() 32 | .build(); 33 | HttpResponse response = makeRequest(request); 34 | return gson.fromJson(response.body(), PurchaseItem[].class); 35 | } 36 | 37 | public void removeById(int id) { 38 | HttpRequest request = HttpRequest.newBuilder(URI.create(dbUrl + "/" + id)) 39 | .header("Content-Type", "application/json") 40 | .DELETE() 41 | .build(); 42 | makeRequest(request); 43 | } 44 | 45 | private HttpResponse makeRequest(HttpRequest request) { 46 | try { 47 | HttpResponse response = client.send(request, HttpResponse.BodyHandlers.ofString()); 48 | if (response.statusCode() < 200 || response.statusCode() > 299) { 49 | throw new RuntimeException("request didn't complete successfully"); 50 | } 51 | 52 | return response; 53 | } catch (Exception e) { 54 | throw new RuntimeException(e); 55 | } 56 | } 57 | } 58 | 59 | -------------------------------------------------------------------------------- /3.4_dependency/cart-with-mocks/src/test/java/ru/netology/manager/CartManagerTestNonEmpty.java: -------------------------------------------------------------------------------- 1 | package ru.netology.manager; 2 | 3 | import org.junit.jupiter.api.Test; 4 | import org.junit.jupiter.api.extension.ExtendWith; 5 | import org.mockito.InjectMocks; 6 | import org.mockito.Mock; 7 | import org.mockito.junit.jupiter.MockitoExtension; 8 | import ru.netology.domain.PurchaseItem; 9 | import ru.netology.repository.CartRepository; 10 | 11 | import static org.junit.jupiter.api.Assertions.assertEquals; 12 | import static org.mockito.Mockito.doReturn; 13 | import static org.mockito.Mockito.verify; 14 | 15 | @ExtendWith(MockitoExtension.class) 16 | public class CartManagerTestNonEmpty { 17 | @Mock 18 | private CartRepository repository; 19 | @InjectMocks 20 | private CartManager manager; 21 | private PurchaseItem first = new PurchaseItem(1, 1, "first", 100, 2); 22 | private PurchaseItem second = new PurchaseItem(2, 2, "second", 10, 1); 23 | private PurchaseItem third = new PurchaseItem(3, 3, "third", 1, 2); 24 | 25 | @Test 26 | public void shouldCalculateSum() { 27 | // настройка заглушки 28 | PurchaseItem[] returned = new PurchaseItem[]{first, second, third}; 29 | doReturn(returned).when(repository).findAll(); 30 | 31 | int expected = 212; 32 | int actual = manager.sum(); 33 | assertEquals(expected, actual); 34 | 35 | // удостоверяемся, что заглушка была вызвана 36 | // но это уже проверка "внутренней" реализации 37 | verify(repository).findAll(); 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /3.4_dependency/cart/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 4.0.0 6 | 7 | ru.netology 8 | cart 9 | 1.0-SNAPSHOT 10 | 11 | 12 | 11 13 | 11 14 | UTF-8 15 | 16 | 17 | 18 | 19 | org.projectlombok 20 | lombok 21 | 1.18.12 22 | provided 23 | 24 | 25 | org.junit.jupiter 26 | junit-jupiter 27 | 5.4.2 28 | test 29 | 30 | 31 | 32 | 33 | 34 | 35 | org.apache.maven.plugins 36 | maven-surefire-plugin 37 | 2.22.2 38 | 39 | 40 | 41 | 42 | 43 | -------------------------------------------------------------------------------- /3.4_dependency/cart/src/main/java/ru/netology/domain/PurchaseItem.java: -------------------------------------------------------------------------------- 1 | package ru.netology.domain; 2 | 3 | import lombok.AllArgsConstructor; 4 | import lombok.Data; 5 | import lombok.NoArgsConstructor; 6 | 7 | @NoArgsConstructor 8 | @AllArgsConstructor 9 | @Data 10 | public class PurchaseItem { 11 | private int id; 12 | private int productId; 13 | private String productName; 14 | private int productPrice; 15 | private int count; 16 | } 17 | -------------------------------------------------------------------------------- /3.4_dependency/cart/src/main/java/ru/netology/manager/CartManager.java: -------------------------------------------------------------------------------- 1 | package ru.netology.manager; 2 | 3 | import ru.netology.domain.PurchaseItem; 4 | 5 | public class CartManager { 6 | private PurchaseItem[] items = new PurchaseItem[0]; 7 | 8 | public void add(PurchaseItem item) { 9 | // создаём новый массив размером на единицу больше 10 | int length = items.length + 1; 11 | PurchaseItem[] tmp = new PurchaseItem[length]; 12 | // itar + tab 13 | // копируем поэлементно 14 | // for (int i = 0; i < items.length; i++) { 15 | // tmp[i] = items[i]; 16 | // } 17 | System.arraycopy(items, 0, tmp, 0, items.length); 18 | // кладём последним наш элемент 19 | int lastIndex = tmp.length - 1; 20 | tmp[lastIndex] = item; 21 | items = tmp; 22 | } 23 | 24 | public PurchaseItem[] getAll() { 25 | PurchaseItem[] result = new PurchaseItem[items.length]; 26 | // перебираем массив в прямом порядке 27 | // но кладём в результаты в обратном 28 | for (int i = 0; i < result.length; i++) { 29 | int index = items.length - i - 1; 30 | result[i] = items[index]; 31 | } 32 | return result; 33 | } 34 | 35 | // наивная реализация 36 | public void removeById(int id) { 37 | int length = items.length - 1; 38 | PurchaseItem[] tmp = new PurchaseItem[length]; 39 | int index = 0; 40 | for (PurchaseItem item : items) { 41 | if (item.getId() != id) { 42 | tmp[index] = item; 43 | index++; 44 | } 45 | } 46 | // меняем наши элементы 47 | items = tmp; 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /3.4_dependency/cart/src/test/java/ru/netology/manager/CartManagerTestNonEmpty.java: -------------------------------------------------------------------------------- 1 | package ru.netology.manager; 2 | 3 | import org.junit.jupiter.api.Test; 4 | import ru.netology.domain.PurchaseItem; 5 | import ru.netology.manager.CartManager; 6 | 7 | import static org.junit.jupiter.api.Assertions.*; 8 | 9 | public class CartManagerTestNonEmpty { 10 | @Test 11 | public void shouldRemoveIfExists() { 12 | CartManager manager = new CartManager(); 13 | int idToRemove = 1; 14 | PurchaseItem first = new PurchaseItem(1, 1, "first", 1, 1); 15 | PurchaseItem second = new PurchaseItem(2, 2, "second", 1, 1); 16 | PurchaseItem third = new PurchaseItem(3, 3, "third", 1, 1); 17 | manager.add(first); 18 | manager.add(second); 19 | manager.add(third); 20 | 21 | manager.removeById(idToRemove); 22 | 23 | PurchaseItem[] actual = manager.getAll(); 24 | PurchaseItem[] expected = new PurchaseItem[]{third, second}; 25 | 26 | // assertEquals(expected, actual); 27 | assertArrayEquals(expected, actual); 28 | } 29 | 30 | @Test 31 | public void shouldNotRemoveIfNotExists() { 32 | CartManager manager = new CartManager(); 33 | int idToRemove = 4; 34 | PurchaseItem first = new PurchaseItem(1, 1, "first", 1, 1); 35 | PurchaseItem second = new PurchaseItem(2, 2, "second", 1, 1); 36 | PurchaseItem third = new PurchaseItem(3, 3, "third", 1, 1); 37 | manager.add(first); 38 | manager.add(second); 39 | manager.add(third); 40 | 41 | manager.removeById(idToRemove); 42 | 43 | PurchaseItem[] actual = manager.getAll(); 44 | PurchaseItem[] expected = new PurchaseItem[]{third, second, first}; 45 | 46 | assertArrayEquals(expected, actual); 47 | } 48 | } -------------------------------------------------------------------------------- /3.4_dependency/cart/src/test/java/ru/netology/manager/CartManagerTestNonEmptyWithSetup.java: -------------------------------------------------------------------------------- 1 | package ru.netology.manager; 2 | 3 | import org.junit.jupiter.api.BeforeEach; 4 | import org.junit.jupiter.api.Test; 5 | import ru.netology.domain.PurchaseItem; 6 | import ru.netology.manager.CartManager; 7 | 8 | import static org.junit.jupiter.api.Assertions.assertArrayEquals; 9 | 10 | public class CartManagerTestNonEmptyWithSetup { 11 | private CartManager manager = new CartManager(); 12 | private PurchaseItem first = new PurchaseItem(1, 1, "first", 1, 1); 13 | private PurchaseItem second = new PurchaseItem(2, 2, "second", 1, 1); 14 | private PurchaseItem third = new PurchaseItem(3, 3, "third", 1, 1); 15 | 16 | @BeforeEach 17 | public void setUp() { 18 | manager.add(first); 19 | manager.add(second); 20 | manager.add(third); 21 | } 22 | 23 | @Test 24 | public void shouldRemoveIfExists() { 25 | int idToRemove = 1; 26 | manager.removeById(idToRemove); 27 | 28 | PurchaseItem[] actual = manager.getAll(); 29 | PurchaseItem[] expected = new PurchaseItem[]{third, second}; 30 | 31 | // assertEquals(expected, actual); 32 | assertArrayEquals(expected, actual); 33 | } 34 | 35 | @Test 36 | public void shouldNotRemoveIfNotExists() { 37 | int idToRemove = 4; 38 | 39 | manager.removeById(idToRemove); 40 | 41 | PurchaseItem[] actual = manager.getAll(); 42 | PurchaseItem[] expected = new PurchaseItem[]{third, second, first}; 43 | 44 | assertArrayEquals(expected, actual); 45 | } 46 | } -------------------------------------------------------------------------------- /3.5_inheritance/lombok-inheritance/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 4.0.0 6 | 7 | ru.netology 8 | lombok-inheritance 9 | 1.0-SNAPSHOT 10 | 11 | 12 | 11 13 | 11 14 | UTF-8 15 | 16 | 17 | 18 | 19 | org.projectlombok 20 | lombok 21 | 1.18.12 22 | provided 23 | 24 | 25 | org.junit.jupiter 26 | junit-jupiter 27 | 5.4.2 28 | test 29 | 30 | 31 | org.mockito 32 | mockito-junit-jupiter 33 | 3.3.3 34 | test 35 | 36 | 37 | 38 | 39 | 40 | 41 | org.apache.maven.plugins 42 | maven-surefire-plugin 43 | 2.22.2 44 | 45 | 46 | 47 | 48 | 49 | -------------------------------------------------------------------------------- /3.5_inheritance/lombok-inheritance/src/main/java/ru/netology/domain/Book.java: -------------------------------------------------------------------------------- 1 | package ru.netology.domain; 2 | 3 | import lombok.Data; 4 | import lombok.EqualsAndHashCode; 5 | 6 | @Data 7 | @EqualsAndHashCode(callSuper = true) 8 | public class Book extends Product { 9 | private String author; 10 | private int pages; 11 | private int publishedYear; 12 | 13 | public Book() { 14 | } 15 | 16 | public Book(int id, String name, int price, String author, int pages, int publishedYear) { 17 | super(id, name, price); 18 | this.author = author; 19 | this.pages = pages; 20 | this.publishedYear = publishedYear; 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /3.5_inheritance/lombok-inheritance/src/main/java/ru/netology/domain/Product.java: -------------------------------------------------------------------------------- 1 | package ru.netology.domain; 2 | 3 | import lombok.AllArgsConstructor; 4 | import lombok.Data; 5 | import lombok.NoArgsConstructor; 6 | 7 | @NoArgsConstructor 8 | @AllArgsConstructor 9 | @Data 10 | public class Product { 11 | private int id; 12 | private String name; 13 | private int price; 14 | } 15 | -------------------------------------------------------------------------------- /3.5_inheritance/products/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 4.0.0 6 | 7 | ru.netology 8 | products 9 | 1.0-SNAPSHOT 10 | 11 | 12 | 11 13 | 11 14 | UTF-8 15 | 16 | 17 | 18 | 19 | org.projectlombok 20 | lombok 21 | 1.18.12 22 | provided 23 | 24 | 25 | org.junit.jupiter 26 | junit-jupiter 27 | 5.4.2 28 | test 29 | 30 | 31 | org.mockito 32 | mockito-junit-jupiter 33 | 3.3.3 34 | test 35 | 36 | 37 | 38 | 39 | 40 | 41 | org.apache.maven.plugins 42 | maven-surefire-plugin 43 | 2.22.2 44 | 45 | 46 | 47 | -------------------------------------------------------------------------------- /3.5_inheritance/products/src/main/java/ru/netology/domain/Book.java: -------------------------------------------------------------------------------- 1 | package ru.netology.domain; 2 | 3 | import java.util.Objects; 4 | 5 | public class Book extends Product { 6 | private String author; 7 | private int pages; 8 | private int publishedYear; 9 | 10 | public Book() { 11 | super(); 12 | } 13 | 14 | public Book(int id, String name, int price, String author, int pages, int publishedYear) { 15 | super(id, name, price); 16 | this.author = author; 17 | this.pages = pages; 18 | this.publishedYear = publishedYear; 19 | } 20 | 21 | public String getAuthor() { 22 | return author; 23 | } 24 | 25 | public void setAuthor(String author) { 26 | this.author = author; 27 | } 28 | 29 | public int getPages() { 30 | return pages; 31 | } 32 | 33 | public void setPages(int pages) { 34 | this.pages = pages; 35 | } 36 | 37 | public int getPublishedYear() { 38 | return publishedYear; 39 | } 40 | 41 | public void setPublishedYear(int publishedYear) { 42 | this.publishedYear = publishedYear; 43 | } 44 | 45 | @Override 46 | public boolean equals(Object o) { 47 | if (this == o) return true; 48 | if (o == null || getClass() != o.getClass()) return false; 49 | if (!super.equals(o)) return false; 50 | Book book = (Book) o; 51 | return pages == book.pages && 52 | publishedYear == book.publishedYear && 53 | Objects.equals(author, book.author); 54 | } 55 | 56 | @Override 57 | public int hashCode() { 58 | return Objects.hash(super.hashCode(), author, pages, publishedYear); 59 | } 60 | 61 | @Override 62 | public String toString() { 63 | return "Book{" + 64 | "author='" + author + '\'' + 65 | ", pages=" + pages + 66 | ", publishedYear=" + publishedYear + 67 | '}'; 68 | } 69 | } 70 | -------------------------------------------------------------------------------- /3.5_inheritance/products/src/main/java/ru/netology/domain/MFU.java: -------------------------------------------------------------------------------- 1 | package ru.netology.domain; 2 | 3 | class Printer { 4 | public void print() { 5 | } 6 | } 7 | 8 | class Scanner { 9 | public void scan() { 10 | } 11 | } 12 | 13 | //class MFU extends Printer, Scanner { 14 | //} 15 | 16 | class MFU { 17 | private Printer printer; 18 | private Scanner scanner; 19 | 20 | public void print() { 21 | printer.print(); 22 | } 23 | 24 | public void scan() { 25 | scanner.scan(); 26 | } 27 | } 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | -------------------------------------------------------------------------------- /3.5_inheritance/products/src/main/java/ru/netology/domain/Product.java: -------------------------------------------------------------------------------- 1 | package ru.netology.domain; 2 | 3 | import java.util.Objects; 4 | 5 | public class Product { 6 | private int id; 7 | private String name; 8 | private int price; 9 | 10 | public Product() { 11 | } 12 | 13 | public Product(int id, String name, int price) { 14 | this.id = id; 15 | this.name = name; 16 | this.price = price; 17 | } 18 | 19 | public int getId() { 20 | return id; 21 | } 22 | 23 | public void setId(int id) { 24 | this.id = id; 25 | } 26 | 27 | public String getName() { 28 | return name; 29 | } 30 | 31 | public void setName(String name) { 32 | this.name = name; 33 | } 34 | 35 | public int getPrice() { 36 | return price; 37 | } 38 | 39 | public void setPrice(int price) { 40 | this.price = price; 41 | } 42 | 43 | @Override 44 | public boolean equals(Object o) { 45 | if (this == o) return true; 46 | if (o == null || getClass() != o.getClass()) return false; 47 | Product product = (Product) o; 48 | return id == product.id && 49 | price == product.price && 50 | Objects.equals(name, product.name); 51 | } 52 | 53 | @Override 54 | public int hashCode() { 55 | return Objects.hash(id, name, price); 56 | } 57 | 58 | @Override 59 | public String toString() { 60 | return "Product{" + 61 | "id=" + id + 62 | ", name='" + name + '\'' + 63 | ", price=" + price + 64 | '}'; 65 | } 66 | } 67 | -------------------------------------------------------------------------------- /3.5_inheritance/products/src/main/java/ru/netology/domain/TShirt.java: -------------------------------------------------------------------------------- 1 | package ru.netology.domain; 2 | 3 | import java.util.Objects; 4 | 5 | public class TShirt extends Product { 6 | private String color; 7 | private String size; 8 | 9 | @Override 10 | public boolean equals(Object o) { 11 | if (this == o) return true; 12 | if (o == null || getClass() != o.getClass()) return false; 13 | if (!super.equals(o)) return false; 14 | TShirt shirt = (TShirt) o; 15 | return Objects.equals(color, shirt.color) && 16 | Objects.equals(size, shirt.size); 17 | } 18 | 19 | @Override 20 | public int hashCode() { 21 | return Objects.hash(super.hashCode(), color, size); 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /3.5_inheritance/products/src/main/java/ru/netology/repository/ProductRepository.java: -------------------------------------------------------------------------------- 1 | package ru.netology.repository; 2 | 3 | import ru.netology.domain.Product; 4 | 5 | public class ProductRepository { 6 | private Product[] items = new Product[0]; 7 | 8 | public void save(Product item) { 9 | int length = items.length + 1; 10 | Product[] tmp = new Product[length]; 11 | System.arraycopy(items, 0, tmp, 0, items.length); 12 | int lastIndex = tmp.length - 1; 13 | tmp[lastIndex] = item; 14 | items = tmp; 15 | } 16 | 17 | public Product[] findAll() { 18 | return items; 19 | } 20 | 21 | public Product findById(int id) { 22 | for (Product item : items) { 23 | if (item.getId() == id) { 24 | return item; 25 | } 26 | } 27 | return null; 28 | } 29 | 30 | public void removeById(int id) { 31 | int length = items.length - 1; 32 | Product[] tmp = new Product[length]; 33 | int index = 0; 34 | for (Product item : items) { 35 | if (item.getId() != id) { 36 | tmp[index] = item; 37 | index++; 38 | } 39 | } 40 | items = tmp; 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /3.5_inheritance/products/src/test/java/ru/netology/domain/BookTest.java: -------------------------------------------------------------------------------- 1 | package ru.netology.domain; 2 | 3 | import org.junit.jupiter.api.Test; 4 | 5 | import static org.junit.jupiter.api.Assertions.*; 6 | 7 | class BookTest { 8 | @Test 9 | public void shouldHaveAllFieldsAndMethodFromSuperClass() { 10 | Book book = new Book(); 11 | // book. 12 | } 13 | 14 | @Test 15 | public void shouldCastFromBaseClass() { 16 | Product product = new Book(); 17 | if (product instanceof Book) { 18 | Book book = (Book) product; 19 | // book. 20 | } 21 | } 22 | 23 | @Test 24 | public void shouldNotCastToDifferentClass() { 25 | Product product = new Book(); 26 | TShirt shirt = (TShirt) product; 27 | } 28 | 29 | @Test 30 | public void shouldUseOverridedMethod() { 31 | Product product = new Book(); 32 | // Вопрос к аудитории: чей метод вызовется? 33 | product.toString(); 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /3.5_inheritance/products/src/test/java/ru/netology/domain/ProductTest.java: -------------------------------------------------------------------------------- 1 | package ru.netology.domain; 2 | 3 | import org.junit.jupiter.api.Test; 4 | 5 | import static org.junit.jupiter.api.Assertions.*; 6 | 7 | class ProductTest { 8 | @Test 9 | public void shouldUseEquals() { 10 | Product first = new Product(1, "Java I", 1000); 11 | Product second = new Product(1, "Java I", 1000); 12 | assertEquals(first, second); 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /3.5_inheritance/products/src/test/java/ru/netology/repository/ProductRepositoryTest.java: -------------------------------------------------------------------------------- 1 | package ru.netology.repository; 2 | 3 | import org.junit.jupiter.api.Test; 4 | import ru.netology.domain.Book; 5 | import ru.netology.domain.Product; 6 | 7 | import static org.junit.jupiter.api.Assertions.*; 8 | 9 | class ProductRepositoryTest { 10 | private ProductRepository repository = new ProductRepository(); 11 | private Book coreJava = new Book(); 12 | 13 | @Test 14 | public void shouldSaveOneItem() { 15 | repository.save(coreJava); 16 | 17 | Product[] expected = new Product[]{coreJava}; 18 | Product[] actual = repository.findAll(); 19 | assertArrayEquals(expected, actual); 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /3.5_inheritance/reflection-sample/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 4.0.0 6 | 7 | ru.netology 8 | reflection-sample 9 | 1.0-SNAPSHOT 10 | 11 | 12 | 11 13 | 11 14 | UTF-8 15 | 16 | 17 | 18 | 19 | org.junit.jupiter 20 | junit-jupiter 21 | 5.4.2 22 | test 23 | 24 | 25 | 26 | 27 | 28 | 29 | org.apache.maven.plugins 30 | maven-surefire-plugin 31 | 2.22.2 32 | 33 | 34 | 35 | -------------------------------------------------------------------------------- /3.5_inheritance/reflection-sample/src/test/java/ru/netology/DemoTest.java: -------------------------------------------------------------------------------- 1 | package ru.netology; 2 | 3 | import org.junit.jupiter.api.Test; 4 | 5 | public class DemoTest { 6 | @Test 7 | public void shouldBeCalled() { 8 | System.out.println("Test method called"); 9 | } 10 | 11 | public void shouldNotBeCalled() { 12 | System.out.println("Invalid method called"); 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /3.5_inheritance/reflection-sample/src/test/java/ru/netology/Launcher.java: -------------------------------------------------------------------------------- 1 | package ru.netology; 2 | 3 | import org.junit.jupiter.api.Test; 4 | 5 | import java.lang.reflect.InvocationTargetException; 6 | import java.lang.reflect.Method; 7 | 8 | public class Launcher { 9 | // что такое исключения мы разберём на следующей лекции 10 | public static void main(String[] args) throws IllegalAccessException, InstantiationException, InvocationTargetException { 11 | // создаём объект типа `Class` (generic'и мы пока не знаем, поэтому и так "сойдёт") 12 | Class clazz = DemoTest.class; 13 | // берём все методы класса 14 | Method[] methods = clazz.getDeclaredMethods(); 15 | // перебираем методы 16 | for (Method method : methods) { 17 | // смотрим, есть ли над методом аннотация @Test 18 | if (method.isAnnotationPresent(Test.class)) { 19 | // создаём объект класса (newInstance помечен аннотацией @Deprecated, но для простоты мы будем использовать его, в противном случае, нужно выбирать конструкторы) 20 | Object object = clazz.newInstance(); 21 | // вызываем метод на объекте 22 | method.invoke(object); 23 | } 24 | } 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /3.5_inheritance/static-sample/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 4.0.0 6 | 7 | ru.netology 8 | static-sample 9 | 1.0-SNAPSHOT 10 | 11 | 12 | 11 13 | 11 14 | UTF-8 15 | 16 | 17 | 18 | 19 | org.junit.jupiter 20 | junit-jupiter 21 | 5.4.2 22 | test 23 | 24 | 25 | 26 | 27 | 28 | 29 | org.apache.maven.plugins 30 | maven-surefire-plugin 31 | 2.22.2 32 | 33 | 34 | 35 | -------------------------------------------------------------------------------- /3.5_inheritance/static-sample/src/main/java/ru/netology/Main.java: -------------------------------------------------------------------------------- 1 | package ru.netology; 2 | 3 | public class Main { 4 | public static void main(String[] args) { 5 | double result = Math.sin(Math.PI / 2); 6 | System.out.println(result); 7 | } 8 | } 9 | -------------------------------------------------------------------------------- /3.5_inheritance/static-sample/src/test/java/ru/netology/SampleTest.java: -------------------------------------------------------------------------------- 1 | package ru.netology; 2 | 3 | import org.junit.jupiter.api.Test; 4 | 5 | import static org.junit.jupiter.api.Assertions.assertTrue; 6 | 7 | class SampleTest { 8 | @Test 9 | public void shouldPass() { 10 | assertTrue(true); 11 | } 12 | } 13 | 14 | -------------------------------------------------------------------------------- /4.1_exceptions/exception-types/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 4.0.0 6 | 7 | ru.netology 8 | exception-types 9 | 1.0-SNAPSHOT 10 | 11 | 12 | 11 13 | 11 14 | UTF-8 15 | 16 | 17 | 18 | 19 | org.projectlombok 20 | lombok 21 | 1.18.12 22 | provided 23 | 24 | 25 | org.junit.jupiter 26 | junit-jupiter 27 | 5.4.2 28 | test 29 | 30 | 31 | org.mockito 32 | mockito-junit-jupiter 33 | 3.3.3 34 | test 35 | 36 | 37 | 38 | 39 | 40 | 41 | org.apache.maven.plugins 42 | maven-surefire-plugin 43 | 2.22.2 44 | 45 | 46 | 47 | 48 | -------------------------------------------------------------------------------- /4.1_exceptions/exception-types/src/main/java/Main.java: -------------------------------------------------------------------------------- 1 | import exception.CheckedException; 2 | import service.Service; 3 | 4 | public class Main { 5 | public static void main(String[] args) { 6 | Service service = new Service(); 7 | 8 | try { 9 | service.throwChecked(); 10 | } catch (CheckedException e) { 11 | e.printStackTrace(); 12 | } 13 | 14 | service.throwUnchecked(); 15 | } 16 | } 17 | 18 | -------------------------------------------------------------------------------- /4.1_exceptions/exception-types/src/main/java/exception/CheckedException.java: -------------------------------------------------------------------------------- 1 | package exception; 2 | 3 | public class CheckedException extends Exception { 4 | public CheckedException() { 5 | super(); 6 | } 7 | 8 | public CheckedException(String message) { 9 | super(message); 10 | } 11 | 12 | public CheckedException(String message, Throwable cause) { 13 | super(message, cause); 14 | } 15 | 16 | public CheckedException(Throwable cause) { 17 | super(cause); 18 | } 19 | 20 | protected CheckedException(String message, Throwable cause, boolean enableSuppression, boolean writableStackTrace) { 21 | super(message, cause, enableSuppression, writableStackTrace); 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /4.1_exceptions/exception-types/src/main/java/exception/UncheckedException.java: -------------------------------------------------------------------------------- 1 | package exception; 2 | 3 | public class UncheckedException extends RuntimeException { 4 | public UncheckedException() { 5 | } 6 | 7 | public UncheckedException(String message) { 8 | super(message); 9 | } 10 | 11 | public UncheckedException(String message, Throwable cause) { 12 | super(message, cause); 13 | } 14 | 15 | public UncheckedException(Throwable cause) { 16 | super(cause); 17 | } 18 | 19 | public UncheckedException(String message, Throwable cause, boolean enableSuppression, boolean writableStackTrace) { 20 | super(message, cause, enableSuppression, writableStackTrace); 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /4.1_exceptions/exception-types/src/main/java/service/Service.java: -------------------------------------------------------------------------------- 1 | package service; 2 | 3 | import exception.CheckedException; 4 | import exception.UncheckedException; 5 | 6 | public class Service { 7 | public void throwChecked() throws CheckedException { 8 | throw new CheckedException(); 9 | } 10 | 11 | public void throwUnchecked() { 12 | throw new UncheckedException(); 13 | } 14 | } 15 | 16 | 17 | 18 | 19 | 20 | 21 | -------------------------------------------------------------------------------- /4.1_exceptions/exception-types/src/test/java/service/ServiceTest.java: -------------------------------------------------------------------------------- 1 | package service; 2 | 3 | import exception.CheckedException; 4 | import exception.UncheckedException; 5 | import org.junit.jupiter.api.Test; 6 | 7 | import static org.junit.jupiter.api.Assertions.*; 8 | 9 | public class ServiceTest { 10 | private Service service = new Service(); 11 | 12 | @Test 13 | public void shouldThrowCheckedException() { 14 | assertThrows(CheckedException.class, () -> service.throwChecked()); 15 | } 16 | 17 | @Test 18 | public void shouldThrowUncheckedException() { 19 | assertThrows(UncheckedException.class, () -> service.throwUnchecked()); 20 | } 21 | } 22 | 23 | 24 | -------------------------------------------------------------------------------- /4.1_exceptions/exceptions/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 4.0.0 6 | 7 | ru.netology 8 | exceptions 9 | 1.0-SNAPSHOT 10 | 11 | 12 | 11 13 | 11 14 | UTF-8 15 | 16 | 17 | 18 | 19 | org.projectlombok 20 | lombok 21 | 1.18.12 22 | provided 23 | 24 | 25 | org.junit.jupiter 26 | junit-jupiter 27 | 5.4.2 28 | test 29 | 30 | 31 | org.mockito 32 | mockito-junit-jupiter 33 | 3.3.3 34 | test 35 | 36 | 37 | 38 | 39 | 40 | 41 | org.apache.maven.plugins 42 | maven-surefire-plugin 43 | 2.22.2 44 | 45 | 46 | 47 | 48 | -------------------------------------------------------------------------------- /4.1_exceptions/exceptions/src/main/java/ru/netology/Main.java: -------------------------------------------------------------------------------- 1 | package ru.netology; 2 | 3 | import ru.netology.domain.PurchaseItem; 4 | import ru.netology.manager.CartManager; 5 | import ru.netology.repository.CartRepository; 6 | 7 | public class Main { 8 | public static void main(String[] args) { 9 | CartManager manager = new CartManager(new CartRepository()); 10 | manager.add(new PurchaseItem( 11 | 1, 12 | 1, 13 | "Java Core", 14 | 1000, 15 | 1 16 | )); 17 | 18 | // manager.removeById(2); 19 | // System.out.println("main done"); // for demo only 20 | 21 | // try { 22 | // System.out.println("before remove"); 23 | // manager.removeById(2); 24 | // System.out.println("after remove"); 25 | // } catch (ArrayIndexOutOfBoundsException e) { 26 | // e.printStackTrace(); 27 | // System.out.println("specific catch"); 28 | // } catch (RuntimeException e) { 29 | // System.out.println("runtime catch"); 30 | // } catch (Exception e) { 31 | // System.out.println("catch"); 32 | // } finally { 33 | // System.out.println("finally"); 34 | // } 35 | 36 | try { 37 | System.out.println("before remove"); 38 | manager.removeById(2); 39 | System.out.println("after remove"); 40 | } catch (Throwable e) { 41 | 42 | } 43 | 44 | 45 | 46 | 47 | System.out.println("main done"); // for demo only 48 | } 49 | } 50 | 51 | -------------------------------------------------------------------------------- /4.1_exceptions/exceptions/src/main/java/ru/netology/domain/PurchaseItem.java: -------------------------------------------------------------------------------- 1 | package ru.netology.domain; 2 | 3 | import lombok.AllArgsConstructor; 4 | import lombok.Data; 5 | import lombok.NoArgsConstructor; 6 | 7 | @NoArgsConstructor 8 | @AllArgsConstructor 9 | @Data 10 | public class PurchaseItem { 11 | private int id; 12 | private int productId; 13 | private String productName; 14 | private int productPrice; 15 | private int count; 16 | } 17 | -------------------------------------------------------------------------------- /4.1_exceptions/exceptions/src/main/java/ru/netology/manager/CartManager.java: -------------------------------------------------------------------------------- 1 | package ru.netology.manager; 2 | 3 | import ru.netology.domain.PurchaseItem; 4 | import ru.netology.repository.CartRepository; 5 | 6 | public class CartManager { 7 | private CartRepository repository; 8 | 9 | public void removeById(int id) { 10 | repository.removeById(id); 11 | System.out.println("manager done"); // for demo only 12 | } 13 | 14 | public CartManager(CartRepository repository) { 15 | this.repository = repository; 16 | } 17 | 18 | public void add(PurchaseItem item) { 19 | repository.save(item); 20 | } 21 | 22 | public PurchaseItem[] getAll() { 23 | PurchaseItem[] items = repository.findAll(); 24 | PurchaseItem[] result = new PurchaseItem[items.length]; 25 | for (int i = 0; i < result.length; i++) { 26 | int index = items.length - i - 1; 27 | result[i] = items[index]; 28 | } 29 | return result; 30 | } 31 | 32 | } 33 | 34 | 35 | -------------------------------------------------------------------------------- /4.1_exceptions/exceptions/src/main/java/ru/netology/repository/CartRepository.java: -------------------------------------------------------------------------------- 1 | package ru.netology.repository; 2 | 3 | import ru.netology.domain.PurchaseItem; 4 | 5 | public class CartRepository { 6 | private PurchaseItem[] items = new PurchaseItem[0]; 7 | 8 | public void removeById(int id) { 9 | int length = items.length - 1; 10 | PurchaseItem[] tmp = new PurchaseItem[length]; 11 | int index = 0; 12 | for (PurchaseItem item : items) { 13 | if (item.getId() != id) { 14 | tmp[index] = item; 15 | index++; 16 | } 17 | } 18 | items = tmp; 19 | System.out.println("repo done"); // for demo only 20 | } 21 | 22 | 23 | public void save(PurchaseItem item) { 24 | int length = items.length + 1; 25 | PurchaseItem[] tmp = new PurchaseItem[length]; 26 | System.arraycopy(items, 0, tmp, 0, items.length); 27 | int lastIndex = tmp.length - 1; 28 | tmp[lastIndex] = item; 29 | items = tmp; 30 | } 31 | 32 | public PurchaseItem[] findAll() { 33 | return items; 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /4.2_interfaces/mfu/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 4.0.0 6 | 7 | ru.netology 8 | mfu 9 | 1.0-SNAPSHOT 10 | 11 | 12 | 11 13 | 11 14 | UTF-8 15 | 16 | 17 | 18 | 19 | org.projectlombok 20 | lombok 21 | 1.18.12 22 | provided 23 | 24 | 25 | org.junit.jupiter 26 | junit-jupiter 27 | 5.4.2 28 | test 29 | 30 | 31 | org.mockito 32 | mockito-junit-jupiter 33 | 3.3.3 34 | test 35 | 36 | 37 | 38 | 39 | 40 | 41 | org.apache.maven.plugins 42 | maven-surefire-plugin 43 | 2.22.2 44 | 45 | 46 | 47 | 48 | -------------------------------------------------------------------------------- /4.2_interfaces/mfu/src/main/java/ru/netology/Printer.java: -------------------------------------------------------------------------------- 1 | package ru.netology; 2 | 3 | import ru.netology.domain.Document; 4 | 5 | public interface Printer { 6 | void print(Document document); 7 | } 8 | -------------------------------------------------------------------------------- /4.2_interfaces/mfu/src/main/java/ru/netology/Scanner.java: -------------------------------------------------------------------------------- 1 | package ru.netology; 2 | 3 | import ru.netology.domain.Document; 4 | 5 | public interface Scanner { 6 | Document scan(); 7 | } 8 | -------------------------------------------------------------------------------- /4.2_interfaces/mfu/src/main/java/ru/netology/domain/Document.java: -------------------------------------------------------------------------------- 1 | package ru.netology.domain; 2 | 3 | import lombok.AllArgsConstructor; 4 | import lombok.Data; 5 | import lombok.NoArgsConstructor; 6 | 7 | @NoArgsConstructor 8 | @AllArgsConstructor 9 | @Data 10 | public class Document { 11 | private int id; 12 | private String name; 13 | private String content; 14 | } 15 | -------------------------------------------------------------------------------- /4.2_interfaces/mfu/src/main/java/ru/netology/hp/LJ1210.java: -------------------------------------------------------------------------------- 1 | package ru.netology.hp; 2 | 3 | import ru.netology.Printer; 4 | import ru.netology.domain.Document; 5 | 6 | public class LJ1210 implements Printer { 7 | @Override 8 | public void print(Document document) { 9 | 10 | } 11 | } 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | -------------------------------------------------------------------------------- /4.2_interfaces/mfu/src/main/java/ru/netology/hp/LJProM283.java: -------------------------------------------------------------------------------- 1 | package ru.netology.hp; 2 | 3 | import ru.netology.Printer; 4 | import ru.netology.Scanner; 5 | import ru.netology.domain.Document; 6 | 7 | public class LJProM283 implements Printer, Scanner { 8 | @Override 9 | public void print(Document document) { 10 | 11 | } 12 | 13 | @Override 14 | public Document scan() { 15 | return null; 16 | } 17 | } 18 | 19 | 20 | -------------------------------------------------------------------------------- /4.2_interfaces/mfu/src/main/java/ru/netology/service/OfficeService.java: -------------------------------------------------------------------------------- 1 | package ru.netology.service; 2 | 3 | import ru.netology.domain.Document; 4 | import ru.netology.Printer; 5 | 6 | public class OfficeService { 7 | public void print(Document document, Printer printer) { 8 | printer.print(document); 9 | } 10 | } 11 | 12 | 13 | 14 | 15 | -------------------------------------------------------------------------------- /4.2_interfaces/sorting/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 4.0.0 6 | 7 | ru.netology 8 | sorting 9 | 1.0-SNAPSHOT 10 | 11 | 12 | 11 13 | 11 14 | UTF-8 15 | 16 | 17 | 18 | 19 | org.projectlombok 20 | lombok 21 | 1.18.12 22 | provided 23 | 24 | 25 | org.junit.jupiter 26 | junit-jupiter 27 | 5.4.2 28 | test 29 | 30 | 31 | org.mockito 32 | mockito-junit-jupiter 33 | 3.3.3 34 | test 35 | 36 | 37 | 38 | 39 | 40 | 41 | org.apache.maven.plugins 42 | maven-surefire-plugin 43 | 2.22.2 44 | 45 | 46 | 47 | 48 | -------------------------------------------------------------------------------- /4.2_interfaces/sorting/src/main/java/ru/netology/container/Box.java: -------------------------------------------------------------------------------- 1 | package ru.netology.container; 2 | 3 | public class Box { 4 | private Object value; 5 | 6 | public Box(Object value) { 7 | this.value = value; 8 | } 9 | 10 | public boolean isEmpty() { 11 | return value == null; 12 | } 13 | 14 | public Object getValue() { 15 | return value; 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /4.2_interfaces/sorting/src/main/java/ru/netology/container/GenericBox.java: -------------------------------------------------------------------------------- 1 | package ru.netology.container; 2 | 3 | public class GenericBox { 4 | private T value; 5 | // constructor + isEmpty + getValue 6 | } 7 | 8 | // public GenericBox(T value) { 9 | // this.value = value; 10 | // } 11 | // 12 | // public boolean isEmpty() { 13 | // return value == null; 14 | // } 15 | // 16 | // public T getValue() { 17 | // return value; 18 | // } 19 | 20 | 21 | -------------------------------------------------------------------------------- /4.2_interfaces/sorting/src/main/java/ru/netology/domain/Product.java: -------------------------------------------------------------------------------- 1 | package ru.netology.domain; 2 | 3 | import lombok.AllArgsConstructor; 4 | import lombok.Data; 5 | import lombok.NoArgsConstructor; 6 | 7 | //@NoArgsConstructor 8 | //@AllArgsConstructor 9 | //@Data 10 | //public class Product implements Comparable { 11 | // private int id; 12 | // private String name; 13 | // private int price; 14 | // private double rating; 15 | // 16 | // @Override 17 | // public int compareTo(Object o) { 18 | // Product p = (Product) o; 19 | // return id - p.id; 20 | // } 21 | //} 22 | 23 | @NoArgsConstructor 24 | @AllArgsConstructor 25 | @Data 26 | public class Product implements Comparable { 27 | private int id; 28 | private String name; 29 | private int price; 30 | private double rating; 31 | 32 | @Override 33 | public int compareTo(Product o) { 34 | return id - o.id; 35 | } 36 | } 37 | 38 | 39 | -------------------------------------------------------------------------------- /4.2_interfaces/sorting/src/test/java/ru/netology/MathTest.java: -------------------------------------------------------------------------------- 1 | package ru.netology; 2 | 3 | import org.junit.jupiter.api.Assertions; 4 | import org.junit.jupiter.api.Test; 5 | 6 | import static org.junit.jupiter.api.Assertions.assertEquals; 7 | 8 | public class MathTest { 9 | @Test 10 | public void shouldCalculateSin() { 11 | double result = Math.sin(Math.PI / 2); 12 | double expected = 1.0; 13 | double delta = 0.01; 14 | Assertions.assertEquals(expected, result, delta); 15 | } 16 | } 17 | 18 | 19 | -------------------------------------------------------------------------------- /4.2_interfaces/sorting/src/test/java/ru/netology/container/BoxTest.java: -------------------------------------------------------------------------------- 1 | package ru.netology.container; 2 | 3 | import org.junit.jupiter.api.Test; 4 | import ru.netology.domain.Product; 5 | 6 | import static org.junit.jupiter.api.Assertions.*; 7 | 8 | class BoxTest { 9 | @Test 10 | public void shouldSaveAndReturnValue() { 11 | Product product = new Product(); 12 | Box box = new Box(product); 13 | 14 | Object value = box.getValue(); 15 | assertEquals(product, value); 16 | } 17 | } 18 | 19 | 20 | 21 | -------------------------------------------------------------------------------- /4.2_interfaces/sorting/src/test/java/ru/netology/container/GenericBoxTest.java: -------------------------------------------------------------------------------- 1 | package ru.netology.container; 2 | 3 | import org.junit.jupiter.api.Test; 4 | import ru.netology.domain.Product; 5 | 6 | import static org.junit.jupiter.api.Assertions.*; 7 | 8 | class GenericBoxTest { 9 | @Test 10 | public void shouldParametrizedWithProduct() { 11 | Product product = new Product(); 12 | GenericBox productBox = new GenericBox<>(product); 13 | 14 | Product value = productBox.getValue(); 15 | assertEquals(product, value); 16 | } 17 | 18 | @Test 19 | public void shouldParametrizedWithString() { 20 | String str = "Hello world"; 21 | GenericBox stringBox = new GenericBox<>(str); 22 | 23 | String value = stringBox.getValue(); 24 | assertEquals(str, value); 25 | } 26 | } 27 | 28 | 29 | 30 | -------------------------------------------------------------------------------- /4.2_interfaces/sorting/src/test/java/ru/netology/domain/ProductsTest.java: -------------------------------------------------------------------------------- 1 | package ru.netology.domain; 2 | 3 | import org.junit.jupiter.api.Test; 4 | 5 | import java.util.Arrays; 6 | 7 | import static org.junit.jupiter.api.Assertions.*; 8 | 9 | class ProductsTest { 10 | private Product first = new Product(1, "First", 1_000, 3.5); 11 | private Product second = new Product(2, "Second", 2_000, 4.5); 12 | private Product third = new Product(3, "Third", 3_000, 5.0); 13 | 14 | @Test 15 | public void shouldSortById() { 16 | Product[] expected = new Product[]{first, second, third}; 17 | Product[] actual = new Product[]{third, first, second}; 18 | 19 | Arrays.sort(actual); 20 | 21 | assertArrayEquals(expected, actual); 22 | } 23 | } 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | -------------------------------------------------------------------------------- /4.3_collections/collections/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 4.0.0 6 | 7 | org.example 8 | collections 9 | 1.0-SNAPSHOT 10 | 11 | 12 | 11 13 | 11 14 | UTF-8 15 | 16 | 17 | 18 | 19 | org.projectlombok 20 | lombok 21 | 1.18.12 22 | provided 23 | 24 | 25 | org.junit.jupiter 26 | junit-jupiter 27 | 5.4.2 28 | test 29 | 30 | 31 | org.mockito 32 | mockito-junit-jupiter 33 | 3.3.3 34 | test 35 | 36 | 37 | 38 | 39 | 40 | 41 | org.apache.maven.plugins 42 | maven-surefire-plugin 43 | 2.22.2 44 | 45 | 46 | 47 | 48 | -------------------------------------------------------------------------------- /4.3_collections/collections/src/main/java/ru/netology/domain/Book.java: -------------------------------------------------------------------------------- 1 | package ru.netology.domain; 2 | 3 | import lombok.Data; 4 | import lombok.EqualsAndHashCode; 5 | import lombok.NoArgsConstructor; 6 | 7 | @NoArgsConstructor 8 | @Data 9 | @EqualsAndHashCode(callSuper = true) 10 | public class Book extends Product { 11 | private String author; 12 | private int pages; 13 | 14 | public Book(int id, String name, int price, double rating, String author, int pages) { 15 | super(id, name, price, rating); 16 | this.author = author; 17 | this.pages = pages; 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /4.3_collections/collections/src/main/java/ru/netology/domain/Product.java: -------------------------------------------------------------------------------- 1 | package ru.netology.domain; 2 | 3 | import lombok.AllArgsConstructor; 4 | import lombok.Data; 5 | import lombok.NoArgsConstructor; 6 | 7 | @NoArgsConstructor 8 | @AllArgsConstructor 9 | @Data 10 | public class Product implements Comparable { 11 | private int id; 12 | private String name; 13 | private int price; 14 | private double rating; 15 | 16 | @Override 17 | public int compareTo(Product o) { 18 | return id - o.id; 19 | } 20 | } 21 | 22 | 23 | -------------------------------------------------------------------------------- /4.3_collections/collections/src/main/java/ru/netology/generic/ParametrizedMethod.java: -------------------------------------------------------------------------------- 1 | package ru.netology.generic; 2 | 3 | public class ParametrizedMethod { 4 | public void method(T param) { } 5 | 6 | public static void staticMethod(T param) { } 7 | 8 | } 9 | 10 | 11 | 12 | -------------------------------------------------------------------------------- /4.3_collections/collections/src/main/java/ru/netology/generic/ParametrizedType.java: -------------------------------------------------------------------------------- 1 | package ru.netology.generic; 2 | 3 | public class ParametrizedType { 4 | } 5 | 6 | -------------------------------------------------------------------------------- /4.3_collections/collections/src/main/java/ru/netology/repository/ProductRepository.java: -------------------------------------------------------------------------------- 1 | package ru.netology.repository; 2 | 3 | import ru.netology.domain.Product; 4 | 5 | import java.util.ArrayList; 6 | import java.util.Collection; 7 | import java.util.List; 8 | 9 | // FIXME: ВАЖНО не оставляйте код в таком виде (закомментированном) в ваших ДЗ! 10 | // FIXME: мы так сделали ТОЛЬКО для удобства демонстрации 11 | 12 | // first version without wildcard 13 | //public class ProductRepository { 14 | // private Collection items = new ArrayList<>(); 15 | // 16 | // public Collection getAll() { 17 | // return items; 18 | // } 19 | // 20 | // public Product getById(int id) { 21 | // for (Product item : items) { 22 | // if (item.getId() == id) { 23 | // return item; 24 | // } 25 | // } 26 | // return null; 27 | // } 28 | // 29 | // public boolean add(Product item) { 30 | // return items.add(item); 31 | // } 32 | // 33 | // public boolean remove(Product item) { 34 | // return items.remove(item); 35 | // } 36 | // 37 | // public boolean addAll(Collection items) { 38 | // return this.items.addAll(items); 39 | // } 40 | // 41 | // public boolean removeAll(Collection items) { 42 | // return this.items.removeAll(items); 43 | // } 44 | //} 45 | 46 | // second version with wildcard 47 | //public class ProductRepository { 48 | // private Collection items = new ArrayList<>(); 49 | // 50 | // public Collection getAll() { 51 | // return items; 52 | // } 53 | // 54 | // public Product getById(int id) { 55 | // for (Product item : items) { 56 | // if (item.getId() == id) { 57 | // return item; 58 | // } 59 | // } 60 | // return null; 61 | // } 62 | // 63 | // public boolean add(Product item) { 64 | // return items.add(item); 65 | // } 66 | // 67 | // public boolean remove(Product item) { 68 | // return items.remove(item); 69 | // } 70 | // 71 | // public boolean addAll(Collection items) { 72 | // return this.items.addAll(items); 73 | // } 74 | // 75 | // public boolean removeAll(Collection items) { 76 | // return this.items.removeAll(items); 77 | // } 78 | //} 79 | 80 | // third version with List 81 | public class ProductRepository { 82 | private List items = new ArrayList<>(); 83 | 84 | public List getAll() { 85 | return items; 86 | } 87 | 88 | public Product getById(int id) { 89 | for (Product item : items) { 90 | if (item.getId() == id) { 91 | return item; 92 | } 93 | } 94 | return null; 95 | } 96 | 97 | public boolean add(Product item) { 98 | // 99 | return items.add(item); 100 | // 101 | } 102 | 103 | public boolean remove(Product item) { 104 | // 105 | return items.remove(item); 106 | // 107 | } 108 | 109 | public boolean addAll(Collection items) { 110 | return this.items.addAll(items); 111 | } 112 | 113 | public boolean removeAll(Collection items) { 114 | return this.items.removeAll(items); 115 | } 116 | } 117 | 118 | -------------------------------------------------------------------------------- /4.3_collections/collections/src/test/java/ru/netology/repository/CRUDRepositoryTest.java: -------------------------------------------------------------------------------- 1 | package ru.netology.repository; 2 | 3 | import org.junit.jupiter.api.Nested; 4 | 5 | public class CRUDRepositoryTest { 6 | @Nested 7 | public class Empty { 8 | } 9 | 10 | @Nested 11 | public class SingleItem { 12 | } 13 | 14 | @Nested 15 | public class MultipleItems { 16 | } 17 | } 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | -------------------------------------------------------------------------------- /4.3_collections/collections/src/test/java/ru/netology/repository/ProductRepositoryTest.java: -------------------------------------------------------------------------------- 1 | package ru.netology.repository; 2 | 3 | import org.junit.jupiter.api.Test; 4 | import ru.netology.domain.Book; 5 | import ru.netology.domain.Product; 6 | 7 | import java.util.ArrayList; 8 | import java.util.Arrays; 9 | import java.util.Collection; 10 | 11 | class ProductRepositoryTest { 12 | private ProductRepository repository = new ProductRepository(); 13 | 14 | @Test 15 | void shouldAddProduct() { 16 | repository.add(new Product()); 17 | } 18 | 19 | @Test 20 | void shouldAddMultipleProducts() { 21 | Collection products = new ArrayList<>(); 22 | products.add(new Product()); 23 | products.add(new Product()); 24 | 25 | repository.addAll(products); 26 | } 27 | 28 | @Test 29 | void shouldAddBook() { 30 | repository.add(new Book()); 31 | } 32 | 33 | @Test 34 | void shouldAddMultipleBooks() { 35 | Collection books = new ArrayList<>(); 36 | books.add(new Book()); 37 | books.add(new Book()); 38 | 39 | boolean removed = repository.addAll(books); 40 | } 41 | } 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | -------------------------------------------------------------------------------- /4.3_collections/collections/src/test/java/ru/netology/repository/ProductRepositoryTestWithListOf.java: -------------------------------------------------------------------------------- 1 | package ru.netology.repository; 2 | 3 | import org.junit.jupiter.api.Test; 4 | import ru.netology.domain.Book; 5 | import ru.netology.domain.Product; 6 | 7 | import java.util.ArrayList; 8 | import java.util.Collection; 9 | import java.util.List; 10 | 11 | class ProductRepositoryTestWithListOf { 12 | private ProductRepository repository = new ProductRepository(); 13 | 14 | @Test 15 | void shouldAddProduct() { 16 | repository.add(new Product()); 17 | } 18 | 19 | @Test 20 | void shouldAddMultipleProducts() { 21 | Collection products = new ArrayList<>(); 22 | products.add(new Product()); 23 | products.add(new Product()); 24 | repository.addAll(products); 25 | 26 | repository.addAll(List.of(new Product(), new Product())); 27 | } 28 | 29 | @Test 30 | void shouldAddBook() { 31 | repository.add(new Book()); 32 | } 33 | 34 | @Test 35 | void shouldAddMultipleBooks() { 36 | boolean removed = repository.addAll(List.of(new Product(), new Product())); 37 | } 38 | } 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Примеры кода по курсу «Java для тестировщиков» 2 | 3 | ## Блок 1. Введение в Java 4 | 5 | 1.1. [x] [Введение в Java: JDK, JRE, JVM, IntelliJ IDEA](1.1_intro) 6 | 7 | 1.2. [x] [Программирование на Java: переменные, операторы, работа с отладчиком](1.2_programming) 8 | 9 | ## Блок 2. Основы Java, Автотесты и CI 10 | 11 | 2.1. [x] [Примитивные типы данных, условные операторы, выход за границы типов и погрешность вычислений](2.1_data) 12 | 13 | 2.2. [x] [Testability, автотесты, введение в ООП: объекты и методы](2.2_methods) 14 | 15 | 2.3. [x] [Система сборки Maven, управление зависимостями, автотесты на JUnit5](2.3_maven-junit) 16 | 17 | 2.4. [x] [Циклы, параметризованные тесты и аннотации](2.4_params) 18 | 19 | 2.5. [x] [Выстраивание процесса непрерывной интеграции (CI): Github Actions. Покрытие кода с JaCoCo, статический анализ кода: CheckStyle, SpotBugs](2.5_ci) 20 | 21 | ## Блок 3. ООП 22 | 23 | 3.1. [x] [Объектно-ориентированное программирование и проектирование](3.1_oop1) 24 | 25 | 3.2. [x] [Объектно-ориентированное программирование: ключевые принципы](3.2_oop2) 26 | 27 | 3.3. [x] [Объекты с внутренним состоянием, управление состоянием при тестировании](3.3_state) 28 | 29 | 3.4. [x] [Композиция и зависимость объектов. Mockito при создании автотестов](3.4_dependency) 30 | 31 | 3.5. [x] [Наследование и расширяемость систем. Проблемы наследования](3.5_inheritance) 32 | 33 | ## Блок 4. Исключения, Интерфейсы, Generics и Collections Framework 34 | 35 | 4.1. [x] [Исключительные ситуации и их обработка. Тестирование исключений](4.1_exceptions) 36 | 37 | 4.2. [x] [Интерфейсы для организации малой связности. Обобщённое программирование (Generics)](4.2_interfaces) 38 | 39 | 4.3. [x] [Collections Framework. CRUD и тестирование систем, управляющих набором объектов](4.3_collections) 40 | --------------------------------------------------------------------------------