kl0u commented on a change in pull request #6492: [FLINK-9962] [FS connector] allow users to specify TimeZone in DateTimeBucketer URL: https://github.com/apache/flink/pull/6492#discussion_r207728642
########## File path: flink-connectors/flink-connector-filesystem/src/test/java/org/apache/flink/streaming/connectors/fs/bucketing/DateTimeBucketerTest.java ########## @@ -0,0 +1,49 @@ +package org.apache.flink.streaming.connectors.fs.bucketing; + +import org.apache.flink.streaming.connectors.fs.Clock; + +import org.apache.hadoop.fs.Path; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.powermock.api.mockito.PowerMockito; +import org.powermock.core.classloader.annotations.PrepareForTest; +import org.powermock.modules.junit4.PowerMockRunner; + +import java.util.TimeZone; + +import static org.junit.Assert.assertEquals; +import static org.mockito.Mockito.mock; +import static org.powermock.api.mockito.PowerMockito.when; + +/** + * Tests for {@link DateTimeBucketer}. + */ +@RunWith(PowerMockRunner.class) +@PrepareForTest(DateTimeBucketer.class) +public class DateTimeBucketerTest { + private static final long TEST_TIME_IN_MILLIS = 1533363082011L; + private static final Path TEST_PATH = new Path("test"); + + @Test + public void testGetBucketPathWithDefaultTimezone() { + TimeZone utc = TimeZone.getTimeZone("UTC"); + PowerMockito.mockStatic(TimeZone.class); + when(TimeZone.getDefault()).thenReturn(utc); + + DateTimeBucketer bucketer = new DateTimeBucketer(); + + Clock clock = mock(Clock.class); + when(clock.currentTimeMillis()).thenReturn(TEST_TIME_IN_MILLIS); + + assertEquals(new Path("test/2018-08-04--06"), bucketer.getBucketPath(clock, TEST_PATH, null)); + } + + @Test + public void testGetBucketPathWithSpecifiedTimezone() { + Clock clock = mock(Clock.class); + when(clock.currentTimeMillis()).thenReturn(TEST_TIME_IN_MILLIS); + DateTimeBucketer bucketer = new DateTimeBucketer(TimeZone.getTimeZone("PST")); + + assertEquals(new Path("test/2018-08-03--23"), bucketer.getBucketPath(clock, TEST_PATH, null)); + } +} Review comment: We do not need Powermock at all in these tests. We can remove all the mocks and add our own clock. ``` new Clock() { @Override public long currentTimeMillis() { return TEST_TIME_IN_MILLIS; } } ``` In general I am against mocking classes (if possible to avoid it) as this code maintainability more tricky. ---------------------------------------------------------------- This is an automated message from the Apache Git Service. To respond to the message, please log on GitHub and use the URL above to go to the specific comment. For queries about this service, please contact Infrastructure at: us...@infra.apache.org With regards, Apache Git Services