-
Notifications
You must be signed in to change notification settings - Fork 0
Feature/hw-02 #2
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
uoles
wants to merge
17
commits into
master
Choose a base branch
from
feature/hw-02
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
17 commits
Select commit
Hold shift + click to select a range
441a587
Add files commit.
uoles b22839c
Edit readme.
uoles baef643
Edit readme.
uoles 1afc67d
Edit readme.
uoles 9d46552
- Переименование классов.
uoles c3266f7
- Переименованы классы.
f02aaa1
- XML конфигурация spring заменена на Java-based.
0c00541
Java-based конфигурация spring заменена на Annotation-based.
5836fb1
Загрузка имени файла с вопросами из конфигурационного файла.
uoles da86894
- Рефакторинг.
c27da6c
- Локализация для вопросов и сообщений.
e37b4a6
Merge branch 'master' into feature/hw-02
uoles d1ca11a
- Убраны лишние тесты.
uoles 00bc9bd
Рефакторинг.
uoles f6c34d2
Merge branch 'master' into feature/hw-02
uoles e2ba5e0
Добавление файлов настроек для тестов.
998fed3
Рефакторинг.
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,2 +1,12 @@ | ||
| # OtusSpringHW | ||
| Домашние задания по Spring для Otus. | ||
| # OtusSpringHW | ||
|
|
||
| Домашнее задание #2: | ||
| - Добавить файл настроек в приложение и для тестирования. | ||
| - Локализовать выводимые сообщения и вопросы теста. | ||
| - Переписать конфигурацию в виде Java + Annotation-based конфигурации. | ||
|
|
||
| ### 19-03-22 Доработки: | ||
| - Убраны лишние тесты. | ||
| - Изменена работа с файлом. | ||
| - Использование @Data вместо @Getter, @Setter. | ||
| - Добавлены *.properties для тестов. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,138 @@ | ||
| <?xml version="1.0" encoding="UTF-8"?> | ||
| <project xmlns="http://maven.apache.org/POM/4.0.0" | ||
| xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
| xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> | ||
| <modelVersion>4.0.0</modelVersion> | ||
|
|
||
| <name>home-work-01</name> | ||
|
|
||
| <groupId>ru.otus.mkulikov</groupId> | ||
| <artifactId>home-work</artifactId> | ||
| <version>1.0-SNAPSHOT</version> | ||
|
|
||
| <properties> | ||
| <java.version>11</java.version> | ||
| <maven.compiler.source>${java.version}</maven.compiler.source> | ||
| <maven.compiler.target>${java.version}</maven.compiler.target> | ||
| <encoding>UTF-8</encoding> | ||
| </properties> | ||
|
|
||
| <dependencies> | ||
| <dependency> | ||
| <groupId>org.springframework</groupId> | ||
| <artifactId>spring-context</artifactId> | ||
| <version>5.0.9.RELEASE</version> | ||
| </dependency> | ||
|
|
||
| <dependency> | ||
| <groupId>org.springframework</groupId> | ||
| <artifactId>spring-test</artifactId> | ||
| <version>5.0.9.RELEASE</version> | ||
| </dependency> | ||
|
|
||
| <dependency> | ||
| <groupId>net.sf.opencsv</groupId> | ||
| <artifactId>opencsv</artifactId> | ||
| <version>2.3</version> | ||
| </dependency> | ||
|
|
||
| <dependency> | ||
| <groupId>javax.annotation</groupId> | ||
| <artifactId>javax.annotation-api</artifactId> | ||
| <version>1.3.2</version> | ||
| </dependency> | ||
|
|
||
| <dependency> | ||
| <groupId>junit</groupId> | ||
| <artifactId>junit</artifactId> | ||
| <version>4.12</version> | ||
| <scope>test</scope> | ||
| </dependency> | ||
|
|
||
| <dependency> | ||
| <groupId>org.junit.jupiter</groupId> | ||
| <artifactId>junit-jupiter-api</artifactId> | ||
| <version>5.4.0</version> | ||
| <scope>test</scope> | ||
| </dependency> | ||
|
|
||
| <dependency> | ||
| <groupId>org.junit.jupiter</groupId> | ||
| <artifactId>junit-jupiter-engine</artifactId> | ||
| <version>5.4.0</version> | ||
| <scope>test</scope> | ||
| </dependency> | ||
|
|
||
| <dependency> | ||
| <groupId>org.assertj</groupId> | ||
| <artifactId>assertj-core</artifactId> | ||
| <version>3.11.1</version> | ||
| <scope>test</scope> | ||
| </dependency> | ||
|
|
||
| <dependency> | ||
| <groupId>org.junit.platform</groupId> | ||
| <artifactId>junit-platform-launcher</artifactId> | ||
| <version>1.4.1</version> | ||
| <scope>test</scope> | ||
| </dependency> | ||
|
|
||
| <dependency> | ||
| <groupId>org.projectlombok</groupId> | ||
| <artifactId>lombok</artifactId> | ||
| <version>1.18.4</version> | ||
| <scope>provided</scope> | ||
| </dependency> | ||
|
|
||
| <!-- https://mvnrepository.com/artifact/org.mockito/mockito-all --> | ||
| <dependency> | ||
| <groupId>org.mockito</groupId> | ||
| <artifactId>mockito-all</artifactId> | ||
| <version>1.10.19</version> | ||
| <scope>test</scope> | ||
| </dependency> | ||
| </dependencies> | ||
|
|
||
| <build> | ||
| <plugins> | ||
| <plugin> | ||
| <groupId>org.apache.maven.plugins</groupId> | ||
| <artifactId>maven-compiler-plugin</artifactId> | ||
| <configuration> | ||
| <source>${java.version}</source> | ||
| <target>${java.version}</target> | ||
| <encoding>${encoding}</encoding> | ||
| </configuration> | ||
| </plugin> | ||
|
|
||
| <plugin> | ||
| <groupId>org.apache.maven.plugins</groupId> | ||
| <artifactId>maven-resources-plugin</artifactId> | ||
| <configuration> | ||
| <encoding>${encoding}</encoding> | ||
| </configuration> | ||
| </plugin> | ||
|
|
||
| <plugin> | ||
| <groupId>org.apache.maven.plugins</groupId> | ||
| <artifactId>maven-surefire-plugin</artifactId> | ||
| <version>2.22.0</version> | ||
|
|
||
| <configuration> | ||
| <skipTests>false</skipTests> | ||
| </configuration> | ||
| </plugin> | ||
| </plugins> | ||
|
|
||
| <resources> | ||
| <resource> | ||
| <directory>src/main/resources</directory> | ||
| <includes> | ||
| <include>**/*.csv</include> | ||
| <include>**/*.properties</include> | ||
| </includes> | ||
| <filtering>false</filtering> | ||
| </resource> | ||
| </resources> | ||
| </build> | ||
| </project> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,33 @@ | ||
| package ru.otus.mkulikov; | ||
|
|
||
| import org.springframework.context.annotation.AnnotationConfigApplicationContext; | ||
| import org.springframework.context.annotation.ComponentScan; | ||
| import org.springframework.context.annotation.Configuration; | ||
| import org.springframework.context.annotation.PropertySource; | ||
| import ru.otus.mkulikov.exceptions.QuestionsFileLoadingException; | ||
| import ru.otus.mkulikov.services.processor.ProcessorService; | ||
|
|
||
| /** | ||
| * Created by IntelliJ IDEA. | ||
| * Developer: Maksim Kulikov | ||
| * Date: 2019-03-14 | ||
| * Time: 15:27 | ||
| */ | ||
|
|
||
| @Configuration | ||
| @ComponentScan | ||
| @PropertySource("classpath:application.properties") | ||
| public class Application { | ||
|
|
||
| public static void main(String[] args) { | ||
| AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(Application.class); | ||
| try { | ||
| ProcessorService processor = context.getBean(ProcessorService.class); | ||
| processor.startTest(); | ||
| } catch (QuestionsFileLoadingException e) { | ||
| e.printStackTrace(); | ||
| } finally { | ||
| context.close(); | ||
| } | ||
| } | ||
| } |
19 changes: 19 additions & 0 deletions
19
src/main/java/ru/otus/mkulikov/exceptions/QuestionsFileLoadingException.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,19 @@ | ||
| package ru.otus.mkulikov.exceptions; | ||
|
|
||
| /** | ||
| * Created by IntelliJ IDEA. | ||
| * Developer: Maksim Kulikov | ||
| * Date: 2019-03-17 | ||
| * Time: 01:40 | ||
| */ | ||
|
|
||
| public class QuestionsFileLoadingException extends RuntimeException { | ||
|
|
||
| public QuestionsFileLoadingException(String message) { | ||
| super(message); | ||
| } | ||
|
|
||
| public QuestionsFileLoadingException(String message, Throwable cause) { | ||
| super(message, cause); | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,39 @@ | ||
| package ru.otus.mkulikov.models; | ||
|
|
||
| import lombok.Data; | ||
|
|
||
| import java.io.Serializable; | ||
|
|
||
| /** | ||
| * Created by IntelliJ IDEA. | ||
| * Developer: Maksim Kulikov | ||
| * Date: 2019-03-14 | ||
| * Time: 15:54 | ||
| */ | ||
|
|
||
| @Data | ||
| public class Question implements Serializable { | ||
|
|
||
| private String id; | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Есть |
||
| private String question; | ||
| private String answer1; | ||
| private String answer2; | ||
| private String answer3; | ||
| private String answer4; | ||
| private String trueAnswer; | ||
| private String userAnswer; | ||
|
|
||
| public Question(String id, String question, String answer1, String answer2, String answer3, String answer4, String trueAnswer, String userAnswer) { | ||
| this.id = id; | ||
| this.question = question; | ||
| this.answer1 = answer1; | ||
| this.answer2 = answer2; | ||
| this.answer3 = answer3; | ||
| this.answer4 = answer4; | ||
| this.trueAnswer = trueAnswer; | ||
| this.userAnswer = userAnswer; | ||
| } | ||
|
|
||
| public Question() { | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,22 @@ | ||
| package ru.otus.mkulikov.models; | ||
|
|
||
| import lombok.Data; | ||
|
|
||
| /** | ||
| * Created by IntelliJ IDEA. | ||
| * Developer: Maksim Kulikov | ||
| * Date: 2019-03-14 | ||
| * Time: 15:29 | ||
| */ | ||
|
|
||
| @Data | ||
| public class User { | ||
|
|
||
| private final String name; | ||
| private final String surname; | ||
|
|
||
| public User(String name, String surname) { | ||
| this.name = name; | ||
| this.surname = surname; | ||
| } | ||
| } |
38 changes: 38 additions & 0 deletions
38
src/main/java/ru/otus/mkulikov/services/console/ConsoleIOServiceImpl.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,38 @@ | ||
| package ru.otus.mkulikov.services.console; | ||
|
|
||
| import org.springframework.stereotype.Service; | ||
|
|
||
| import javax.annotation.PreDestroy; | ||
| import java.util.Scanner; | ||
|
|
||
| /** | ||
| * Created by IntelliJ IDEA. | ||
| * Developer: Maksim Kulikov | ||
| * Date: 17.03.2019 | ||
| * Time: 23:21 | ||
| */ | ||
|
|
||
| @Service | ||
| public class ConsoleIOServiceImpl implements IOService { | ||
|
|
||
| private final Scanner in; | ||
|
|
||
| public ConsoleIOServiceImpl() { | ||
| in = new Scanner(System.in); | ||
| } | ||
|
|
||
| @Override | ||
| public void write(String text) { | ||
| System.out.println(text); | ||
| } | ||
|
|
||
| @Override | ||
| public String read() { | ||
| return in.nextLine(); | ||
| } | ||
|
|
||
| @PreDestroy | ||
| public void destroy() { | ||
| in.close(); | ||
| } | ||
| } |
15 changes: 15 additions & 0 deletions
15
src/main/java/ru/otus/mkulikov/services/console/IOService.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,15 @@ | ||
| package ru.otus.mkulikov.services.console; | ||
|
|
||
| /** | ||
| * Created by IntelliJ IDEA. | ||
| * Developer: Maksim Kulikov | ||
| * Date: 17.03.2019 | ||
| * Time: 23:21 | ||
| */ | ||
|
|
||
| public interface IOService { | ||
|
|
||
| void write(String text); | ||
|
|
||
| String read(); | ||
| } |
15 changes: 15 additions & 0 deletions
15
src/main/java/ru/otus/mkulikov/services/localisation/LocalisationService.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,15 @@ | ||
| package ru.otus.mkulikov.services.localisation; | ||
|
|
||
| /** | ||
| * Created by IntelliJ IDEA. | ||
| * Developer: Maksim Kulikov | ||
| * Date: 2019-03-21 | ||
| * Time: 14:02 | ||
| */ | ||
|
|
||
| public interface LocalisationService { | ||
|
|
||
| String getValue(String key); | ||
|
|
||
| String getValueWithParams(String key, String[] params); | ||
| } |
43 changes: 43 additions & 0 deletions
43
src/main/java/ru/otus/mkulikov/services/localisation/LocalisationServiceImpl.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,43 @@ | ||
| package ru.otus.mkulikov.services.localisation; | ||
|
|
||
| import org.springframework.beans.factory.annotation.Value; | ||
| import org.springframework.context.support.ReloadableResourceBundleMessageSource; | ||
| import org.springframework.stereotype.Service; | ||
|
|
||
| import java.util.Locale; | ||
|
|
||
| /** | ||
| * Created by IntelliJ IDEA. | ||
| * Developer: Maksim Kulikov | ||
| * Date: 2019-03-21 | ||
| * Time: 14:02 | ||
| */ | ||
|
|
||
| @Service | ||
| public class LocalisationServiceImpl extends ReloadableResourceBundleMessageSource implements LocalisationService { | ||
|
|
||
| private final Locale locale; | ||
| private final Locale russian = new Locale("ru"); | ||
|
|
||
| public LocalisationServiceImpl( | ||
| @Value("${locale.basename}") String basename, | ||
| @Value("${locale.default.encoding}") String defaultEncoding, | ||
| @Value("${locale.default}") String localeDefault | ||
| ) { | ||
| super(); | ||
| setBasename(basename); | ||
| setDefaultEncoding(defaultEncoding); | ||
|
|
||
| locale = (localeDefault != null) | ||
| ? new Locale(localeDefault) | ||
| : russian; | ||
| } | ||
|
|
||
| public String getValue(String key) { | ||
| return getMessage(key, null, locale); | ||
| } | ||
|
|
||
| public String getValueWithParams(String key, String[] params) { | ||
| return getMessage(key, params, locale); | ||
| } | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Отлично