-
Notifications
You must be signed in to change notification settings - Fork 0
Feature/hw-01 #1
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
base: master
Are you sure you want to change the base?
Changes from all commits
441a587
b22839c
baef643
1afc67d
9d46552
c3266f7
91a1a80
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,4 +1,5 @@ | ||
| .idea | ||
| target | ||
| *.iml | ||
| *.log | ||
| *.log | ||
| *.txt |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,2 +1,20 @@ | ||
| # OtusSpringHW | ||
| Домашние задания по Spring для Otus. | ||
| # OtusSpringHW | ||
|
|
||
| Домашнее задание #1: | ||
|
|
||
| Программа по проведению тестирования студентов | ||
| В ресурсах хранятся вопросы и различные ответы к ним в виде CSV файла (5 вопрсов). Программа должна спросить у пользователя фамилию и имя, спросить 5 вопросов из CSV-файла и вывести результат тестирования. | ||
|
|
||
| Все сервисы в программе должны решать строго определённую задачу. Зависимости должны быть настроены в IoC контейнере. | ||
|
|
||
| Опционально: сервисы, по возможности, покрыть тестами. | ||
|
|
||
| ### 19-03-18 Доработки: | ||
| - Переименованы классы. | ||
| - Добавлено исключение QuestionsFileLoadingException. | ||
| - Работа с консолью вынесена в сервис ConsoleService. | ||
| - Тесты для QuestionsDAO. | ||
|
|
||
| ### 19-03-19 Доработки: | ||
| - Переименованы классы. | ||
| - Добавлены тесты. |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,100 @@ | ||
| <?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>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>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> | ||
| </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.21.0</version> | ||
| </plugin> | ||
| </plugins> | ||
|
|
||
| <resources> | ||
| <resource> | ||
| <directory>src/main/resources</directory> | ||
| <includes> | ||
| <include>**/*.properties</include> | ||
| <include>**/*.xml</include> | ||
| <include>**/*.csv</include> | ||
| </includes> | ||
| <filtering>false</filtering> | ||
| </resource> | ||
| </resources> | ||
| </build> | ||
| </project> |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,27 @@ | ||
| package ru.otus.mkulikov; | ||
|
|
||
| import org.springframework.context.support.ClassPathXmlApplicationContext; | ||
| import ru.otus.mkulikov.exceptions.QuestionsFileLoadingException; | ||
| import ru.otus.mkulikov.processor.ProcessorService; | ||
|
|
||
| /** | ||
| * Created by IntelliJ IDEA. | ||
| * Developer: Maksim Kulikov | ||
| * Date: 2019-03-14 | ||
| * Time: 15:27 | ||
| */ | ||
|
|
||
| public class Main { | ||
|
|
||
| public static void main(String[] args) { | ||
| ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext("applicationContext.xml"); | ||
| try { | ||
| ProcessorService processor = context.getBean(ProcessorService.class); | ||
| processor.startTest(); | ||
| } catch (QuestionsFileLoadingException e) { | ||
| e.printStackTrace(); | ||
| } finally { | ||
| context.close(); | ||
| } | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,15 @@ | ||
| package ru.otus.mkulikov.console; | ||
|
|
||
| /** | ||
| * Created by IntelliJ IDEA. | ||
| * Developer: Maksim Kulikov | ||
| * Date: 17.03.2019 | ||
| * Time: 23:21 | ||
| */ | ||
|
|
||
| public interface ConsoleService { | ||
|
|
||
| void write(String text); | ||
|
|
||
| String read(); | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,35 @@ | ||
| package ru.otus.mkulikov.console; | ||
|
|
||
| import javax.annotation.PreDestroy; | ||
| import java.util.Scanner; | ||
|
|
||
| /** | ||
| * Created by IntelliJ IDEA. | ||
| * Developer: Maksim Kulikov | ||
| * Date: 17.03.2019 | ||
| * Time: 23:21 | ||
| */ | ||
|
|
||
| public class ConsoleServiceImpl implements ConsoleService { | ||
|
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. А тут соответственно ConsoleIOServiceImpl |
||
|
|
||
| private Scanner in; | ||
|
|
||
| public ConsoleServiceImpl() { | ||
| 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(); | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,16 @@ | ||
| package ru.otus.mkulikov.constants; | ||
|
|
||
| /** | ||
| * Created by IntelliJ IDEA. | ||
| * Developer: Maksim Kulikov | ||
| * Date: 2019-03-18 | ||
| * Time: 13:07 | ||
| */ | ||
|
|
||
| public class StringConstants { | ||
|
|
||
| public static final String c_error_load_consoleService = "Ошибка загрузки ConsoleService!"; | ||
| public static final String c_error_load_questionsDAO = "Ошибка загрузки QuestionsDAO!"; | ||
| public static final String c_error_load_questionsService = "Ошибка загрузки QuestionsService!"; | ||
| public static final String c_error_load_registrationService = "Ошибка загрузки RegistrationService!"; | ||
| } |
| 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 Exception { | ||
|
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. Лучше наследоваться от RuntimeException. |
||
|
|
||
| public QuestionsFileLoadingException(String message) { | ||
| super(message); | ||
| } | ||
|
|
||
| public QuestionsFileLoadingException(String message, Throwable cause) { | ||
| super(message, cause); | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,99 @@ | ||
| package ru.otus.mkulikov.model; | ||
|
|
||
| import java.io.Serializable; | ||
|
|
||
| /** | ||
| * Created by IntelliJ IDEA. | ||
| * Developer: Maksim Kulikov | ||
| * Date: 2019-03-14 | ||
| * Time: 15:54 | ||
| */ | ||
|
|
||
| public class Question implements Serializable { | ||
|
|
||
| private String id; | ||
| private String question; | ||
| private String answer1; | ||
| private String answer2; | ||
| private String answer3; | ||
| private String answer4; | ||
| private String trueAnswer; | ||
| private String userAnswer; | ||
|
|
||
| public String getId() { | ||
| return id; | ||
| } | ||
|
|
||
| public void setId(String id) { | ||
| this.id = id; | ||
| } | ||
|
|
||
| public String getQuestion() { | ||
| return question; | ||
| } | ||
|
|
||
| public void setQuestion(String question) { | ||
|
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. Советую попробовать библиотеку lombok |
||
| this.question = question; | ||
| } | ||
|
|
||
| public String getAnswer1() { | ||
| return answer1; | ||
| } | ||
|
|
||
| public void setAnswer1(String answer1) { | ||
| this.answer1 = answer1; | ||
| } | ||
|
|
||
| public String getAnswer2() { | ||
| return answer2; | ||
| } | ||
|
|
||
| public void setAnswer2(String answer2) { | ||
| this.answer2 = answer2; | ||
| } | ||
|
|
||
| public String getAnswer3() { | ||
| return answer3; | ||
| } | ||
|
|
||
| public void setAnswer3(String answer3) { | ||
| this.answer3 = answer3; | ||
| } | ||
|
|
||
| public String getAnswer4() { | ||
| return answer4; | ||
| } | ||
|
|
||
| public void setAnswer4(String answer4) { | ||
| this.answer4 = answer4; | ||
| } | ||
|
|
||
| public String getTrueAnswer() { | ||
| return trueAnswer; | ||
| } | ||
|
|
||
| public void setTrueAnswer(String trueAnswer) { | ||
| this.trueAnswer = trueAnswer; | ||
| } | ||
|
|
||
| public String getUserAnswer() { | ||
| return userAnswer; | ||
| } | ||
|
|
||
| public void setUserAnswer(String userAnswer) { | ||
| this.userAnswer = userAnswer; | ||
| } | ||
|
|
||
| @Override | ||
| public String toString() { | ||
| return "Question {" + | ||
| "id='" + id + '\'' + | ||
| ", question='" + question + '\'' + | ||
| ", answer1='" + answer1 + '\'' + | ||
| ", answer2='" + answer2 + '\'' + | ||
| ", answer3='" + answer3 + '\'' + | ||
| ", answer4='" + answer4 + '\'' + | ||
| ", trueAnswer='" + trueAnswer + '\'' + | ||
| '}'; | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,35 @@ | ||
| package ru.otus.mkulikov.model; | ||
|
|
||
| /** | ||
| * Created by IntelliJ IDEA. | ||
| * Developer: Maksim Kulikov | ||
| * Date: 2019-03-14 | ||
| * Time: 15:29 | ||
| */ | ||
|
|
||
| public class User { | ||
|
|
||
| private final String name; | ||
| private final String surname; | ||
|
|
||
| public User(String name, String surname) { | ||
| this.name = name; | ||
| this.surname = surname; | ||
| } | ||
|
|
||
| public String getName() { | ||
| return name; | ||
| } | ||
|
|
||
| public String getSurname() { | ||
| return surname; | ||
| } | ||
|
|
||
| @Override | ||
| public String toString() { | ||
| return "User {" + | ||
| "name='" + name + '\'' + | ||
| ", surname='" + surname + '\'' + | ||
| '}'; | ||
| } | ||
| } |
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.
Лучше IOService. Мы же можем написать разные реализации в т.ч. не консольные