@Test void testSetEvent() { Map<String, EntityData> map = new HashMap<>(); when(this.environment.getCurrentLocalDateTime()).thenReturn(LocalDateTime.of(2018, 9, 20, 00, 00)); when(alldayEntity.getString()).thenReturn("yes"); map.put("allday", alldayEntity); when(startdateEntity.getDate()).thenReturn(LocalDate.of(2018, 9, 16)); map.put("startdate", startdateEntity); when(enddateEntity.getDate()).thenReturn(LocalDate.of(2018, 9, 19)); map.put("enddate", enddateEntity); map.put("startyear", null); map.put("endyear", null); when(locationEntity.getString()).thenReturn("no"); map.put("location", locationEntity); when(descriptionEntity.getString()).thenReturn("no"); map.put("description", descriptionEntity); when(remindertimevalueEntity.getNumber()).thenReturn(20); map.put("remindertimevalue", remindertimevalueEntity); when(remindertimeunitEntity.getString()).thenReturn("days"); map.put("remindertimeunit", remindertimeunitEntity); when(titleEntity.getString()).thenReturn("Okay"); map.put("title", titleEntity); when(remindertypeEntity.getString()).thenReturn("email"); map.put("remindertype", remindertypeEntity); CalendarEvent event2 = new CalendarEvent(LocalDateTime.of(2019, 9, 17, 00, 00), LocalDateTime.of(2019, 9, 21, 00, 00), "Okay", "", "", "email", 28800, "", true); this.speech.setEvent(map); verify(this.logic).setEvent(event2); }
@Intent public String setEvent(Map<String, EntityData> entities) { boolean allDay = isAllDay(entities.get("allday").getString()); LocalDateTime start; LocalDateTime end; if (allDay) { start = LocalDateTime.of(entities.get("startdate").getDate().plusDays(1), ZERO); end = LocalDateTime.of(entities.get("enddate").getDate().plusDays(2), ZERO); } else if(entities.get("starttime") == null || entities.get("endtime") == null) { return "You have to restart the creation of a new event and please make sure that you add a time to the " + "start and to the end if you choose an non all day event."; } else { start = LocalDateTime.of(entities.get("startdate").getDate(), entities.get("starttime").getTime()); end = LocalDateTime.of(entities.get("enddate").getDate(), entities.get("endtime").getTime()); } LocalDateTime now = this.environment.getCurrentLocalDateTime(); if (entities.get("startyear") == null && entities.get("endyear") == null && start.isBefore(now)) { start = start.withYear(now.getYear() + 1); end = end.withYear(now.getYear() + 1); } if (end.isBefore(start)) { return "You have to restart the creation of a new event and please make sure that the start of the event " + "is before the end."; } String location = entities.get("location").getString(); if (location.equals("no")) { location = ""; } String description = entities.get("description").getString(); if (description.equals("no")) { description = ""; } int reminderTime = entities.get("remindertimevalue").getNumber(); String reminderTimeUnit = entities.get("remindertimeunit").getString(); if (reminderTimeUnit.equals("hours")) { reminderTime *= 60; } if (reminderTimeUnit.equals("days")) { reminderTime *= 60 * 24; } String title = entities.get("title").getString(); this.logic.setEvent(new CalendarEvent(start, end, title, location, description, entities.get("remindertype").getString(), reminderTime, "", allDay)); return "I set up the event " + title + " for you."; }
CalendarSpeech { @Intent public String setEvent(Map<String, EntityData> entities) { boolean allDay = isAllDay(entities.get("allday").getString()); LocalDateTime start; LocalDateTime end; if (allDay) { start = LocalDateTime.of(entities.get("startdate").getDate().plusDays(1), ZERO); end = LocalDateTime.of(entities.get("enddate").getDate().plusDays(2), ZERO); } else if(entities.get("starttime") == null || entities.get("endtime") == null) { return "You have to restart the creation of a new event and please make sure that you add a time to the " + "start and to the end if you choose an non all day event."; } else { start = LocalDateTime.of(entities.get("startdate").getDate(), entities.get("starttime").getTime()); end = LocalDateTime.of(entities.get("enddate").getDate(), entities.get("endtime").getTime()); } LocalDateTime now = this.environment.getCurrentLocalDateTime(); if (entities.get("startyear") == null && entities.get("endyear") == null && start.isBefore(now)) { start = start.withYear(now.getYear() + 1); end = end.withYear(now.getYear() + 1); } if (end.isBefore(start)) { return "You have to restart the creation of a new event and please make sure that the start of the event " + "is before the end."; } String location = entities.get("location").getString(); if (location.equals("no")) { location = ""; } String description = entities.get("description").getString(); if (description.equals("no")) { description = ""; } int reminderTime = entities.get("remindertimevalue").getNumber(); String reminderTimeUnit = entities.get("remindertimeunit").getString(); if (reminderTimeUnit.equals("hours")) { reminderTime *= 60; } if (reminderTimeUnit.equals("days")) { reminderTime *= 60 * 24; } String title = entities.get("title").getString(); this.logic.setEvent(new CalendarEvent(start, end, title, location, description, entities.get("remindertype").getString(), reminderTime, "", allDay)); return "I set up the event " + title + " for you."; } }
CalendarSpeech { @Intent public String setEvent(Map<String, EntityData> entities) { boolean allDay = isAllDay(entities.get("allday").getString()); LocalDateTime start; LocalDateTime end; if (allDay) { start = LocalDateTime.of(entities.get("startdate").getDate().plusDays(1), ZERO); end = LocalDateTime.of(entities.get("enddate").getDate().plusDays(2), ZERO); } else if(entities.get("starttime") == null || entities.get("endtime") == null) { return "You have to restart the creation of a new event and please make sure that you add a time to the " + "start and to the end if you choose an non all day event."; } else { start = LocalDateTime.of(entities.get("startdate").getDate(), entities.get("starttime").getTime()); end = LocalDateTime.of(entities.get("enddate").getDate(), entities.get("endtime").getTime()); } LocalDateTime now = this.environment.getCurrentLocalDateTime(); if (entities.get("startyear") == null && entities.get("endyear") == null && start.isBefore(now)) { start = start.withYear(now.getYear() + 1); end = end.withYear(now.getYear() + 1); } if (end.isBefore(start)) { return "You have to restart the creation of a new event and please make sure that the start of the event " + "is before the end."; } String location = entities.get("location").getString(); if (location.equals("no")) { location = ""; } String description = entities.get("description").getString(); if (description.equals("no")) { description = ""; } int reminderTime = entities.get("remindertimevalue").getNumber(); String reminderTimeUnit = entities.get("remindertimeunit").getString(); if (reminderTimeUnit.equals("hours")) { reminderTime *= 60; } if (reminderTimeUnit.equals("days")) { reminderTime *= 60 * 24; } String title = entities.get("title").getString(); this.logic.setEvent(new CalendarEvent(start, end, title, location, description, entities.get("remindertype").getString(), reminderTime, "", allDay)); return "I set up the event " + title + " for you."; }  }
CalendarSpeech { @Intent public String setEvent(Map<String, EntityData> entities) { boolean allDay = isAllDay(entities.get("allday").getString()); LocalDateTime start; LocalDateTime end; if (allDay) { start = LocalDateTime.of(entities.get("startdate").getDate().plusDays(1), ZERO); end = LocalDateTime.of(entities.get("enddate").getDate().plusDays(2), ZERO); } else if(entities.get("starttime") == null || entities.get("endtime") == null) { return "You have to restart the creation of a new event and please make sure that you add a time to the " + "start and to the end if you choose an non all day event."; } else { start = LocalDateTime.of(entities.get("startdate").getDate(), entities.get("starttime").getTime()); end = LocalDateTime.of(entities.get("enddate").getDate(), entities.get("endtime").getTime()); } LocalDateTime now = this.environment.getCurrentLocalDateTime(); if (entities.get("startyear") == null && entities.get("endyear") == null && start.isBefore(now)) { start = start.withYear(now.getYear() + 1); end = end.withYear(now.getYear() + 1); } if (end.isBefore(start)) { return "You have to restart the creation of a new event and please make sure that the start of the event " + "is before the end."; } String location = entities.get("location").getString(); if (location.equals("no")) { location = ""; } String description = entities.get("description").getString(); if (description.equals("no")) { description = ""; } int reminderTime = entities.get("remindertimevalue").getNumber(); String reminderTimeUnit = entities.get("remindertimeunit").getString(); if (reminderTimeUnit.equals("hours")) { reminderTime *= 60; } if (reminderTimeUnit.equals("days")) { reminderTime *= 60 * 24; } String title = entities.get("title").getString(); this.logic.setEvent(new CalendarEvent(start, end, title, location, description, entities.get("remindertype").getString(), reminderTime, "", allDay)); return "I set up the event " + title + " for you."; }  @Intent String getEvents(Map<String, EntityData> entities); @Intent String getEventsAt(Map<String, EntityData> entities); @Intent String setEvent(Map<String, EntityData> entities); String getDate(LocalDateTime date); static String ordinal(int i); String checkDate(LocalDateTime dayToCheck, CalendarEvent event, boolean withDate); String eventToString(LocalDateTime startDate, LocalDateTime endDate, CalendarEvent event, boolean withStartDate,
			boolean withEndDate, boolean withTime, OutputCase outputCase); String getCorrectTime(LocalDateTime localDateTime); LocalTime parseTo12Hour(LocalDateTime localDateTime); String dateOutput(LocalDateTime date, boolean withDate, boolean withTime); static OutputCase eventType(ChronoLocalDate date1, ChronoLocalDate date2, CalendarEvent event,
			OutputCase defaultCase); static boolean isAllDay(String allDayEntity); }
