Java 类org.joda.time.DateTimeUtils.MillisProvider 实例源码

项目:astor    文件:TestDateTimeUtils.java   
public void testMillisProviderSecurity() {
    if (OLD_JDK) {
        return;
    }
    try {
        try {
            Policy.setPolicy(RESTRICT);
            System.setSecurityManager(new SecurityManager());
            DateTimeUtils.setCurrentMillisProvider(new MillisProvider() {
                public long getMillis() {
                    return 0L;
                }
            });
            fail();
        } catch (SecurityException ex) {
            // ok
        } finally {
            System.setSecurityManager(null);
            Policy.setPolicy(ALLOW);
        }
    } finally {
        DateTimeUtils.setCurrentMillisSystem();
    }
}
项目:astor    文件:TestDateTimeUtils.java   
public void testMillisProviderSecurity() {
    if (OLD_JDK) {
        return;
    }
    try {
        try {
            Policy.setPolicy(RESTRICT);
            System.setSecurityManager(new SecurityManager());
            DateTimeUtils.setCurrentMillisProvider(new MillisProvider() {
                public long getMillis() {
                    return 0L;
                }
            });
            fail();
        } catch (SecurityException ex) {
            // ok
        } finally {
            System.setSecurityManager(null);
            Policy.setPolicy(ALLOW);
        }
    } finally {
        DateTimeUtils.setCurrentMillisSystem();
    }
}
项目:versemem-android    文件:TestDateTimeUtils.java   
public void testMillisProviderSecurity() {
    if (OLD_JDK) {
        return;
    }
    try {
        try {
            Policy.setPolicy(RESTRICT);
            System.setSecurityManager(new SecurityManager());
            DateTimeUtils.setCurrentMillisProvider(new MillisProvider() {
                public long getMillis() {
                    return 0L;
                }
            });
            fail();
        } catch (SecurityException ex) {
            // ok
        } finally {
            System.setSecurityManager(null);
            Policy.setPolicy(ALLOW);
        }
    } finally {
        DateTimeUtils.setCurrentMillisSystem();
    }
}
项目:astor    文件:TestDateTimeUtils.java   
public void testMillisProvider() {
    try {
        DateTimeUtils.setCurrentMillisProvider(new MillisProvider() {
            public long getMillis() {
                return 1L;
            }
        });
        assertEquals(1L, DateTimeUtils.currentTimeMillis());
    } finally {
        DateTimeUtils.setCurrentMillisSystem();
    }
}
项目:astor    文件:TestDateTimeUtils.java   
public void testMillisProvider() {
    try {
        DateTimeUtils.setCurrentMillisProvider(new MillisProvider() {
            public long getMillis() {
                return 1L;
            }
        });
        assertEquals(1L, DateTimeUtils.currentTimeMillis());
    } finally {
        DateTimeUtils.setCurrentMillisSystem();
    }
}
项目:versemem-android    文件:TestDateTimeUtils.java   
public void testMillisProvider() {
    try {
        DateTimeUtils.setCurrentMillisProvider(new MillisProvider() {
            public long getMillis() {
                return 1L;
            }
        });
        assertEquals(1L, DateTimeUtils.currentTimeMillis());
    } finally {
        DateTimeUtils.setCurrentMillisSystem();
    }
}
项目:timemachine    文件:TimeMachine.java   
/**
 * Runs the given {@link Block} in the date and time given when constructing
 * the TimeMachine. A {@link DateTime} created inside the given code will
 * have always the same value, equal to the DateTime given when constructing
 * the TimeMachine.
 *
 * @param code
 *            The code to be run in a different date and time
 * @return The result of running the given code
 */
public <T> T andExecute(Block<T> code) {
    MillisProvider provider = getCurrentTimeMillisProvider();
    DateTimeUtils.setCurrentMillisFixed(somewhereInTime.getMillis());
    try {
        return code.run();
    } finally {
        DateTimeUtils.setCurrentMillisProvider(provider);
    }
}