DateRangeFactory { public JSONArray replaceAliases( JSONArray rangesJSONArray, Calendar calendar, JSONFactory jsonFactory) { JSONArray normalizedRangesJSONArray = jsonFactory.createJSONArray(); for (int i = 0; i < rangesJSONArray.length(); i++) { JSONObject rangeJSONObject = rangesJSONArray.getJSONObject(i); JSONObject normalizedJSONObject = jsonFactory.createJSONObject(); normalizedJSONObject.put( "label", rangeJSONObject.getString("label") ).put( "range", replaceAliases(rangeJSONObject.getString("range"), calendar) ); normalizedRangesJSONArray.put(normalizedJSONObject); } return normalizedRangesJSONArray; } DateRangeFactory(DateFormatFactory dateFormatFactory); String getRangeString(String label, Calendar calendar); String getRangeString(String from, String to); Map<String, String> getRangeStrings(Calendar calendar); JSONArray replaceAliases(
		JSONArray rangesJSONArray, Calendar calendar, JSONFactory jsonFactory); String replaceAliases(String rangeString, Calendar calendar); void validateRange(String ranges);  }
@Test public void testReplaceAliasPast24Hours() { Calendar calendar = new GregorianCalendar( 2018, Calendar.MAY, 15, 23, 59, 59); Assert.assertEquals( "[20180514235959 TO 20180515225959]", _dateRangeFactory.replaceAliases( "[past-24-hours TO past-hour]", calendar)); }
@Test public void testReplaceAliasPastHour() { Calendar calendar = new GregorianCalendar( 2018, Calendar.MAY, 15, 23, 59, 59); Assert.assertEquals( "[20180515225959 TO 20180515235959]", _dateRangeFactory.replaceAliases("[past-hour TO *]", calendar)); }
@Test public void testReplaceAliasPastMonth() { Calendar calendar = new GregorianCalendar( 2018, Calendar.MAY, 15, 23, 59, 59); Assert.assertEquals( "[20180415235959 TO 20180508235959]", _dateRangeFactory.replaceAliases( "[past-month TO past-week]", calendar)); }
@Test public void testReplaceAliasPastWeek() { Calendar calendar = new GregorianCalendar( 2018, Calendar.MAY, 15, 23, 59, 59); Assert.assertEquals( "[20180508235959 TO 20180514235959]", _dateRangeFactory.replaceAliases( "[past-week TO past-24-hours]", calendar)); }
@Test public void testReplaceAliasPastYear() { Calendar calendar = new GregorianCalendar( 2018, Calendar.MAY, 15, 23, 59, 59); Assert.assertEquals( "[20170515235959 TO 20180415235959]", _dateRangeFactory.replaceAliases( "[past-year TO past-month]", calendar)); }