public void insertSessions(String eventId, LocalDate date) { LocalDateTime dateTime = date.toLocalDateTime(LocalTime.MIDNIGHT); dateTime = dateTime.plusHours(9); Session session1 = new Session(); session1.setEventId(eventId); session1.setTitle("Session 1"); session1.setTimeslot(new Interval(dateTime.toDateTime(), Minutes.minutes(60))); session1.setRoom(room1); sessionDao.saveSession(session1); dateTime = dateTime.plusHours(1); Session session2 = new Session(); session2.setEventId(eventId); session2.setTitle("Session 2"); session2.setTimeslot(new Interval(dateTime.toDateTime(), Minutes.minutes(60))); session2.setRoom(room2); sessionDao.saveSession(session2); dateTime = dateTime.plusHours(1); Session session3 = new Session(); session3.setEventId(eventId); session3.setTitle("Session 3"); session3.setTimeslot(new Interval(dateTime.toDateTime(), Minutes.minutes(60))); session3.setRoom(room3); sessionDao.saveSession(session3); }
/** * Defines the magnitudes that can be added to the timestamp * * @param token token of form "[number][magnitude]" (ex. "1d") * @return integer indicating the magnitude of the date for the calendar system */ public static ReadablePeriod getTimePeriod(String token) { String valString = token.substring(0, token.length() - 1); int value = Integer.parseInt(valString); char mag = token.charAt(token.length() - 1); ReadablePeriod period; switch (mag) { case 's': period = Seconds.seconds(value); break; case 'm': period = Minutes.minutes(value); break; case 'h': period = Hours.hours(value); break; case 'd': period = Days.days(value); break; case 'M': period = Months.months(value); break; case 'y': period = Years.years(value); break; default: logger.warn("Invalid date magnitude: {}. Defaulting to seconds.", mag); period = Seconds.seconds(value); break; } return period; }
@Test(timeout = 1000L) public void shouldNotLoopForever() throws Exception { // given final MinutesHolder minutesHolder = new MinutesHolder(); // when minutesHolder.addObserver( new Observer() { @Override public void update(Observable observable, Object data) { Minutes minutes = (Minutes) data; assertThat(minutesHolder, sameInstance(observable)); observable.deleteObserver(this); // any method that would trigger the observer minutesHolder.setMinutes(minutes); observable.addObserver(this); } }); minutesHolder.setMinutes(Minutes.minutes(1)); // then assertThat(minutesHolder.getMinutes().getMinutes(), equalTo(1)); // no StackOverflowError }