Skip to content

Feature/hw-01#1

Open
uoles wants to merge 7 commits intomasterfrom
feature/hw-01
Open

Feature/hw-01#1
uoles wants to merge 7 commits intomasterfrom
feature/hw-01

Conversation

@uoles
Copy link
Copy Markdown
Owner

@uoles uoles commented Mar 19, 2019

  • Переименованы классы.
  • Добавлено исключение QuestionsFileLoadingException.
  • Работа с консолью вынесена в сервис ConsoleService.
  • Добавлены тесты.

uoles and others added 7 commits March 16, 2019 10:11
- Добавление исключения QuestionsFileLoadingException.
- Работа с консолью вынесена в сервис ConsoleService.
- Тесты для QuestionsDAO.
- Добавлены тесты.
* 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. Мы же можем написать разные реализации в т.ч. не консольные

* 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

* 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.

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


public interface ProcessorService {

void startTest() throws QuestionsFileLoadingException;
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. Не придется тут его указывать

if (questionsService == null) {
throw new QuestionsFileLoadingException(c_error_load_questionsService);
}
return questionsService;
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Тут не понял. Во первых зачем вообще нужны геттеры для сервисов? Во вторых достаточно того, что мы их внедрили через конструктор. Не нужно создавать бины руками. Это нарушает принципы IOC. Таких мест в коде несколько


public interface QuestionsDAO {

List<Question> getQuestions(String csvFilename) throws QuestionsFileLoadingException;
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Имя файла лучше не упоминать в интерфейсе. Его можно передать в конструктор реализации, а тут сделать просто getQuestions(). Тогда этот интерфейс подойдет ко множеству реализаций

*/

@DisplayName("Класс исключения QuestionsFileLoadingException")
class QuestionsFileLoadingExceptionTest {
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Это конечно перебор

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants