Code Monkey home page Code Monkey logo

jvmfaketime's Introduction

jvmfaketime lets you fake System.currentTimeMillis() calls to return anything you want. Since currentTimeMillis() is the source of all time in java, the jvm time is as good as faked. This is useful for performing time dependent tests in your application.

#Usage

jvmfaketime adds additional methods to java.lang.System to let you manipulate time.

System.startFakingTime() gets you into fake time mode System.moveTimeBy(long offset) sets an offset from the current time (real or fake) by which to move time by System.resetTime() resets any offsets you've applied so you'd get the real time

For example,

System.out.println("current time: " + new Date());            

System.startFakingTime();
System.moveTimeBy(30 * 24 * 60 * 60 * 1000l);
System.out.println("faked by 30 days: " + new Date());            

outputs,

current time: Fri Nov 02 13:44:25 IST 2012
faked by 30 days: Sun Dec 02 13:44:25 IST 2012   

#Install

There are a couple of steps needed for installation.

  1. Compile jvmfaketime.c as a jni library and place it in sun.boot.library.path for your jre.
  2. Build a jar out of ClassModifer.java and place it in a bootclasspath for your jre (use -Xbootclasspath/p to specify custom bootclasspaths).

There are a couple of very rudimentary install scripts for linux and osx which probably will work. Or you can use them to write your own for your environment.

jvmfaketime's People

Stargazers

 avatar  avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.