Github user vvysotskyi commented on the issue:

    https://github.com/apache/drill/pull/904
  
    @weijietong thanks for the explanation of your problem. I was able to 
reproduce it, but also I found working solution. This mock works correctly. The 
problem appears when unit test is run with other tests: 
[DateTimeZone](https://github.com/JodaOrg/joda-time/blob/ba95735daf79d00ce0928f30701d691f5e029d81/src/main/java/org/joda/time/DateTimeZone.java)
 class contains static field 
[cDefault](https://github.com/JodaOrg/joda-time/blob/ba95735daf79d00ce0928f30701d691f5e029d81/src/main/java/org/joda/time/DateTimeZone.java#L128)
 which is used to receive timezone in `testToDateForTimeStamp()` and in other 
tests. When timezone does not set to this field, but method 
[getDefault()](https://github.com/JodaOrg/joda-time/blob/ba95735daf79d00ce0928f30701d691f5e029d81/src/main/java/org/joda/time/DateTimeZone.java#L149)
 is called, value is taken from `System.getProperty()`. 
    When the first test that calls this method does not have a mock, it sets a 
real value of timezone from `System.getProperty()`. Therefore our test uses a 
unmocked value from `cDefault`. 
    
    So lets mock `DateTimeZone.getDefault()` method:
    ```
        new MockUp<DateTimeZone>() {
          @Mock
          public DateTimeZone getDefault() {
            return DateTimeZone.UTC;
          }
        };
    ```


---

Reply via email to