Refactor CurrentDateTimeTest

This commit is contained in:
Grzegorz Piwowarek 2016-10-10 18:54:01 +02:00
parent 9ec0893cdd
commit 798b624a90
2 changed files with 5 additions and 20 deletions

View File

@ -114,6 +114,7 @@ public class FileOperationsTest {
resultStringBuilder.append(line).append("\n"); resultStringBuilder.append(line).append("\n");
} }
} }
return resultStringBuilder.toString(); return resultStringBuilder.toString();
} }
} }

View File

@ -1,31 +1,15 @@
package com.baeldung.util; package com.baeldung.util;
import static org.junit.Assert.assertEquals; import org.junit.Test;
import static org.mockito.Mockito.when;
import java.time.Clock; import java.time.*;
import java.time.Instant;
import java.time.LocalDate;
import java.time.LocalTime;
import java.time.ZoneId;
import java.time.temporal.ChronoField; import java.time.temporal.ChronoField;
import org.junit.BeforeClass; import static org.junit.Assert.assertEquals;
import org.junit.Test;
import org.mockito.Mockito;
public class CurrentDateTimeTest { public class CurrentDateTimeTest {
private static Clock clock; private static final Clock clock = Clock.fixed(Instant.parse("2016-10-09T15:10:30.00Z"), ZoneId.of("UTC"));
@BeforeClass
public static void setup() {
final Instant currentTime = Instant.parse("2016-10-09T15:10:30.00Z");
clock = Mockito.mock(Clock.class);
when(clock.instant()).thenAnswer((invocation) -> currentTime);
when(clock.getZone()).thenAnswer((invocation) -> ZoneId.of("UTC"));
}
@Test @Test
public void shouldReturnCurrentDate() { public void shouldReturnCurrentDate() {