Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
.idea
target
*.iml
*.log
*.log
*.txt
22 changes: 20 additions & 2 deletions README.md
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 Доработки:
- Переименованы классы.
- Добавлены тесты.
100 changes: 100 additions & 0 deletions pom.xml
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>
27 changes: 27 additions & 0 deletions src/main/java/ru/otus/mkulikov/Main.java
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();
}
}
}
15 changes: 15 additions & 0 deletions src/main/java/ru/otus/mkulikov/console/ConsoleService.java
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 {

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Лучше IOService. Мы же можем написать разные реализации в т.ч. не консольные


void write(String text);

String read();
}
35 changes: 35 additions & 0 deletions src/main/java/ru/otus/mkulikov/console/ConsoleServiceImpl.java
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 {

Copy link
Copy Markdown

Choose a reason for hiding this comment

The 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();
}
}
16 changes: 16 additions & 0 deletions src/main/java/ru/otus/mkulikov/constants/StringConstants.java
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 {

Copy link
Copy Markdown

Choose a reason for hiding this comment

The 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);
}
}
99 changes: 99 additions & 0 deletions src/main/java/ru/otus/mkulikov/model/Question.java
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) {

Copy link
Copy Markdown

Choose a reason for hiding this comment

The 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 + '\'' +
'}';
}
}
35 changes: 35 additions & 0 deletions src/main/java/ru/otus/mkulikov/model/User.java
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 + '\'' +
'}';
}
}
Loading