Skip to content

Commit

Permalink
Removed TaskToEvent class as it was acting as an unproductive Middle …
Browse files Browse the repository at this point in the history
…Man (#63)

* removed task to event middle man

* refactored EventScheduler dependency to interface
  • Loading branch information
ckatsube authored Nov 25, 2021
1 parent 49bc02c commit 55974d9
Show file tree
Hide file tree
Showing 6 changed files with 37 additions and 57 deletions.
5 changes: 3 additions & 2 deletions src/main/java/console_app/event_adapters/EventController.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

import services.event_creation.CalendarEventCreationBoundary;
import services.event_creation.EventSaver;
import services.event_from_task_creation.CalendarAnalyzer;
import services.event_from_task_creation.EventScheduler;
import services.event_presentation.EventGetter;
import services.event_presentation.EventInfo;
Expand All @@ -20,11 +21,11 @@
public class EventController {

private final CalendarEventCreationBoundary eventAdder;
private final EventScheduler eventScheduler;
private final CalendarAnalyzer eventScheduler;
private final EventGetter eventGetter;
private final EventSaver eventSaver;

public EventController(CalendarEventCreationBoundary eventAdder, EventScheduler eventScheduler,
public EventController(CalendarEventCreationBoundary eventAdder, CalendarAnalyzer eventScheduler,
EventGetter eventGetter, EventSaver eventSaver) {
this.eventAdder = eventAdder;
this.eventScheduler = eventScheduler;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package console_app.task_to_event_adapters;

import services.event_from_task_creation.CalendarAnalyzer;
import console_app.event_adapters.EventController;
import services.event_from_task_creation.EventScheduler;
import services.event_from_task_creation.TaskToEvent;
import services.task_presentation.TaskInfo;

import java.time.LocalDateTime;
Expand All @@ -12,8 +12,7 @@

public class TaskToEventController {

private final TaskToEvent taskToEvent = new TaskToEvent();
private final EventScheduler eventScheduler;
private final CalendarAnalyzer eventScheduler;

protected final EventController eventController;

Expand All @@ -34,8 +33,8 @@ public void suggestTimeToUser(TaskInfo task) {
Scanner scanner = new Scanner(System.in);

do {
suggestedTime = taskToEvent.getAvailableTime(
task, eventScheduler, unwantedTimes
suggestedTime = eventScheduler.getAvailableTime(
unwantedTimes, task.getDuration()
);
System.out.println("Suggested time: " + suggestedTime);
System.out.print("Type 'y' for yes, anything else for no: ");
Expand All @@ -54,6 +53,6 @@ public void suggestTimeToUser(TaskInfo task) {
* @return whether the task is successfully scheduled to event
*/
public boolean checkUserSuggestedTime(TaskInfo task, LocalDateTime userSuggestedTime) {
return taskToEvent.checkTimeAvailability(task, eventScheduler, userSuggestedTime);
return eventScheduler.isAvailable(userSuggestedTime.toLocalTime(), task.getDuration(), userSuggestedTime.toLocalDate());
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package services.event_from_task_creation;

import java.time.Duration;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.LocalTime;
import java.util.List;

public interface CalendarAnalyzer {

boolean isAvailable(LocalTime startTime, Duration timeNeeded, LocalDate date);

LocalDateTime getAvailableTime(List<LocalDateTime> timesToIgnore, Duration taskDuration);

}
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,7 @@
import java.util.Collections;
import java.util.List;

public class EventScheduler {
// private TaskToEventAuto converter;
public class EventScheduler implements CalendarAnalyzer {
private final GapFinder gapFinder;
private final CalendarManager calendarManager;

Expand Down
34 changes: 0 additions & 34 deletions src/main/java/services/event_from_task_creation/TaskToEvent.java

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import services.event_creation.CalendarEventModel;
import services.event_from_task_creation.CalendarAnalyzer;
import services.event_from_task_creation.EventScheduler;
import services.event_from_task_creation.TaskToEvent;
import services.task_presentation.TaskInfo;

import java.io.IOException;
Expand All @@ -19,36 +19,36 @@
import java.util.Set;

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertTrue;

public class TaskToEventTest {
TaskToEvent taskToEvent;
public class CalendarAnalyzerTest {
TaskInfo taskInfo;
EventScheduler scheduler;
CalendarAnalyzer scheduler;
CalendarManager manager;

@BeforeEach
void setup() {
taskToEvent = new TaskToEvent();
taskInfo = new MockTaskInfo();
manager = new MockCalendarManager();
scheduler = new EventScheduler(manager);
}

private LocalDateTime toMinutes(LocalDateTime dateTime) {
return dateTime.truncatedTo(ChronoUnit.MINUTES);
}

@Test
void getAvailableTime() {
LocalDateTime expected = scheduler.getAvailableTime(
new ArrayList<>() , taskInfo.getDuration()).truncatedTo(ChronoUnit.MINUTES);
LocalDateTime actual = taskToEvent.getAvailableTime(taskInfo, scheduler, new ArrayList<>());
assertEquals(expected, actual);
LocalDateTime actual = scheduler.getAvailableTime(new ArrayList<>(), taskInfo.getDuration());
LocalDateTime expected = LocalDateTime.now().plus(taskInfo.getDuration());
assertEquals(toMinutes(expected), toMinutes(actual));
}

@Test
void checkTimeAvailability() {
LocalDateTime userSuggestedTime = LocalDateTime.of(2021, 11, 26, 10, 0);
boolean expected = scheduler.isAvailable(userSuggestedTime.toLocalTime(), taskInfo.getDuration(),
userSuggestedTime.toLocalDate());
boolean actual = taskToEvent.checkTimeAvailability(taskInfo, scheduler, userSuggestedTime);
assertEquals(expected, actual);
boolean actual = scheduler.isAvailable(userSuggestedTime.toLocalTime(), taskInfo.getDuration(), userSuggestedTime.toLocalDate());
assertTrue(actual);
}

private static class MockTaskInfo implements TaskInfo {
Expand Down

0 comments on commit 55974d9

Please sign in to comment.