Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- @Test
- public void testGetDeliveryDateEightDaysAndHoliday ()
- {
- new NonStrictExpectations( product )
- {
- {
- product.getDeliveryDays( 1, 1 );
- result = 8;
- }
- };
- Clock clock = Clock.fixed( Instant.parse( "2017-06-29T12:30:00.00Z" ), ZoneId.of( "UTC" ) );
- Date deliveryDate = product.getDeliveryDate( 1, 1, clock );
- Calendar cal = Calendar.getInstance();
- cal.setTime( deliveryDate );
- int day = cal.get( Calendar.DAY_OF_MONTH );
- Assert.assertEquals( 11, day );
- }
- public Date getDeliveryDate ( final int contextId, final int quantity, Clock clock )
- {
- Date returnValue = null;
- int daysToAdd = quantity > 0 ? getDeliveryDays( contextId, quantity ) : getDeliveryDays( contextId );
- final DeliveryBlock block = DeliveryBlockManager.getInstance().getDeliveryBlock( getClientId(), contextId );
- LocalDateTime localDateTime = LocalDateTime.now(clock);
- if ( block != null && block.isValid( Date.from(localDateTime.atZone(ZoneId.systemDefault()).toInstant()) ) )
- {
- daysToAdd = localDateTime.getHour() < DELIVERY_TIME_LAST_HOUR ? daysToAdd - 1 : daysToAdd;
- }
- if ( daysToAdd <= 0 )
- {
- returnValue = Date.from( getNextDate( localDateTime, block ).atZone( ZoneId.systemDefault() ).toInstant() );
- }
- else
- {
- LocalDateTime deliveryDate = Stream
- .iterate( getNextDate( localDateTime, block ), t -> getNextDate( t, block ) ).limit( daysToAdd )
- .reduce( ( a, b ) -> b ).orElse( getNextDate( LocalDateTime.now(), block ) );
- returnValue = Date.from( deliveryDate.atZone( ZoneId.systemDefault() ).toInstant() );
- }
- return returnValue;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement