diff --git a/src/main/java/org/sadtech/autoresponder/Autoresponder.java b/src/main/java/org/sadtech/autoresponder/Autoresponder.java index d895efe..d30ea01 100644 --- a/src/main/java/org/sadtech/autoresponder/Autoresponder.java +++ b/src/main/java/org/sadtech/autoresponder/Autoresponder.java @@ -17,7 +17,7 @@ public class Autoresponder { private PersonService personService; public String answer(@NotNull Integer idPerson, @NotNull String message) { - Person person = addPerson(idPerson); + Person person = CheckAndAddPerson(idPerson); Unit unit; if (person.getUnit() == null) { unit = unitService.nextUnit(unitService.menuUnit(), message); @@ -29,15 +29,14 @@ public class Autoresponder { } public String answer(@NotNull Integer idPerson, @NotNull String message, @NotNull List words) { - Person person = addPerson(idPerson); - Unit unit = unitService.nextUnit(person.getUnit(), message); + String answer = answer(idPerson, message); InsertWords insertWords = new InsertWords(); - insertWords.setInText(unit.getAnswer()); + insertWords.setInText(answer); insertWords.insert(words); return insertWords.getOutText(); } - private Person addPerson(Integer idPerson) { + private Person CheckAndAddPerson(Integer idPerson) { Person person; if (personService.checkPerson(idPerson)) { person = personService.getPersonById(idPerson); diff --git a/src/test/java/org/sadtech/autoresponder/AutoresponderTest.java b/src/test/java/org/sadtech/autoresponder/AutoresponderTest.java index 63c2ad4..81ec996 100644 --- a/src/test/java/org/sadtech/autoresponder/AutoresponderTest.java +++ b/src/test/java/org/sadtech/autoresponder/AutoresponderTest.java @@ -85,6 +85,7 @@ public class AutoresponderTest { @Test public void NoAnswer() { + person.setUnit(null); String test = autoresponder.answer(person.getId(), "Привет это срабатывания"); Assert.assertNull(test); } @@ -125,6 +126,5 @@ public class AutoresponderTest { public void answerNoPerson() { Assert.assertEquals(autoresponder.answer(100, "Привет это тест срабатывания"), "Здравствуйте, вы написали в нашу компанию!"); Assert.assertEquals(autoresponder.answer(100, "Привет это тест срабатывания"), "Ответ с {0} параметрами!"); - } } \ No newline at end of file