diff --git a/.idea/misc.xml b/.idea/misc.xml index 779255b..ea71d50 100644 --- a/.idea/misc.xml +++ b/.idea/misc.xml @@ -1,6 +1,6 @@ - + \ No newline at end of file diff --git a/resources/task.csv b/resources/task.csv index 6958abc..ffa2af2 100644 --- a/resources/task.csv +++ b/resources/task.csv @@ -1,6 +1,2 @@ id,type,name,status,description,epic -1,TASK,Дом,NEW,Убраться в кухни и ванной, -2,TASK,Работа,IN_PROGRESS,Сделать куча рутины и пойти домой:), -3,EPIC,Прогулка,NEW,Прежде чем погулять нужно:, -4,EPIC,Приготовить кофе,NEW,Пойти на кухню и:, diff --git a/src/ru/yandex/javacource/golotin/schedule/Main.java b/src/ru/yandex/javacource/golotin/schedule/Main.java index 8e49743..e41ca36 100644 --- a/src/ru/yandex/javacource/golotin/schedule/Main.java +++ b/src/ru/yandex/javacource/golotin/schedule/Main.java @@ -11,21 +11,21 @@ public class Main { public static void main(String[] args) { TaskManager taskManager = Manager.getDefault(); - taskManager.createTask(new Task("Дом", Status.NEW, "Убраться в кухни и ванной")); - taskManager.createTask(new Task("Работа", Status.IN_PROGRESS, "Сделать куча рутины и пойти домой:)")); - - taskManager.createEpic(new Epic("Прогулка", Status.NEW, "Прежде чем погулять нужно:")); - taskManager.createSubtask(new Subtask("Уборка", Status.NEW, "Убраться в квартире", 1)); - taskManager.createSubtask(new Subtask("Одежда", Status.NEW, "Подготовить одежду к прогулке", 1)); - - taskManager.createEpic(new Epic("Приготовить кофе", Status.NEW, "Пойти на кухню и:")); - taskManager.createSubtask(new Subtask("Сделать кофе", Status.NEW, "Налить в кружку горячую воду и наспать кофе", 2)); - - taskManager.updateTask(new Task("Дом", Status.IN_PROGRESS, "Уборка в кухни и ванной")); - - taskManager.updateEpic(new Epic("Прогулка", Status.NEW, "Не пойду гулять")); - taskManager.updateSubtask(new Subtask("Уборка", Status.IN_PROGRESS, "Убираюсь)", 1)); - taskManager.updateSubtask(new Subtask("Сделать кофе", Status.DONE, "Кофе приготовлено", 1)); +// taskManager.createTask(new Task("Дом", Status.NEW, "Убраться в кухни и ванной")); +// taskManager.createTask(new Task("Работа", Status.IN_PROGRESS, "Сделать куча рутины и пойти домой:)")); +// +// taskManager.createEpic(new Epic("Прогулка", Status.NEW, "Прежде чем погулять нужно:")); +// taskManager.createSubtask(new Subtask("Уборка", Status.NEW, "Убраться в квартире", 1)); +// taskManager.createSubtask(new Subtask("Одежда", Status.NEW, "Подготовить одежду к прогулке", 1)); +// +// taskManager.createEpic(new Epic("Приготовить кофе", Status.NEW, "Пойти на кухню и:")); +// taskManager.createSubtask(new Subtask("Сделать кофе", Status.NEW, "Налить в кружку горячую воду и наспать кофе", 2)); +// +// taskManager.updateTask(new Task("Дом", Status.IN_PROGRESS, "Уборка в кухни и ванной")); +// +// taskManager.updateEpic(new Epic("Прогулка", Status.NEW, "Не пойду гулять")); +// taskManager.updateSubtask(new Subtask("Уборка", Status.IN_PROGRESS, "Убираюсь)", 1)); +// taskManager.updateSubtask(new Subtask("Сделать кофе", Status.DONE, "Кофе приготовлено", 1)); System.out.println(taskManager.getTasks()); diff --git a/src/ru/yandex/javacource/golotin/schedule/model/Epic.java b/src/ru/yandex/javacource/golotin/schedule/model/Epic.java index 7176116..2b39ffb 100644 --- a/src/ru/yandex/javacource/golotin/schedule/model/Epic.java +++ b/src/ru/yandex/javacource/golotin/schedule/model/Epic.java @@ -1,18 +1,22 @@ package ru.yandex.javacource.golotin.schedule.model; +import java.time.Duration; +import java.time.Instant; +import java.time.LocalDateTime; import java.util.ArrayList; import java.util.List; public class Epic extends Task { private final List subtaskIds = new ArrayList<>(); + private LocalDateTime endTime; - public Epic(String name, Status status, String description) { - super(name, status, description); + public Epic(String name, Status status, String description, LocalDateTime startTime, long duration) { + super(name, status, description, startTime, duration); } - public Epic(int id, String name, String description, Status status) { - super(name, status, description); + public Epic(int id, String name, String description, Status status, LocalDateTime startTime, long duration) { + super(name, status, description, startTime, duration); setId(id); } @@ -36,11 +40,15 @@ public TaskType getType() { return TaskType.EPIC; } + public void setEndTime(LocalDateTime endTime) { + this.endTime = endTime; + } + @Override public String toString() { return "Epic{" + "subtaskIds=" + subtaskIds + + ", endTime=" + endTime + '}'; } - } diff --git a/src/ru/yandex/javacource/golotin/schedule/model/Subtask.java b/src/ru/yandex/javacource/golotin/schedule/model/Subtask.java index 53ed50c..513acc7 100644 --- a/src/ru/yandex/javacource/golotin/schedule/model/Subtask.java +++ b/src/ru/yandex/javacource/golotin/schedule/model/Subtask.java @@ -1,17 +1,20 @@ package ru.yandex.javacource.golotin.schedule.model; +import java.time.Instant; +import java.time.LocalDateTime; + public class Subtask extends Task { private Integer epicId; - public Subtask(String name, Status status, String description, int epicId) { + public Subtask(String name, Status status, String description, LocalDateTime startTime, long duration, int epicId) { - super(name, status, description); + super(name, status, description, startTime, duration); setEpicId(epicId); } - public Subtask(int id, String name, String description, Status status, Integer epicId) { - super(name, status, description); + public Subtask(int id, String name, String description, Status status, LocalDateTime startTime, long duration, Integer epicId) { + super(name, status, description, startTime, duration); setId(id); setEpicId(epicId); } diff --git a/src/ru/yandex/javacource/golotin/schedule/model/Task.java b/src/ru/yandex/javacource/golotin/schedule/model/Task.java index adf1482..98dcb12 100644 --- a/src/ru/yandex/javacource/golotin/schedule/model/Task.java +++ b/src/ru/yandex/javacource/golotin/schedule/model/Task.java @@ -1,6 +1,9 @@ package ru.yandex.javacource.golotin.schedule.model; +import java.time.Duration; +import java.time.LocalDateTime; import java.util.Objects; +import java.time.Instant; public class Task { private int id; @@ -8,17 +11,24 @@ public class Task { private String description; private Status status; - public Task(String name, Status status, String description) { + private LocalDateTime startTime; // LocalDateTime + private Duration duration; // минуты или Duration + + public Task(String name, Status status, String description, LocalDateTime startTime, long duration) { this.name = name; this.status = status; this.description = description; + this.startTime = LocalDateTime.from(startTime); + this.duration = Duration.ofMinutes(duration); } - public Task(int id, String name, String description, Status status) { + public Task(int id, String name, String description, Status status, LocalDateTime startTime, long duration) { setId(id); this.name = name; this.status = status; this.description = description; + this.startTime = startTime; + this.duration = Duration.ofMinutes(duration); } public int getId() { @@ -61,19 +71,27 @@ public void setStatus(Status status) { this.status = status; } - @Override - public boolean equals(Object o) { - if (this == o) return true; - if (o == null || getClass() != o.getClass()) return false; - Task task = (Task) o; - return id == task.id; + public LocalDateTime getStartTime() { + return startTime; } - @Override - public int hashCode() { - return Objects.hash(id); + public void setStartTime(LocalDateTime startTime) { + this.startTime = startTime; + } + + public long getDuration() { + return duration.toMinutesPart(); + } + + public void setDuration(long duration) { + this.duration = Duration.ofMinutes(duration); + } + + public LocalDateTime getEndTime() { + return startTime.plus(duration); } + @Override public String toString() { return "Task{" + @@ -81,6 +99,21 @@ public String toString() { ", name='" + name + '\'' + ", description='" + description + '\'' + ", status=" + status + + ", startTime=" + startTime + + ", endTime=" + getEndTime() + '}'; } + + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (o == null || getClass() != o.getClass()) return false; + Task task = (Task) o; + return id == task.id && Objects.equals(name, task.name) && Objects.equals(description, task.description) && status == task.status && Objects.equals(startTime, task.startTime) && Objects.equals(duration, task.duration); + } + + @Override + public int hashCode() { + return Objects.hash(id, name, description, status, startTime, duration); + } } diff --git a/src/ru/yandex/javacource/golotin/schedule/service/FileBackedTaskManager.java b/src/ru/yandex/javacource/golotin/schedule/service/FileBackedTaskManager.java index c162686..6d5813a 100644 --- a/src/ru/yandex/javacource/golotin/schedule/service/FileBackedTaskManager.java +++ b/src/ru/yandex/javacource/golotin/schedule/service/FileBackedTaskManager.java @@ -6,6 +6,9 @@ import java.nio.file.Files; +import java.time.Duration; +import java.time.Instant; +import java.time.LocalDateTime; import java.util.Map; import ru.yandex.javacource.golotin.schedule.exception.ManagerSaveException; @@ -41,10 +44,10 @@ public static FileBackedTaskManager loadFromFile(File file) { taskManager.createTask(task); } else if (task.getType() == TaskType.SUBTASK) { taskManager.createSubtask(new Subtask(task.getId(), task.getName(), task.getDescription(), - task.getStatus(), task.getEpicId())); + task.getStatus(), task.getStartTime(), task.getDuration(), task.getEpicId())); } else if (task.getType() == TaskType.EPIC) { taskManager.createEpic(new Epic(task.getId(), task.getName(), task.getDescription(), - task.getStatus())); + task.getStatus(), task.getStartTime(), task.getDuration())); for (Subtask subtask : taskManager.subtasks.values()) {// Поиск подзадач эпика if (subtask.getEpicId() == task.getId()) { Epic epic = taskManager.epics.get(task.getId()); @@ -124,7 +127,7 @@ public void deleteSubtask(int id) { public static String toString(Task task) { return task.getId() + "," + task.getType() + "," + task.getName() + "," + task.getStatus() + "," + - task.getDescription() + "," + (task.getType().equals(TaskType.SUBTASK) ? task.getEpicId() : ""); + task.getDescription() + "," + (task.getType().equals(TaskType.SUBTASK) ? task.getEpicId() : ""+task.getStartTime()+","+task.getEndTime()); } @@ -135,15 +138,17 @@ public static Task taskFromString(String value) { final String name = values[2]; final Status status = Status.valueOf(values[3]); final String description = values[4]; + final LocalDateTime startTime = LocalDateTime.parse(values[5]); + final Duration duration = Duration.between(LocalDateTime.parse(values[5]), LocalDateTime.parse(values[6])); if (type == TaskType.TASK) { - return new Task(id, name, description, status); + return new Task(id, name, description, status, startTime, duration.toMinutesPart()); } if (type == TaskType.SUBTASK) { final int epicId = Integer.parseInt(values[5]); - return new Subtask(id, name, description, status, epicId); + return new Subtask(id, name, description, status, startTime, duration.toMinutesPart(), epicId); } - return new Epic(id, name, description, status); + return new Epic(id, name, description, status, startTime, duration.toMinutesPart()); } protected void saveToFile() { diff --git a/src/ru/yandex/javacource/golotin/schedule/service/InMemoryTaskManager.java b/src/ru/yandex/javacource/golotin/schedule/service/InMemoryTaskManager.java index f5cb431..c08e838 100644 --- a/src/ru/yandex/javacource/golotin/schedule/service/InMemoryTaskManager.java +++ b/src/ru/yandex/javacource/golotin/schedule/service/InMemoryTaskManager.java @@ -1,15 +1,15 @@ package ru.yandex.javacource.golotin.schedule.service; +import ru.yandex.javacource.golotin.schedule.exception.ManagerSaveException; import ru.yandex.javacource.golotin.schedule.exception.NotFoundException; import ru.yandex.javacource.golotin.schedule.model.Epic; import ru.yandex.javacource.golotin.schedule.model.Status; import ru.yandex.javacource.golotin.schedule.model.Subtask; import ru.yandex.javacource.golotin.schedule.model.Task; -import java.util.ArrayList; -import java.util.HashMap; -import java.util.List; -import java.util.Map; +import java.time.LocalDateTime; +import java.util.*; +import java.util.stream.Collectors; public class InMemoryTaskManager implements TaskManager { @@ -18,19 +18,21 @@ public class InMemoryTaskManager implements TaskManager { protected final Map epics; protected final Map subtasks; protected final HistoryManager historyManager; - + protected final Set prioritizedTasks; public InMemoryTaskManager(HistoryManager historyManager) { this.historyManager = historyManager; // 3 this.tasks = new HashMap<>(); this.epics = new HashMap<>(); this.subtasks = new HashMap<>(); + this.prioritizedTasks = new TreeSet<>(Comparator.comparing(Task::getStartTime)); } @Override public Task createTask(Task task) {// создание Task final int id = ++counterId; task.setId(id); + addPriorityTask(task); tasks.put(id, task); return task; } @@ -39,6 +41,7 @@ public Task createTask(Task task) {// создание Task public Epic createEpic(Epic epic) {// создание Epic final int id = ++counterId; epic.setId(id); + addPriorityTask(epic); epics.put(id, epic); return epic; } @@ -51,8 +54,10 @@ public Subtask createSubtask(Subtask subtask) {// создание Subtask if (epic == null) { return null; } + updateEpicDuration(epic); final int id = ++counterId; subtask.setId(id); + addPriorityTask(subtask); subtasks.put(id, subtask); epic.addSubtaskId(subtask.getId()); updateEpicStatus(epicId); @@ -61,29 +66,30 @@ public Subtask createSubtask(Subtask subtask) {// создание Subtask @Override public void updateTask(Task task) {// обновление Task - final int id = task.getId(); - final Task savedTask = tasks.get(id); + final Task savedTask = tasks.get(task.getId()); if (savedTask == null) { return; } - tasks.put(id, task); + addPriorityTask(task); + tasks.put(task.getId(), task); } @Override public void updateEpic(Epic epic) {// обновление Epic - Epic savedEpic = epics.get(epic.getId()); + final Epic savedEpic = epics.get(epic.getId()); if (savedEpic == null) { return; } savedEpic.setName(epic.getName()); savedEpic.setDescription(epic.getDescription()); + addPriorityTask(savedEpic); + epics.put(epic.getId(), epic); } @Override public void updateSubtask(Subtask subtask) {// обновление Subtask - final int id = subtask.getId(); final int epicId = subtask.getEpicId(); - final Subtask savedSubtask = subtasks.get(id); + final Subtask savedSubtask = subtasks.get(subtask.getId()); if (savedSubtask == null) { return; } @@ -91,8 +97,9 @@ public void updateSubtask(Subtask subtask) {// обновление Subtask if (epic == null) { return; } - subtasks.put(id, subtask); - updateEpicStatus(epicId);// обновление статуса у Epic + addPriorityTask(savedSubtask); + subtasks.put(subtask.getId(), subtask); + updateEpic(epicId);// обновление статуса у Epic } @Override @@ -155,13 +162,8 @@ public List getEpics() { @Override public List getEpicSubtasks(int epicId) {// получаем список Epic с Subtasks Epic epic = epics.get(epicId); - ArrayList getSubtasks = null; - for (Integer subtaskId : epic.getSubtaskIds()) { - if (this.subtasks.containsKey(subtaskId)) { - getSubtasks.add(this.subtasks.get(subtaskId)); - } - } - return getSubtasks; + updateEpic(epicId); + return epic.getSubtaskIds().stream().map(subtasks::get).collect(Collectors.toList()); } @Override @@ -202,12 +204,10 @@ public List getHistory() {// получаем список истории private void updateEpicStatus(int epicId) {// обновление статуса Epic Epic epic = epics.get(epicId); - ArrayList subtasks = new ArrayList<>(); - for (Integer subtaskId : epic.getSubtaskIds()) { - if (this.subtasks.containsKey(subtaskId)) { - subtasks.add(this.subtasks.get(subtaskId)); - } - } + List subtasks = epic.getSubtaskIds().stream() + .filter(this.subtasks::containsKey) + .map(this.subtasks::get) + .toList(); for (Subtask statusSubtask : subtasks) { short subtaskNew = 0; short subtaskDone = 0; @@ -232,4 +232,58 @@ private void updateEpicStatus(int epicId) {// обновление статус } } + private void updateEpicDuration(Epic epic) { + List subs = epic.getSubtaskIds(); + if (subs.isEmpty()) { + epic.setDuration(0L); + return; + } + LocalDateTime start = LocalDateTime.MAX; + LocalDateTime end = LocalDateTime.MIN; + long duration = 0L; + for (int id : subs) { + final Subtask subtask = subtasks.get(id); + final LocalDateTime startTime = subtask.getStartTime(); + final LocalDateTime endTime = subtask.getEndTime(); + if (startTime.isBefore(start)) { + start = startTime; + } + if (endTime.isAfter(end)) { + end = endTime; + } + duration += subtask.getDuration(); + } + epic.setDuration(duration); + epic.setStartTime(start); + epic.setEndTime(end); + } + + protected void updateEpic(int epicId) { + Epic epic = epics.get(epicId); + updateEpicStatus(epicId); + updateEpicDuration(epic); + } + + private void addPriorityTask(Task task) { + final LocalDateTime startTime = task.getStartTime(); + final LocalDateTime endTime = task.getEndTime(); + for (Task t : prioritizedTasks) { + final LocalDateTime existStart = t.getStartTime(); + final LocalDateTime existEnd = t.getEndTime(); + if (!endTime.isAfter(existStart)) { + continue; + } + if (!existEnd.isAfter(startTime)) { + continue; + } + + throw new ManagerSaveException("Задача пересекаются с id=" + t.getId() + " c " + existStart + " по " + existEnd); + } + + prioritizedTasks.add(task); + } + + public List getPrioritizedTasks() { + return new ArrayList<>(prioritizedTasks); + } } diff --git a/test/ru/yandex/javacource/golotin/schedule/service/FileBackedTaskManagerTest.java b/test/ru/yandex/javacource/golotin/schedule/service/FileBackedTaskManagerTest.java new file mode 100644 index 0000000..b691320 --- /dev/null +++ b/test/ru/yandex/javacource/golotin/schedule/service/FileBackedTaskManagerTest.java @@ -0,0 +1,49 @@ +package ru.yandex.javacource.golotin.schedule.service; + +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import ru.yandex.javacource.golotin.schedule.model.Status; +import ru.yandex.javacource.golotin.schedule.model.Task; + +import java.io.File; +import java.time.LocalDateTime; + +import static org.junit.jupiter.api.Assertions.*; + +class FileBackedTaskManagerTest { + TaskManager taskManager; + @BeforeEach + void beforeEach() { + taskManager = Manager.getDefault(); + + } + + @Test + void createTask() { + LocalDateTime localDateTime = LocalDateTime.now().plusDays(1); + Task task = new Task("test", Status.NEW, "testing", localDateTime,30); + Task task2 = new Task("test2", Status.NEW, "testing2",LocalDateTime.now(),45); + taskManager.createTask(task); + taskManager.createTask(task2); + assertEquals(taskManager.getTasks(),FileBackedTaskManager.loadFromFile(new File("resources/task.csv")).getTasks()); + } + + @Test + void updateTask() { + Task task = new Task("test", Status.NEW, "testing", LocalDateTime.now(),30); + taskManager.createTask(task); + Task task2 = new Task(0,"test2","testing2", Status.NEW, LocalDateTime.now(),45); + taskManager.updateTask(task2); + assertEquals(task, FileBackedTaskManager.loadFromFile(new File("resources/task.csv")).getTask(1)); + } + + @Test + void deleteTask() { + Task task = new Task("test", Status.NEW, "testing", LocalDateTime.now(),30); + taskManager.createTask(task); + TaskManager taskManager1 = taskManager; + taskManager.deleteTask(task.getId()); + assertNotEquals(taskManager, taskManager1); + } + +} \ No newline at end of file diff --git a/test/ru/yandex/javacource/golotin/schedule/service/InMemoryTaskManagerTest.java b/test/ru/yandex/javacource/golotin/schedule/service/InMemoryTaskManagerTest.java index e932770..245f262 100644 --- a/test/ru/yandex/javacource/golotin/schedule/service/InMemoryTaskManagerTest.java +++ b/test/ru/yandex/javacource/golotin/schedule/service/InMemoryTaskManagerTest.java @@ -2,29 +2,34 @@ import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; +import ru.yandex.javacource.golotin.schedule.exception.ManagerSaveException; import ru.yandex.javacource.golotin.schedule.model.Status; import ru.yandex.javacource.golotin.schedule.model.Task; import ru.yandex.javacource.golotin.schedule.service.InMemoryTaskManager; +import ru.yandex.javacource.golotin.schedule.service.Manager; +import ru.yandex.javacource.golotin.schedule.service.TaskManager; +import java.time.LocalDateTime; import java.util.ArrayList; import java.util.List; import static org.junit.jupiter.api.Assertions.*; class InMemoryTaskManagerTest { - InMemoryTaskManager taskManager; + TaskManager taskManager; @BeforeEach void beforeEach() { - taskManager = new InMemoryTaskManager(); + taskManager = Manager.getDefault(); } @Test void shouldCreateTask() { - Task task = new Task("test", Status.NEW, "testing"); - Task task2 = new Task("test2", Status.NEW, "testing2"); + LocalDateTime localDateTime = LocalDateTime.now().plusDays(1); + Task task = new Task("test", Status.NEW, "testing", localDateTime,30); + Task task2 = new Task("test2", Status.NEW, "testing2",LocalDateTime.now(),45); Task task3 = task; assertEquals(task, task2); assertSame(task, task3); @@ -35,33 +40,40 @@ void shouldCreateTask() { Task clone = taskManager.getTask(result.getId()); assertEquals(clone.getId(), result.getId()); assertEquals(clone.getName(), result.getName()); - assertTrue(taskManager.getTasks().containsValue(task)); + assertTrue(taskManager.getTasks().contains(task)); } @Test void shouldUpdateTask() { - Task task = new Task("test", Status.NEW, "testing"); + LocalDateTime localDateTime = LocalDateTime.now().plusDays(1); + Task task = new Task("test", Status.NEW, "testing", localDateTime,30); taskManager.createTask(task); - Task task2 = new Task("test2", Status.NEW, "testing2"); + Task task2 = new Task(0,"test2", "testing2", Status.NEW, LocalDateTime.now(),45); taskManager.updateTask(task2); - assertNotEquals(task, taskManager.getTask(1)); + assertEquals(task, taskManager.getTask(1)); } @Test void shouldDeleteTask() { - Task task = new Task("test", Status.NEW, "testing"); - Task task2 = new Task("test2", Status.NEW, "testing2"); + LocalDateTime localDateTime = LocalDateTime.now().plusDays(1); + Task task = new Task("test", Status.NEW, "testing", localDateTime,30); + Task task2 = new Task("test2", Status.NEW, "testing2", LocalDateTime.now(),45); taskManager.createTask(task); taskManager.createTask(task2); taskManager.deleteTask(1); - assertNull(taskManager.getTask(1)); + Exception exception = assertThrows(ManagerSaveException.class, ()->taskManager.getTask(1)); + String expectedMessage = "Задача с ид=" + 1; + String actualMessage = exception.getMessage(); + assertTrue(actualMessage.contains(expectedMessage)); + } @Test void shouldCleanTask() { - Task task = new Task("test", Status.NEW, "testing"); - Task task2 = new Task("test2", Status.NEW, "testing2"); + LocalDateTime localDateTime = LocalDateTime.now().plusDays(1); + Task task = new Task("test", Status.NEW, "testing", LocalDateTime.now(),30); + Task task2 = new Task("test2", Status.NEW, "testing2", localDateTime,45); taskManager.createTask(task); taskManager.createTask(task2); taskManager.cleanTasks(); @@ -70,8 +82,9 @@ void shouldCleanTask() { @Test void shouldGetTasks() { - Task task = new Task("test", Status.NEW, "testing"); - Task task2 = new Task("test2", Status.NEW, "testing2"); + LocalDateTime localDateTime = LocalDateTime.now().plusDays(1); + Task task = new Task("test", Status.NEW, "testing", localDateTime,30); + Task task2 = new Task("test2", Status.NEW, "testing2", LocalDateTime.now(),45); taskManager.createTask(task); taskManager.createTask(task2); @@ -79,6 +92,19 @@ void shouldGetTasks() { tasks.add(task); tasks.add(task2); assertEquals(tasks, taskManager.getTasks()); + } + + @Test + void shouldaddPriorityTask(){ + LocalDateTime localDateTime = LocalDateTime.now(); + Task task = new Task("test", Status.NEW, "testing", localDateTime,30); + Task task2 = new Task("test2", Status.NEW, "testing2", localDateTime,45); + taskManager.createTask(task); + Exception exception = assertThrows(ManagerSaveException.class, () -> taskManager.createTask(task2)); + + String expectedMessage = "Задача пересекаются с id=" + task.getId() + " c " + task.getStartTime() + " по " + task.getEndTime(); + String actualMessage = exception.getMessage(); + assertTrue(actualMessage.contains(expectedMessage)); } } \ No newline at end of file