From c9ce89904851b7d3369b2b4c49246d0829991fa8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=A1=D0=BB=D0=B0=D0=B2=D0=B0?= Date: Wed, 11 Dec 2024 16:09:19 +0400 Subject: [PATCH 1/6] =?UTF-8?q?=D0=9F=D0=B5=D1=80=D0=B2=D0=B0=D1=8F=20?= =?UTF-8?q?=D1=80=D0=B5=D0=B0=D0=BB=D0=B8=D0=B7=D0=B0=D1=86=D0=B8=D1=8F=20?= =?UTF-8?q?=D0=A2=D0=97=208=D0=BE=D0=B3=D0=BE=20=D1=81=D0=BF=D1=80=D0=B8?= =?UTF-8?q?=D0=BD=D1=82=D0=B0.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/Main.java | 24 ++++- src/exception/IntersectionException.java | 8 ++ src/exception/ManagerLoadException.java | 11 ++ src/manager/FileBackedTaskManager.java | 23 ++-- src/manager/InMemoryHistoryManager.java | 2 +- src/manager/InMemoryTaskManager.java | 111 ++++++++++++++++++-- src/task/Epic.java | 51 ++++++++- src/task/Subtask.java | 34 +++++- src/task/Task.java | 63 ++++++++++- test/manager/FileBackedTaskManagerTest.java | 10 +- test/manager/InMemoryTaskManagerTest.java | 53 +++++++++- test/manager/TestFile.csv | 14 +-- 12 files changed, 368 insertions(+), 36 deletions(-) create mode 100644 src/exception/IntersectionException.java create mode 100644 src/exception/ManagerLoadException.java diff --git a/src/Main.java b/src/Main.java index 4b1cca9..44d9d41 100644 --- a/src/Main.java +++ b/src/Main.java @@ -5,6 +5,9 @@ import task.Task; import java.io.File; +import java.time.Duration; +import java.time.LocalDateTime; +import java.time.LocalTime; public class Main { @@ -14,14 +17,15 @@ public static void main(String[] args) { File file = new File("src/loadFile.csv"); System.out.println(FileBackedTaskManager.loadFromFile(file).getHistory()); FileBackedTaskManager taskManager = new FileBackedTaskManager(Managers.getDefaultHistory()); + // InMemoryTaskManager taskManager = new InMemoryTaskManager(Managers.getDefaultHistory()); Epic epic1 = new Epic("Epic-1", "Epic-1", Status.IN_PROGRESS); Epic epic2 = new Epic("Epic-2", "Epic-2", Status.NEW); - Task task1 = new Task("Task-1", "description for task-1", Status.NEW); + Task task1 = new Task("Task-1", "description for task-1", Status.NEW, LocalDateTime.of(2024, 3, 13, 14, 20), Duration.ofMinutes(10)); - Subtask subtask1 = new Subtask("Subtask-1", "Subtask-1 for Epic-1", Status.DONE, epic1); - Subtask subtask2 = new Subtask("Subtask-2", "Subtask-2 for Epic-1", Status.IN_PROGRESS, epic1); - Subtask subtask3 = new Subtask("Subtask-3", "Subtask-3 for Epic-1", Status.NEW, epic1); + Subtask subtask1 = new Subtask("Subtask-1", "Subtask-1 for Epic-1", Status.DONE, epic1, LocalDateTime.of(2024, 2, 10, 15, 40), Duration.ofMinutes(10)); + Subtask subtask2 = new Subtask("Subtask-2", "Subtask-2 for Epic-1", Status.IN_PROGRESS, epic1, LocalDateTime.of(2024, 1, 24, 22, 5), Duration.ofMinutes(10)); + Subtask subtask3 = new Subtask("Subtask-3", "Subtask-3 for Epic-1", Status.NEW, epic1, LocalDateTime.of(2024, 2, 5, 10, 0), Duration.ofMinutes(10)); taskManager.createTask(task1); taskManager.createEpic(epic1); taskManager.createEpic(epic2); @@ -29,7 +33,19 @@ public static void main(String[] args) { taskManager.createSubtask(subtask1); taskManager.createSubtask(subtask2); taskManager.createSubtask(subtask3); + // System.out.println(taskManager.getHistory()); + System.out.println(epic1); + taskManager.deleteSubtask(4); + System.out.println(epic1); + System.out.println(taskManager.getHistory()); + /* System.out.println(task1); + System.out.println(epic1.getSubtaskList()); + System.out.println(epic1.getDuration()); + System.out.println(epic1.getDuration()); + System.out.println(epic1.getStartTime()); + System.out.println(epic1.getEndTime());*/ + System.out.println(taskManager.getPrioritizedTasks()); /* taskManager.getEpic(1); diff --git a/src/exception/IntersectionException.java b/src/exception/IntersectionException.java new file mode 100644 index 0000000..bf1e648 --- /dev/null +++ b/src/exception/IntersectionException.java @@ -0,0 +1,8 @@ +package exception; + +public class IntersectionException extends RuntimeException { + + public IntersectionException(String message) { + super(message); + } +} diff --git a/src/exception/ManagerLoadException.java b/src/exception/ManagerLoadException.java new file mode 100644 index 0000000..4cf68c0 --- /dev/null +++ b/src/exception/ManagerLoadException.java @@ -0,0 +1,11 @@ +package exception; + +public class ManagerLoadException extends RuntimeException { + + + public ManagerLoadException(final Throwable cause) { + super(cause); + } + + +} diff --git a/src/manager/FileBackedTaskManager.java b/src/manager/FileBackedTaskManager.java index 71e7281..ecb5aec 100644 --- a/src/manager/FileBackedTaskManager.java +++ b/src/manager/FileBackedTaskManager.java @@ -1,5 +1,6 @@ package manager; +import exception.ManagerLoadException; import task.Epic; import task.Status; import task.Subtask; @@ -13,6 +14,9 @@ import java.nio.file.Path; import java.nio.file.Paths; +import java.time.Duration; +import java.time.LocalDateTime; +import java.time.format.DateTimeFormatter; import java.util.List; public class FileBackedTaskManager extends InMemoryTaskManager implements TaskManager { @@ -70,14 +74,14 @@ public Task createSubtask(Subtask subtask) { public String toString(Task task) { - return task.getId() + "," + task.getType() + "," + task.getName() + "," + task.getDescription() + "," + task.getStatus(); + return task.getId() + "," + task.getType() + "," + task.getName() + "," + task.getDescription() + "," + task.getStatus() + "," + task.getStartTime() + "," + task.getDuration() + "," + task.getEndTime(); } public void save() { try (BufferedWriter bw = new BufferedWriter(new FileWriter(pathToFile))) { - bw.write("id,type,name,description,status,epic\n"); + bw.write("id,type,name,description,status,epic,start time, duration, end Time\n"); for (Task task : getTasks()) { bw.write(toString(task) + "\n"); } @@ -102,6 +106,9 @@ public Task fromString(String value) { String name = mass[2]; String description = mass[3]; String status = mass[4]; + LocalDateTime startTime = LocalDateTime.parse(mass[5]); + Duration duration = Duration.parse(mass[6]); + LocalDateTime endTime = LocalDateTime.parse(mass[7]); if (type.equals("TASK")) { @@ -113,7 +120,7 @@ public Task fromString(String value) { } else { taskStatus = Status.IN_PROGRESS; } - Task task = new Task(id, name, description, taskStatus); + Task task = new Task(id, name, description, taskStatus, startTime, duration); task.setType(TaskType.TASK); createTask(task); return task; @@ -132,7 +139,7 @@ public Task fromString(String value) { return epic; } else { Status taskStatus; - int epicId = Integer.parseInt(mass[5]); + int epicId = Integer.parseInt(mass[8]); if (status.equals("NEW")) { taskStatus = Status.NEW; } else if (status.equals("DONE")) { @@ -140,7 +147,7 @@ public Task fromString(String value) { } else { taskStatus = Status.IN_PROGRESS; } - Subtask subtask = new Subtask(id, name, description, taskStatus, getEpic(epicId)); + Subtask subtask = new Subtask(id, name, description, taskStatus, getEpic(epicId), startTime, duration); subtask.setType(TaskType.SUBTASK); createSubtask(subtask); return subtask; @@ -150,7 +157,7 @@ public Task fromString(String value) { } public static FileBackedTaskManager loadFromFile(File file) { - FileBackedTaskManager fileBackedTaskManager = new FileBackedTaskManager(Managers.getDefaultHistory(),Paths.get(file.getPath())); + FileBackedTaskManager fileBackedTaskManager = new FileBackedTaskManager(Managers.getDefaultHistory(), Paths.get(file.getPath())); //теперь запись будет происходит в тот-же файл из которого была загрузка, а не в "file.csv" try { List lines = Files.readAllLines(file.toPath()); @@ -176,7 +183,7 @@ public ManagerSaveException(final Throwable cause) { } - public static class ManagerLoadException extends RuntimeException { + /* public static class ManagerLoadException extends RuntimeException { public ManagerLoadException(final Throwable cause) { @@ -184,5 +191,5 @@ public ManagerLoadException(final Throwable cause) { } - } + }*/ } diff --git a/src/manager/InMemoryHistoryManager.java b/src/manager/InMemoryHistoryManager.java index 72facdd..5173c0b 100644 --- a/src/manager/InMemoryHistoryManager.java +++ b/src/manager/InMemoryHistoryManager.java @@ -121,7 +121,7 @@ public void linkLast(Node node) { } - private static class Node { + private static class Node { Node previous; Node next; Task value; diff --git a/src/manager/InMemoryTaskManager.java b/src/manager/InMemoryTaskManager.java index b5b9c92..960933c 100644 --- a/src/manager/InMemoryTaskManager.java +++ b/src/manager/InMemoryTaskManager.java @@ -1,14 +1,17 @@ package manager; +import exception.IntersectionException; import task.Epic; import task.Status; import task.Subtask; import task.Task; -import java.util.ArrayList; -import java.util.HashMap; -import java.util.List; -import java.util.Map; + +import java.time.Duration; +import java.time.LocalDateTime; +import java.util.*; +import java.util.stream.Collectors; + public class InMemoryTaskManager implements TaskManager { private final Map tasks = new HashMap<>(); @@ -20,6 +23,15 @@ public class InMemoryTaskManager implements TaskManager { public InMemoryTaskManager(HistoryManager defaultHistory) { } + Comparator comparator = new Comparator() { + @Override + public int compare(Task o1, Task o2) { + + return o1.getStartTime().compareTo(o2.getStartTime()); + } + }; + private TreeSet prioritizedTasks = new TreeSet<>(comparator); + @Override public List getHistory() { return historyManager.getTasks(); @@ -81,6 +93,9 @@ public HashMap getSubtasksFromEpic(Epic epic) { @Override public Task createTask(Task task) { + if (taskIntersection(task)) { + throw new IntersectionException("Задача пересекается с уже существующей"); + } task.setId(getNextId()); tasks.put(task.getId(), task); @@ -89,9 +104,21 @@ public Task createTask(Task task) { @Override public Task createSubtask(Subtask subtask) { + if (taskIntersection(subtask)) { + throw new IntersectionException("Задача пересекается с уже существующей"); + } subtask.setId(getNextId()); + subtasks.put(subtask.getId(), subtask); subtask.getEpic().getSubtaskList().put(subtask.getId(), subtask); + if (subtask.getStartTime() != null) { //для создания сабтасок без времени в конструкторе. + // Может есть смысл в принципе убрать возможность создавать таски без времени, но пока не уверен + updateStartTimeForEpic(subtask.getEpic()); + + } + if (subtask.getDuration() != null) { //для создания сабтасок без времени в конструкторе + plusEpicDuration(subtask.getEpic(), subtask); + } epicStatus(subtask.getEpic()); return subtask; } @@ -99,6 +126,8 @@ public Task createSubtask(Subtask subtask) { @Override public Task createEpic(Epic epic) { epic.setId(getNextId()); + epic.setStartTime(LocalDateTime.of(2024, 1, 1, 0, 0)); // у меня сначала создаётся эпик, а потом уже сабтаски. + // Поэтому старт тайм эпика сделал таким, чтоб он не был null. При добавлении первой сабтаски с временем старттайм изменится. epics.put(epic.getId(), epic); return epic; } @@ -137,6 +166,9 @@ public Subtask updateSubtask(Subtask subtask) { } subtasks.put(subtaskId, subtask); subtask.getEpic().getSubtaskList().put(subtask.getId(), subtask); + if (subtask == firsSubtaskFromEpic(subtask.getEpic())) { + updateStartTimeForEpic(subtask.getEpic()); + } epicStatus(subtask.getEpic()); @@ -186,6 +218,10 @@ public boolean deleteSubtask(int taskId) { if (historyManager.getTasks().contains(subtasks.get(taskId))) { historyManager.remove(taskId); } + if (subtasks.get(taskId) == firsSubtaskFromEpic(subtasks.get(taskId).getEpic())) { + updateStartTimeForEpic(subtasks.get(taskId).getEpic()); + } + minusEpicDuration(subtasks.get(taskId).getEpic(), subtasks.get(taskId)); subtasks.remove(taskId); @@ -194,12 +230,14 @@ public boolean deleteSubtask(int taskId) { @Override public boolean deleteEpic(int taskId) { - // historyManager.remove(taskId); + if (!epics.containsKey(taskId)) { return false; } + + for (Subtask subtask : getEpic(taskId).getSubtaskList().values()) { - // historyManager.remove(taskId); + deleteSubtask(subtask.getId()); } if (historyManager.getTasks().contains(epics.get(taskId))) { @@ -209,6 +247,67 @@ public boolean deleteEpic(int taskId) { return true; } + public Subtask firsSubtaskFromEpic(Epic epic) { + List subtaskList = new ArrayList<>(); + for (Subtask subtask : epic.getSubtaskList().values()) { + subtaskList.add(subtask); + } + return subtaskList.getFirst(); + + } + + public void plusEpicDuration(Epic epic, Subtask subtask) { + Duration duration = epic.getDuration().plus(subtask.getDuration()); + epic.setDuration(duration); + + } + + public void minusEpicDuration(Epic epic, Subtask subtask) { + Duration duration = epic.getDuration().minus(subtask.getDuration()); + epic.setDuration(duration); + } + + public void updateStartTimeForEpic(Epic epic) { + if (!epic.getSubtaskList().isEmpty()) { + + LocalDateTime startTime = firsSubtaskFromEpic(epic).getStartTime(); + epic.setStartTime(startTime); + } + + + } + + + public boolean taskIntersection(Task newTask) { + if (newTask.getStartTime() == null || newTask.getDuration() == null) { + return false; + } + List intersectionList = getPrioritizedTasks().stream() + .filter(task1 -> newTask.getStartTime().isBefore(task1.getEndTime()) && newTask.getEndTime().isAfter(task1.getStartTime())) + .collect(Collectors.toList()); + if (!intersectionList.isEmpty()) { + return true; + } + + return false; + + + } + + public TreeSet getPrioritizedTasks() { + List allTasks = new ArrayList<>(); + allTasks.addAll(getTasks()); + allTasks.addAll(getSubtasks()); + List notNullTasks = allTasks + .stream() + .filter(task -> task.getStartTime() != null) + .collect(Collectors.toList()); + prioritizedTasks.addAll(notNullTasks); + return prioritizedTasks; + + } + + @Override public int getNextId() { return ++nextId; diff --git a/src/task/Epic.java b/src/task/Epic.java index 38ac560..6599528 100644 --- a/src/task/Epic.java +++ b/src/task/Epic.java @@ -2,13 +2,50 @@ import manager.TaskType; +import java.time.Duration; +import java.time.Instant; +import java.time.LocalDateTime; +import java.time.LocalTime; +import java.util.ArrayList; import java.util.HashMap; +import java.util.List; import java.util.Map; public class Epic extends Task { protected Map subtaskList = new HashMap<>(); + private LocalDateTime endTime; TaskType type; + Duration duration = Duration.ZERO; + LocalDateTime startTime; + @Override + public Duration getDuration() { + return duration; + } + + public Epic(String name, String description) { + super(name, description); + } + + @Override + public void setDuration(Duration duration) { + this.duration = duration; + } + + @Override + public LocalDateTime getEndTime() { + return getStartTime().plus(getDuration()); + } + + @Override + public LocalDateTime getStartTime() { + + return startTime; + } + + public void setStartTime(LocalDateTime startTime) { + this.startTime = startTime; + } public Epic(String name, String description, Status status) { super(name, description, status); @@ -16,6 +53,7 @@ public Epic(String name, String description, Status status) { } + @Override public void setType(TaskType type) { this.type = type; @@ -40,5 +78,16 @@ public Map getSubtaskList() { return subtaskList; } - + @Override + public String toString() { + return "Epic{" + + "id=" + getId() + + ", name='" + getName() + '\'' + + ", description='" + getDescription() + '\'' + + ", status=" + getStatus() + + ", type=" + getType() + + ", startTime=" + getStartTime() + + ", duration=" + getDuration() + + '}'; + } } diff --git a/src/task/Subtask.java b/src/task/Subtask.java index c694b3a..0402b7b 100644 --- a/src/task/Subtask.java +++ b/src/task/Subtask.java @@ -2,16 +2,19 @@ import manager.TaskType; +import java.time.Duration; +import java.time.LocalDateTime; +import java.time.format.DateTimeFormatter; + public class Subtask extends Task { Epic epic; + TaskType type; @Override public TaskType getType() { return type; } - TaskType type; - public Subtask(String name, String description, Status status, Epic epic) { super(name, description, status); @@ -26,6 +29,20 @@ public Subtask(Integer id, String name, String description, Status status, Epic } + public Subtask(String name, String description, Status status, Epic epic, LocalDateTime startTime, Duration duration) { + super(name, description, status, startTime, duration); + this.epic = epic; + this.type = TaskType.SUBTASK; + + } + + public Subtask(Integer id, String name, String description, Status status, Epic epic, LocalDateTime startTime, Duration duration) { + super(id, name, description, status, startTime, duration); + this.epic = epic; + this.type = TaskType.SUBTASK; + + } + @Override public void setType(TaskType type) { this.type = type; @@ -39,5 +56,16 @@ public Epic getEpic() { return epic; } - + @Override + public String toString() { + return "Task{" + + "id=" + getId() + + ", name='" + getName() + '\'' + + ", description='" + getDescription() + '\'' + + ", status=" + getStatus() + + ", type=" + getType() + + ", startTime=" + getStartTime().format(DateTimeFormatter.ofPattern("dd.MM.yy HH:mm")) + + ", duration=" + getDuration() + + '}'; + } } diff --git a/src/task/Task.java b/src/task/Task.java index dfd908a..655fb06 100644 --- a/src/task/Task.java +++ b/src/task/Task.java @@ -2,6 +2,9 @@ import manager.TaskType; +import java.time.Duration; +import java.time.LocalDateTime; +import java.time.format.DateTimeFormatter; import java.util.Objects; public class Task { @@ -10,7 +13,33 @@ public class Task { private String description; private Status status; private TaskType type; + private LocalDateTime startTime; + private Duration duration; + private DateTimeFormatter formatter = DateTimeFormatter.ofPattern("HH:mm"); + public Task(String name, String description) { + this.name = name; + this.description = description; + } + + public LocalDateTime getEndTime() { + if (startTime != null && duration != null) { + return startTime.plus(duration); + } + return null; + } + + public void setDuration(Duration duration) { + this.duration = duration; + } + + public Duration getDuration() { + return duration; + } + + public LocalDateTime getStartTime() { + return startTime; + } public Task(String name, String descriprion, Status status) { this.name = name; @@ -19,6 +48,7 @@ public Task(String name, String descriprion, Status status) { this.type = TaskType.TASK; } + public Task(Integer id, String name, String descriprion, Status status) { this.id = id; this.name = name; @@ -27,6 +57,25 @@ public Task(Integer id, String name, String descriprion, Status status) { this.type = TaskType.TASK; } + public Task(String name, String description, Status status, LocalDateTime startTime, Duration duration) { + this.name = name; + this.description = description; + this.status = status; + this.type = TaskType.TASK; + this.startTime = startTime; + this.duration = duration; + } + + public Task(Integer id, String name, String description, Status status, LocalDateTime startTime, Duration duration) { + this.id = id; + this.name = name; + this.description = description; + this.status = status; + this.type = TaskType.TASK; + this.startTime = startTime; + this.duration = duration; + } + public void setId(Integer id) { this.id = id; } @@ -85,8 +134,20 @@ public String toString() { return "Task{" + "id=" + id + ", name='" + name + '\'' + - ", descriprion='" + description + '\'' + + ", description='" + description + '\'' + ", status=" + status + + ", type=" + type + + ", startTime=" + startTime.format(DateTimeFormatter.ofPattern("dd.MM.yy HH:mm")) + + ", duration=" + duration + '}'; } +/* @Override + public String toString() { + return "Task{" + + "id=" + id + + ", name='" + name + '\'' + + ", descriprion='" + description + '\'' + + ", status=" + status + + '}'; + }*/ } diff --git a/test/manager/FileBackedTaskManagerTest.java b/test/manager/FileBackedTaskManagerTest.java index 41ba3b1..af377c3 100644 --- a/test/manager/FileBackedTaskManagerTest.java +++ b/test/manager/FileBackedTaskManagerTest.java @@ -10,6 +10,8 @@ import java.io.IOException; import java.nio.file.Files; import java.nio.file.Paths; +import java.time.Duration; +import java.time.LocalDateTime; import java.util.List; import static org.junit.jupiter.api.Assertions.assertEquals; @@ -24,12 +26,12 @@ void saveInFile() throws IOException { Files.createTempFile("testFile", ".csv")); Epic epic1 = new Epic("Epic-1", "Epic-1", Status.IN_PROGRESS); Epic epic2 = new Epic("Epic-2", "Epic-2", Status.NEW); - Task task1 = new Task("Task-1", "description for task-1", Status.NEW); + Task task1 = new Task("Task-1", "description for task-1", Status.NEW, LocalDateTime.of(2024, 1, 13, 14, 20), Duration.ofMinutes(10)); - Subtask subtask1 = new Subtask("Subtask-1", "Subtask-1 for Epic-1", Status.DONE, epic1); - Subtask subtask2 = new Subtask("Subtask-2", "Subtask-2 for Epic-1", Status.IN_PROGRESS, epic1); - Subtask subtask3 = new Subtask("Subtask-3", "Subtask-3 for Epic-1", Status.NEW, epic1); + Subtask subtask1 = new Subtask("Subtask-1", "Subtask-1 for Epic-1", Status.DONE, epic1, LocalDateTime.of(2024, 2, 10, 15, 40), Duration.ofMinutes(10)); + Subtask subtask2 = new Subtask("Subtask-2", "Subtask-2 for Epic-1", Status.IN_PROGRESS, epic1, LocalDateTime.of(2024, 2, 24, 22, 5), Duration.ofMinutes(10)); + Subtask subtask3 = new Subtask("Subtask-3", "Subtask-3 for Epic-1", Status.NEW, epic1, LocalDateTime.of(2024, 3, 5, 10, 0), Duration.ofMinutes(10)); fileBackedTaskManager.createTask(task1); fileBackedTaskManager.createEpic(epic1); fileBackedTaskManager.createEpic(epic2); diff --git a/test/manager/InMemoryTaskManagerTest.java b/test/manager/InMemoryTaskManagerTest.java index 18394b5..c601015 100644 --- a/test/manager/InMemoryTaskManagerTest.java +++ b/test/manager/InMemoryTaskManagerTest.java @@ -7,6 +7,9 @@ import task.Subtask; import task.Task; +import java.time.Duration; +import java.time.LocalDateTime; + import static org.junit.jupiter.api.Assertions.*; class InMemoryTaskManagerTest { @@ -136,7 +139,7 @@ void deleteId() { @Test void deleteSubtaskFromEpic() { Epic epic1 = new Epic(1, "Test Epic", "Test epic description", Status.NEW); - Subtask subtask1 = new Subtask(2, "Subtask for epic1", "description", Status.NEW, epic1); + Subtask subtask1 = new Subtask(2, "Subtask for epic1", "description", Status.NEW, epic1, LocalDateTime.of(2024, 2, 10, 15, 40), Duration.ofMinutes(10)); taskManager.createEpic(epic1); taskManager.createSubtask(subtask1); taskManager.deleteSubtask(2); @@ -144,5 +147,53 @@ void deleteSubtaskFromEpic() { } + @Test + void epicNewStatusTest() { + Epic epic1 = new Epic("Test Epic", "Test epic description"); + Subtask subtask1 = new Subtask("Subtask-1 for epic1", "description", Status.NEW, epic1, LocalDateTime.of(2024, 2, 10, 15, 40), Duration.ofMinutes(10)); + Subtask subtask2 = new Subtask("Subtask-2 for epic1", "description", Status.NEW, epic1, LocalDateTime.of(2024, 3, 10, 15, 40), Duration.ofMinutes(10)); + taskManager.createEpic(epic1); + taskManager.createSubtask(subtask1); + taskManager.createSubtask(subtask2); + assertEquals(epic1.getStatus(), Status.NEW); + + } + + @Test + void epicDoneStatusTest() { + Epic epic1 = new Epic("Test Epic", "Test epic description"); + Subtask subtask1 = new Subtask("Subtask-1 for epic1", "description", Status.DONE, epic1, LocalDateTime.of(2024, 2, 10, 15, 40), Duration.ofMinutes(10)); + Subtask subtask2 = new Subtask("Subtask-2 for epic1", "description", Status.DONE, epic1, LocalDateTime.of(2024, 3, 10, 15, 40), Duration.ofMinutes(10)); + taskManager.createEpic(epic1); + taskManager.createSubtask(subtask1); + taskManager.createSubtask(subtask2); + assertEquals(epic1.getStatus(), Status.DONE); + + } + + @Test + void epicMixedStatusTest() { + Epic epic1 = new Epic("Test Epic", "Test epic description"); + Subtask subtask1 = new Subtask("Subtask-1 for epic1", "description", Status.NEW, epic1, LocalDateTime.of(2024, 2, 10, 15, 40), Duration.ofMinutes(10)); + Subtask subtask2 = new Subtask("Subtask-2 for epic1", "description", Status.DONE, epic1, LocalDateTime.of(2024, 3, 10, 15, 40), Duration.ofMinutes(10)); + taskManager.createEpic(epic1); + taskManager.createSubtask(subtask1); + taskManager.createSubtask(subtask2); + assertEquals(epic1.getStatus(), Status.IN_PROGRESS); + + } + + @Test + void epicInProgressStatusTest() { + Epic epic1 = new Epic("Test Epic", "Test epic description"); + Subtask subtask1 = new Subtask("Subtask-1 for epic1", "description", Status.IN_PROGRESS, epic1, LocalDateTime.of(2024, 2, 10, 15, 40), Duration.ofMinutes(10)); + Subtask subtask2 = new Subtask("Subtask-2 for epic1", "description", Status.IN_PROGRESS, epic1, LocalDateTime.of(2024, 3, 10, 15, 40), Duration.ofMinutes(10)); + taskManager.createEpic(epic1); + taskManager.createSubtask(subtask1); + taskManager.createSubtask(subtask2); + assertEquals(epic1.getStatus(), Status.IN_PROGRESS); + + } + } \ No newline at end of file diff --git a/test/manager/TestFile.csv b/test/manager/TestFile.csv index 0cfd080..d6a3825 100644 --- a/test/manager/TestFile.csv +++ b/test/manager/TestFile.csv @@ -1,7 +1,7 @@ -id,type,name,description,status,epic -1,TASK,Task-1,description for task-1,NEW -2,EPIC,Epic-1,Epic-1,IN_PROGRESS -3,EPIC,Epic-2,Epic-2,NEW -4,SUBTASK,Subtask-1,Subtask-1 for Epic-1,DONE,2 -5,SUBTASK,Subtask-2,Subtask-2 for Epic-1,IN_PROGRESS,2 -6,SUBTASK,Subtask-3,Subtask-3 for Epic-1,NEW,2 +id,type,name,description,status,epic,start time, duration, end Time +1,TASK,Task-1,description for task-1,NEW,2024-01-13T14:20,PT10M,2024-01-13T14:30 +2,EPIC,Epic-1,Epic-1,IN_PROGRESS,2024-02-10T15:40,PT30M,2024-02-10T16:10 +3,EPIC,Epic-2,Epic-2,NEW,2024-01-01T00:00,PT0S,2024-01-01T00:00 +4,SUBTASK,Subtask-1,Subtask-1 for Epic-1,DONE,2024-02-10T15:40,PT10M,2024-02-10T15:50,2 +5,SUBTASK,Subtask-2,Subtask-2 for Epic-1,IN_PROGRESS,2024-02-24T22:05,PT10M,2024-02-24T22:15,2 +6,SUBTASK,Subtask-3,Subtask-3 for Epic-1,NEW,2024-03-05T10:00,PT10M,2024-03-05T10:10,2 From 138ef9dec9dbf62f1af9b916f7e1c21cb6af2e7a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=A1=D0=BB=D0=B0=D0=B2=D0=B0?= Date: Wed, 11 Dec 2024 16:10:59 +0400 Subject: [PATCH 2/6] =?UTF-8?q?=D0=9F=D0=B5=D1=80=D0=B2=D0=B0=D1=8F=20?= =?UTF-8?q?=D1=80=D0=B5=D0=B0=D0=BB=D0=B8=D0=B7=D0=B0=D1=86=D0=B8=D1=8F=20?= =?UTF-8?q?=D0=A2=D0=97=208=D0=BE=D0=B3=D0=BE=20=D1=81=D0=BF=D1=80=D0=B8?= =?UTF-8?q?=D0=BD=D1=82=D0=B0.=20=D0=98=D1=81=D0=BF=D1=80=D0=B0=D0=B2?= =?UTF-8?q?=D0=BB=D0=B5=D0=BD=D0=B8=D1=8F=20=D0=B4=D0=BB=D1=8F=20=D0=B0?= =?UTF-8?q?=D0=B2=D1=82=D0=BE=D1=82=D0=B5=D1=81=D1=82=D0=BE=D0=B2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/Main.java | 1 - 1 file changed, 1 deletion(-) diff --git a/src/Main.java b/src/Main.java index 44d9d41..41d15fc 100644 --- a/src/Main.java +++ b/src/Main.java @@ -7,7 +7,6 @@ import java.io.File; import java.time.Duration; import java.time.LocalDateTime; -import java.time.LocalTime; public class Main { From 5b5dc11cce4dba67d5b8bac2058b2f9d597b0522 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=A1=D0=BB=D0=B0=D0=B2=D0=B0?= Date: Wed, 11 Dec 2024 16:12:27 +0400 Subject: [PATCH 3/6] =?UTF-8?q?=D0=9F=D0=B5=D1=80=D0=B2=D0=B0=D1=8F=20?= =?UTF-8?q?=D1=80=D0=B5=D0=B0=D0=BB=D0=B8=D0=B7=D0=B0=D1=86=D0=B8=D1=8F=20?= =?UTF-8?q?=D0=A2=D0=97=208=D0=BE=D0=B3=D0=BE=20=D1=81=D0=BF=D1=80=D0=B8?= =?UTF-8?q?=D0=BD=D1=82=D0=B0.=20=D0=98=D1=81=D0=BF=D1=80=D0=B0=D0=B2?= =?UTF-8?q?=D0=BB=D0=B5=D0=BD=D0=B8=D1=8F=20=D0=B4=D0=BB=D1=8F=20=D0=B0?= =?UTF-8?q?=D0=B2=D1=82=D0=BE=D1=82=D0=B5=D1=81=D1=82=D0=BE=D0=B2=202?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/manager/FileBackedTaskManager.java | 1 - 1 file changed, 1 deletion(-) diff --git a/src/manager/FileBackedTaskManager.java b/src/manager/FileBackedTaskManager.java index ecb5aec..88d6176 100644 --- a/src/manager/FileBackedTaskManager.java +++ b/src/manager/FileBackedTaskManager.java @@ -16,7 +16,6 @@ import java.nio.file.Paths; import java.time.Duration; import java.time.LocalDateTime; -import java.time.format.DateTimeFormatter; import java.util.List; public class FileBackedTaskManager extends InMemoryTaskManager implements TaskManager { From b2cd736409596a12e9dfe5c3a37fe4a9beaaff65 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=A1=D0=BB=D0=B0=D0=B2=D0=B0?= Date: Wed, 11 Dec 2024 16:13:47 +0400 Subject: [PATCH 4/6] =?UTF-8?q?=D0=9F=D0=B5=D1=80=D0=B2=D0=B0=D1=8F=20?= =?UTF-8?q?=D1=80=D0=B5=D0=B0=D0=BB=D0=B8=D0=B7=D0=B0=D1=86=D0=B8=D1=8F=20?= =?UTF-8?q?=D0=A2=D0=97=208=D0=BE=D0=B3=D0=BE=20=D1=81=D0=BF=D1=80=D0=B8?= =?UTF-8?q?=D0=BD=D1=82=D0=B0.=20=D0=98=D1=81=D0=BF=D1=80=D0=B0=D0=B2?= =?UTF-8?q?=D0=BB=D0=B5=D0=BD=D0=B8=D1=8F=20=D0=B4=D0=BB=D1=8F=20=D0=B0?= =?UTF-8?q?=D0=B2=D1=82=D0=BE=D1=82=D0=B5=D1=81=D1=82=D0=BE=D0=B2=203?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/task/Epic.java | 4 ---- 1 file changed, 4 deletions(-) diff --git a/src/task/Epic.java b/src/task/Epic.java index 6599528..db328ff 100644 --- a/src/task/Epic.java +++ b/src/task/Epic.java @@ -3,12 +3,8 @@ import manager.TaskType; import java.time.Duration; -import java.time.Instant; import java.time.LocalDateTime; -import java.time.LocalTime; -import java.util.ArrayList; import java.util.HashMap; -import java.util.List; import java.util.Map; public class Epic extends Task { From 3ca89fc38cb660f75e490d94c2141a3d818e15c9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=A1=D0=BB=D0=B0=D0=B2=D0=B0?= Date: Thu, 12 Dec 2024 18:12:36 +0400 Subject: [PATCH 5/6] =?UTF-8?q?=D0=92=D1=82=D0=BE=D1=80=D0=B0=D1=8F=20?= =?UTF-8?q?=D1=80=D0=B5=D0=B0=D0=BB=D0=B8=D0=B7=D0=B0=D1=86=D0=B8=D1=8F=20?= =?UTF-8?q?=D0=A2=D0=97=208=D0=BE=D0=B3=D0=BE=20=D1=81=D0=BF=D1=80=D0=B8?= =?UTF-8?q?=D0=BD=D1=82=D0=B0=20=D1=81=20=D0=B8=D1=81=D0=BF=D1=80=D0=B0?= =?UTF-8?q?=D0=B2=D0=BB=D0=B5=D0=BD=D0=B8=D0=B5=D0=BC=20=D0=BE=D1=88=D0=B8?= =?UTF-8?q?=D0=B1=D0=BE=D0=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/Main.java | 28 +----------------- src/exception/IntersectionException.java | 3 +- src/manager/InMemoryTaskManager.java | 35 ++++++++++++++--------- src/task/Task.java | 10 +------ test/manager/InMemoryTaskManagerTest.java | 17 ++++++++++- 5 files changed, 41 insertions(+), 52 deletions(-) diff --git a/src/Main.java b/src/Main.java index 41d15fc..fad5ef0 100644 --- a/src/Main.java +++ b/src/Main.java @@ -16,7 +16,6 @@ public static void main(String[] args) { File file = new File("src/loadFile.csv"); System.out.println(FileBackedTaskManager.loadFromFile(file).getHistory()); FileBackedTaskManager taskManager = new FileBackedTaskManager(Managers.getDefaultHistory()); - // InMemoryTaskManager taskManager = new InMemoryTaskManager(Managers.getDefaultHistory()); Epic epic1 = new Epic("Epic-1", "Epic-1", Status.IN_PROGRESS); Epic epic2 = new Epic("Epic-2", "Epic-2", Status.NEW); Task task1 = new Task("Task-1", "description for task-1", Status.NEW, LocalDateTime.of(2024, 3, 13, 14, 20), Duration.ofMinutes(10)); @@ -32,39 +31,14 @@ public static void main(String[] args) { taskManager.createSubtask(subtask1); taskManager.createSubtask(subtask2); taskManager.createSubtask(subtask3); - // System.out.println(taskManager.getHistory()); System.out.println(epic1); taskManager.deleteSubtask(4); System.out.println(epic1); System.out.println(taskManager.getHistory()); - /* System.out.println(task1); - System.out.println(epic1.getSubtaskList()); - System.out.println(epic1.getDuration()); - System.out.println(epic1.getDuration()); - System.out.println(epic1.getStartTime()); - System.out.println(epic1.getEndTime());*/ - System.out.println(taskManager.getPrioritizedTasks()); + System.out.println(taskManager.getPrioritizedTasks()); - /* taskManager.getEpic(1); - System.out.println(taskManager.getHistory()); - taskManager.getSubtask(3); - System.out.println(taskManager.getHistory()); - taskManager.getSubtask(5); - System.out.println(taskManager.getHistory()); - taskManager.getEpic(1); - System.out.println(taskManager.getHistory()); - taskManager.deleteTask(4); - System.out.println(taskManager.getHistory()); - taskManager.getSubtask(4); - System.out.println(taskManager.getHistory()); - taskManager.getEpic(2); - System.out.println(taskManager.getHistory()); - taskManager.deleteSubtask(4); - System.out.println(taskManager.getHistory()); - taskManager.deleteEpic(1); - System.out.println(taskManager.getHistory());*/ } diff --git a/src/exception/IntersectionException.java b/src/exception/IntersectionException.java index bf1e648..602be37 100644 --- a/src/exception/IntersectionException.java +++ b/src/exception/IntersectionException.java @@ -1,6 +1,7 @@ package exception; -public class IntersectionException extends RuntimeException { +public class IntersectionException extends Exception { + public IntersectionException(String message) { super(message); diff --git a/src/manager/InMemoryTaskManager.java b/src/manager/InMemoryTaskManager.java index 960933c..864e916 100644 --- a/src/manager/InMemoryTaskManager.java +++ b/src/manager/InMemoryTaskManager.java @@ -30,7 +30,7 @@ public int compare(Task o1, Task o2) { return o1.getStartTime().compareTo(o2.getStartTime()); } }; - private TreeSet prioritizedTasks = new TreeSet<>(comparator); + private Set prioritizedTasks = new TreeSet<>(comparator); @Override public List getHistory() { @@ -93,20 +93,20 @@ public HashMap getSubtasksFromEpic(Epic epic) { @Override public Task createTask(Task task) { - if (taskIntersection(task)) { - throw new IntersectionException("Задача пересекается с уже существующей"); - } + taskIntersection(task); + task.setId(getNextId()); tasks.put(task.getId(), task); + + return task; } @Override public Task createSubtask(Subtask subtask) { - if (taskIntersection(subtask)) { - throw new IntersectionException("Задача пересекается с уже существующей"); - } + taskIntersection(subtask); + subtask.setId(getNextId()); subtasks.put(subtask.getId(), subtask); @@ -120,6 +120,7 @@ public Task createSubtask(Subtask subtask) { plusEpicDuration(subtask.getEpic(), subtask); } epicStatus(subtask.getEpic()); + return subtask; } @@ -282,19 +283,25 @@ public boolean taskIntersection(Task newTask) { if (newTask.getStartTime() == null || newTask.getDuration() == null) { return false; } - List intersectionList = getPrioritizedTasks().stream() - .filter(task1 -> newTask.getStartTime().isBefore(task1.getEndTime()) && newTask.getEndTime().isAfter(task1.getStartTime())) - .collect(Collectors.toList()); - if (!intersectionList.isEmpty()) { - return true; + boolean intersection = getPrioritizedTasks().stream() + .anyMatch(task -> newTask.getStartTime().isBefore(task.getEndTime()) && newTask.getEndTime().isAfter(task.getStartTime())); + ; + try { + if (intersection) { + throw new IntersectionException("Задача " + newTask.getName() + " пересекается с уже существующей"); + } + } catch (IntersectionException e) { + System.out.println(e.getMessage()); + throw new RuntimeException(); } - return false; + + return intersection; } - public TreeSet getPrioritizedTasks() { + public Set getPrioritizedTasks() { List allTasks = new ArrayList<>(); allTasks.addAll(getTasks()); allTasks.addAll(getSubtasks()); diff --git a/src/task/Task.java b/src/task/Task.java index 655fb06..9316c45 100644 --- a/src/task/Task.java +++ b/src/task/Task.java @@ -141,13 +141,5 @@ public String toString() { ", duration=" + duration + '}'; } -/* @Override - public String toString() { - return "Task{" + - "id=" + id + - ", name='" + name + '\'' + - ", descriprion='" + description + '\'' + - ", status=" + status + - '}'; - }*/ + } diff --git a/test/manager/InMemoryTaskManagerTest.java b/test/manager/InMemoryTaskManagerTest.java index c601015..4db498f 100644 --- a/test/manager/InMemoryTaskManagerTest.java +++ b/test/manager/InMemoryTaskManagerTest.java @@ -195,5 +195,20 @@ void epicInProgressStatusTest() { } + @Test + public void intersectionTest() { + Task task1 = new Task("Task-1", "description", Status.NEW, LocalDateTime.of(2024, 12, 12, 10, 0), Duration.ofMinutes(600)); + Task task2 = new Task("Task-2", "description", Status.NEW, LocalDateTime.of(2024, 12, 12, 10, 10), Duration.ofMinutes(10)); + + assertThrows(RuntimeException.class, () -> { + taskManager.createTask(task1); + taskManager.createTask(task2); + + + }); + + } +} + + -} \ No newline at end of file From 83e8ae0993182f6960e405e6612ad7c6b1858781 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=A1=D0=BB=D0=B0=D0=B2=D0=B0?= Date: Fri, 13 Dec 2024 00:38:27 +0400 Subject: [PATCH 6/6] =?UTF-8?q?=D0=92=D1=82=D0=BE=D1=80=D0=B0=D1=8F=20?= =?UTF-8?q?=D1=80=D0=B5=D0=B0=D0=BB=D0=B8=D0=B7=D0=B0=D1=86=D0=B8=D1=8F=20?= =?UTF-8?q?=D0=A2=D0=97=208=D0=BE=D0=B3=D0=BE=20=D1=81=D0=BF=D1=80=D0=B8?= =?UTF-8?q?=D0=BD=D1=82=D0=B0=20=D1=81=20=D0=B8=D1=81=D0=BF=D1=80=D0=B0?= =?UTF-8?q?=D0=B2=D0=BB=D0=B5=D0=BD=D0=B8=D0=B5=D0=BC=20=D0=B8=D1=81=D0=BA?= =?UTF-8?q?=D0=BB=D1=8E=D1=87=D0=B5=D0=BD=D0=B8=D0=B9.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/Main.java | 3 ++- src/manager/FileBackedTaskManager.java | 9 +++---- src/manager/InMemoryTaskManager.java | 18 ++++++-------- src/manager/TaskManager.java | 5 ++-- test/manager/FileBackedTaskManagerTest.java | 7 +++--- test/manager/InMemoryHistoryManagerTest.java | 9 +++---- test/manager/InMemoryTaskManagerTest.java | 25 ++++++++++---------- 7 files changed, 39 insertions(+), 37 deletions(-) diff --git a/src/Main.java b/src/Main.java index fad5ef0..a1d7249 100644 --- a/src/Main.java +++ b/src/Main.java @@ -1,3 +1,4 @@ +import exception.IntersectionException; import manager.*; import task.Epic; import task.Status; @@ -11,7 +12,7 @@ public class Main { - public static void main(String[] args) { + public static void main(String[] args) throws IntersectionException { File file = new File("src/loadFile.csv"); System.out.println(FileBackedTaskManager.loadFromFile(file).getHistory()); diff --git a/src/manager/FileBackedTaskManager.java b/src/manager/FileBackedTaskManager.java index 88d6176..44fc12f 100644 --- a/src/manager/FileBackedTaskManager.java +++ b/src/manager/FileBackedTaskManager.java @@ -1,5 +1,6 @@ package manager; +import exception.IntersectionException; import exception.ManagerLoadException; import task.Epic; import task.Status; @@ -45,7 +46,7 @@ public FileBackedTaskManager(HistoryManager defaultHistory) { @Override - public Task createTask(Task task) { + public Task createTask(Task task) throws IntersectionException { super.createTask(task); save(); @@ -63,7 +64,7 @@ public Task createEpic(Epic epic) { } @Override - public Task createSubtask(Subtask subtask) { + public Task createSubtask(Subtask subtask) throws IntersectionException { super.createSubtask(subtask); save(); @@ -98,7 +99,7 @@ public void save() { } - public Task fromString(String value) { + public Task fromString(String value) throws IntersectionException { String[] mass = value.split(","); int id = Integer.parseInt(mass[0]); String type = mass[1]; @@ -155,7 +156,7 @@ public Task fromString(String value) { } - public static FileBackedTaskManager loadFromFile(File file) { + public static FileBackedTaskManager loadFromFile(File file) throws IntersectionException { FileBackedTaskManager fileBackedTaskManager = new FileBackedTaskManager(Managers.getDefaultHistory(), Paths.get(file.getPath())); //теперь запись будет происходит в тот-же файл из которого была загрузка, а не в "file.csv" try { diff --git a/src/manager/InMemoryTaskManager.java b/src/manager/InMemoryTaskManager.java index 864e916..a3efc3f 100644 --- a/src/manager/InMemoryTaskManager.java +++ b/src/manager/InMemoryTaskManager.java @@ -92,7 +92,7 @@ public HashMap getSubtasksFromEpic(Epic epic) { } @Override - public Task createTask(Task task) { + public Task createTask(Task task) throws IntersectionException { taskIntersection(task); @@ -104,7 +104,7 @@ public Task createTask(Task task) { } @Override - public Task createSubtask(Subtask subtask) { + public Task createSubtask(Subtask subtask) throws IntersectionException { taskIntersection(subtask); subtask.setId(getNextId()); @@ -279,20 +279,16 @@ public void updateStartTimeForEpic(Epic epic) { } - public boolean taskIntersection(Task newTask) { + public boolean taskIntersection(Task newTask) throws IntersectionException { if (newTask.getStartTime() == null || newTask.getDuration() == null) { return false; } boolean intersection = getPrioritizedTasks().stream() .anyMatch(task -> newTask.getStartTime().isBefore(task.getEndTime()) && newTask.getEndTime().isAfter(task.getStartTime())); - ; - try { - if (intersection) { - throw new IntersectionException("Задача " + newTask.getName() + " пересекается с уже существующей"); - } - } catch (IntersectionException e) { - System.out.println(e.getMessage()); - throw new RuntimeException(); + + + if (intersection) { + throw new IntersectionException("Задача " + newTask.getName() + " пересекается с уже существующей"); } diff --git a/src/manager/TaskManager.java b/src/manager/TaskManager.java index 8220f16..61acfe4 100644 --- a/src/manager/TaskManager.java +++ b/src/manager/TaskManager.java @@ -1,5 +1,6 @@ package manager; +import exception.IntersectionException; import task.Epic; import task.Subtask; @@ -28,9 +29,9 @@ public interface TaskManager { HashMap getSubtasksFromEpic(Epic epic); - Task createTask(Task task); + Task createTask(Task task) throws IntersectionException; - Task createSubtask(Subtask subtask); + Task createSubtask(Subtask subtask) throws IntersectionException; Task createEpic(Epic epic); diff --git a/test/manager/FileBackedTaskManagerTest.java b/test/manager/FileBackedTaskManagerTest.java index af377c3..54dd2e2 100644 --- a/test/manager/FileBackedTaskManagerTest.java +++ b/test/manager/FileBackedTaskManagerTest.java @@ -1,5 +1,6 @@ package manager; +import exception.IntersectionException; import org.junit.jupiter.api.Test; import task.Epic; import task.Status; @@ -19,7 +20,7 @@ public class FileBackedTaskManagerTest { @Test - void saveInFile() throws IOException { + void saveInFile() throws IOException, IntersectionException { FileBackedTaskManager fileBackedTaskManager = new FileBackedTaskManager(Managers.getDefaultHistory(), @@ -50,7 +51,7 @@ void saveInFile() throws IOException { @Test - void loadFromFile() throws IOException { + void loadFromFile() throws IOException, IntersectionException { List loadFile = null; loadFile = Files.readAllLines(Paths.get("test/manager/TestFile.csv")); @@ -67,7 +68,7 @@ void loadFromFile() throws IOException { } @Test - void loadFromEmptyFile() throws IOException { + void loadFromEmptyFile() throws IOException, IntersectionException { FileBackedTaskManager.loadFromFile(new File("test/manager/emptyFile.csv")); diff --git a/test/manager/InMemoryHistoryManagerTest.java b/test/manager/InMemoryHistoryManagerTest.java index 89dcbc5..1cc6fa1 100644 --- a/test/manager/InMemoryHistoryManagerTest.java +++ b/test/manager/InMemoryHistoryManagerTest.java @@ -1,5 +1,6 @@ package manager; +import exception.IntersectionException; import org.junit.jupiter.api.Test; import task.Status; @@ -17,7 +18,7 @@ class InMemoryHistoryManagerTest { @Test - void HistoryManagerTest() { + void HistoryManagerTest() throws IntersectionException { List historyList = new ArrayList<>(); Task task1 = new Task(1, "Task1", "1-1", Status.NEW); Task task2 = new Task(2, "Task 2", "2-1", Status.NEW); @@ -38,7 +39,7 @@ void HistoryManagerTest() { } @Test - void HistoryManagerSizeTest() { + void HistoryManagerSizeTest() throws IntersectionException { Task task1 = new Task(1, "Task1", "1-1", Status.NEW); Task task2 = new Task(2, "Task 2", "2-1", Status.NEW); taskManager.createTask(task1); @@ -51,7 +52,7 @@ void HistoryManagerSizeTest() { } @Test - void LastTaskTest() { + void LastTaskTest() throws IntersectionException { Task task1 = new Task(1, "Task1", "1-1", Status.NEW); Task task2 = new Task(2, "Task 2", "2-1", Status.NEW); Task task3 = new Task(3, "Task 3", "3-1", Status.NEW); @@ -67,7 +68,7 @@ void LastTaskTest() { } @Test - void FirstTaskTest() { + void FirstTaskTest() throws IntersectionException { Task task1 = new Task(1, "Task1", "1-1", Status.NEW); Task task2 = new Task(2, "Task 2", "2-1", Status.NEW); Task task3 = new Task(3, "Task 3", "3-1", Status.NEW); diff --git a/test/manager/InMemoryTaskManagerTest.java b/test/manager/InMemoryTaskManagerTest.java index 4db498f..876d230 100644 --- a/test/manager/InMemoryTaskManagerTest.java +++ b/test/manager/InMemoryTaskManagerTest.java @@ -1,6 +1,7 @@ package manager; +import exception.IntersectionException; import org.junit.jupiter.api.Test; import task.Epic; import task.Status; @@ -59,14 +60,14 @@ void SubtaskInSubtask(){ @Test - void addNewTask() { + void addNewTask() throws IntersectionException { Task task = new Task("Test addNewTask", "Test addNewTask description", Status.NEW); taskManager.createTask(task); assertNotNull(taskManager.getTask(1), "Задача не найдена."); } @Test - void addNewSubtask() { + void addNewSubtask() throws IntersectionException { Subtask subtask = new Subtask("Test addNewTask", "Test addNewTask description", Status.NEW, testEpic); taskManager.createSubtask(subtask); assertNotNull(taskManager.getSubtask(1), "Задача не найдена."); @@ -80,7 +81,7 @@ void addNewEpic() { } @Test - void ConflictBetweenId() { + void ConflictBetweenId() throws IntersectionException { Task task1 = new Task(2, "Test addNewTask", "Test addNewTask description", Status.NEW); Task task2 = new Task("Test addNewTask1", "Test addNewTask description1", Status.DONE); taskManager.createTask(task1); @@ -92,7 +93,7 @@ void ConflictBetweenId() { } @Test - void addTaskInManager() { + void addTaskInManager() throws IntersectionException { Task task = new Task("Test addNewTask", "Test addNewTask description", Status.NEW); taskManager.createTask(task); assertEquals(taskManager.getTask(1).getName(), "Test addNewTask"); @@ -102,7 +103,7 @@ void addTaskInManager() { } @Test - void addSubtaskInManager() { + void addSubtaskInManager() throws IntersectionException { Subtask subtask = new Subtask(1, "Test addNewTask", "Test addNewTask description", Status.NEW, testEpic); taskManager.createSubtask(subtask); assertEquals(taskManager.getSubtask(1).getName(), "Test addNewTask"); @@ -123,7 +124,7 @@ void addEpicInManager() { } @Test - void deleteId() { + void deleteId() throws IntersectionException { Task task1 = new Task(1, "Task1", "1-1", Status.NEW); Task task2 = new Task(2, "Task 2", "2-1", Status.NEW); taskManager.createTask(task1); @@ -137,7 +138,7 @@ void deleteId() { } @Test - void deleteSubtaskFromEpic() { + void deleteSubtaskFromEpic() throws IntersectionException { Epic epic1 = new Epic(1, "Test Epic", "Test epic description", Status.NEW); Subtask subtask1 = new Subtask(2, "Subtask for epic1", "description", Status.NEW, epic1, LocalDateTime.of(2024, 2, 10, 15, 40), Duration.ofMinutes(10)); taskManager.createEpic(epic1); @@ -148,7 +149,7 @@ void deleteSubtaskFromEpic() { } @Test - void epicNewStatusTest() { + void epicNewStatusTest() throws IntersectionException { Epic epic1 = new Epic("Test Epic", "Test epic description"); Subtask subtask1 = new Subtask("Subtask-1 for epic1", "description", Status.NEW, epic1, LocalDateTime.of(2024, 2, 10, 15, 40), Duration.ofMinutes(10)); Subtask subtask2 = new Subtask("Subtask-2 for epic1", "description", Status.NEW, epic1, LocalDateTime.of(2024, 3, 10, 15, 40), Duration.ofMinutes(10)); @@ -160,7 +161,7 @@ void epicNewStatusTest() { } @Test - void epicDoneStatusTest() { + void epicDoneStatusTest() throws IntersectionException { Epic epic1 = new Epic("Test Epic", "Test epic description"); Subtask subtask1 = new Subtask("Subtask-1 for epic1", "description", Status.DONE, epic1, LocalDateTime.of(2024, 2, 10, 15, 40), Duration.ofMinutes(10)); Subtask subtask2 = new Subtask("Subtask-2 for epic1", "description", Status.DONE, epic1, LocalDateTime.of(2024, 3, 10, 15, 40), Duration.ofMinutes(10)); @@ -172,7 +173,7 @@ void epicDoneStatusTest() { } @Test - void epicMixedStatusTest() { + void epicMixedStatusTest() throws IntersectionException { Epic epic1 = new Epic("Test Epic", "Test epic description"); Subtask subtask1 = new Subtask("Subtask-1 for epic1", "description", Status.NEW, epic1, LocalDateTime.of(2024, 2, 10, 15, 40), Duration.ofMinutes(10)); Subtask subtask2 = new Subtask("Subtask-2 for epic1", "description", Status.DONE, epic1, LocalDateTime.of(2024, 3, 10, 15, 40), Duration.ofMinutes(10)); @@ -184,7 +185,7 @@ void epicMixedStatusTest() { } @Test - void epicInProgressStatusTest() { + void epicInProgressStatusTest() throws IntersectionException { Epic epic1 = new Epic("Test Epic", "Test epic description"); Subtask subtask1 = new Subtask("Subtask-1 for epic1", "description", Status.IN_PROGRESS, epic1, LocalDateTime.of(2024, 2, 10, 15, 40), Duration.ofMinutes(10)); Subtask subtask2 = new Subtask("Subtask-2 for epic1", "description", Status.IN_PROGRESS, epic1, LocalDateTime.of(2024, 3, 10, 15, 40), Duration.ofMinutes(10)); @@ -200,7 +201,7 @@ public void intersectionTest() { Task task1 = new Task("Task-1", "description", Status.NEW, LocalDateTime.of(2024, 12, 12, 10, 0), Duration.ofMinutes(600)); Task task2 = new Task("Task-2", "description", Status.NEW, LocalDateTime.of(2024, 12, 12, 10, 10), Duration.ofMinutes(10)); - assertThrows(RuntimeException.class, () -> { + assertThrows(IntersectionException.class, () -> { taskManager.createTask(task1); taskManager.createTask(task2);