CalendarSpeech { @Intent public String setEvent(Map<String, EntityData> entities) { boolean allDay = isAllDay(entities.get("allday").getString()); LocalDateTime start; LocalDateTime end; if (allDay) { start = LocalDateTime.of(entities.get("startdate").getDate().plusDays(1), ZERO); end = LocalDateTime.of(entities.get("enddate").getDate().plusDays(2), ZERO); } else if(entities.get("starttime") == null || entities.get("endtime") == null) { return "You have to restart the creation of a new event and please make sure that you add a time to the " + "start and to the end if you choose an non all day event."; } else { start = LocalDateTime.of(entities.get("startdate").getDate(), entities.get("starttime").getTime()); end = LocalDateTime.of(entities.get("enddate").getDate(), entities.get("endtime").getTime()); } LocalDateTime now = this.environment.getCurrentLocalDateTime(); if (entities.get("startyear") == null && entities.get("endyear") == null && start.isBefore(now)) { start = start.withYear(now.getYear() + 1); end = end.withYear(now.getYear() + 1); } if (end.isBefore(start)) { return "You have to restart the creation of a new event and please make sure that the start of the event " + "is before the end."; } String location = entities.get("location").getString(); if (location.equals("no")) { location = ""; } String description = entities.get("description").getString(); if (description.equals("no")) { description = ""; } int reminderTime = entities.get("remindertimevalue").getNumber(); String reminderTimeUnit = entities.get("remindertimeunit").getString(); if (reminderTimeUnit.equals("hours")) { reminderTime *= 60; } if (reminderTimeUnit.equals("days")) { reminderTime *= 60 * 24; } String title = entities.get("title").getString(); this.logic.setEvent(new CalendarEvent(start, end, title, location, description, entities.get("remindertype").getString(), reminderTime, "", allDay)); return "I set up the event " + title + " for you."; }  @Intent String getEvents(Map<String, EntityData> entities); @Intent String getEventsAt(Map<String, EntityData> entities); @Intent String setEvent(Map<String, EntityData> entities); String getDate(LocalDateTime date); static String ordinal(int i); String checkDate(LocalDateTime dayToCheck, CalendarEvent event, boolean withDate); String eventToString(LocalDateTime startDate, LocalDateTime endDate, CalendarEvent event, boolean withStartDate,
			boolean withEndDate, boolean withTime, OutputCase outputCase); String getCorrectTime(LocalDateTime localDateTime); LocalTime parseTo12Hour(LocalDateTime localDateTime); String dateOutput(LocalDateTime date, boolean withDate, boolean withTime); static OutputCase eventType(ChronoLocalDate date1, ChronoLocalDate date2, CalendarEvent event,
			OutputCase defaultCase); static boolean isAllDay(String allDayEntity);  }