### Question:
MinuteBasedStorageLocationMapper implements RelatedItemStorageLocationMapper { @Override public String getLocationName(RelatedItem product) { String dateStr = product.getDate(); String date; if(dateStr==null) { date = currentDayFormatter.getCurrentDayAndHourAndMinute(); } else { date = currentDayFormatter.parseToDateAndHourAndMinute(dateStr); } StringBuilder indexName = new StringBuilder(indexNameSize); return indexName.append(this.indexPrefixName).append(date).toString(); } MinuteBasedStorageLocationMapper(Configuration configuration,
                                            UTCCurrentDateAndHourAndMinuteFormatter dateFormatter); @Override String getLocationName(RelatedItem product);  }### Answer:
@Test public void testEmptyDateReturnsToday() { RelatedItem product = new RelatedItem("1".toCharArray(),null,null,new RelatedItemAdditionalProperties()); String name = minBasedMapper.getLocationName(product); SimpleDateFormat today = new SimpleDateFormat("yyyy-MM-dd_HH':'mm"); assertEquals(config.getStorageIndexNamePrefix() + "-" + today.format(new Date()),name); }
@Test public void testSetDateReturnsIndexNameWithGivenDate() { Date now = new Date(); SimpleDateFormat today = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ssZ"); SimpleDateFormat todayDate = new SimpleDateFormat("yyyy-MM-dd'_'HH':'mm"); RelatedItem product = new RelatedItem("1".toCharArray(),today.format(now),null,new RelatedItemAdditionalProperties()); try { Thread.sleep(2000); } catch(Exception e) { } RelatedItem product2 = new RelatedItem("1".toCharArray(),today.format(now),null,new RelatedItemAdditionalProperties()); String name = minBasedMapper.getLocationName(product); String name2 = minBasedMapper.getLocationName(product2); assertEquals(config.getStorageIndexNamePrefix() + "-" + todayDate.format(now), name); assertEquals(config.getStorageIndexNamePrefix() + "-" + todayDate.format(now),name2); RelatedItem product3 = new RelatedItem("1".toCharArray(),"1920-01-02T23:59:59+00:00",null,new RelatedItemAdditionalProperties()); name = minBasedMapper.getLocationName(product3); assertEquals(config.getStorageIndexNamePrefix() + "-1920-01-02_23:59",name); }
@Test public void testTimeZoneDate() { RelatedItem product = new RelatedItem("1".toCharArray(),"1920-01-02T01:59:59+02:00",null,new RelatedItemAdditionalProperties()); String name = minBasedMapper.getLocationName(product); assertEquals(config.getStorageIndexNamePrefix() + "-1920-01-01_23:59",name); }