Linked Questions

2 votes
1 answer
231 views

Have you ever encounter such a scenario: Need to test some date related functionality of your software, the software rely on OS to get current date, so we have to change the date of OS, but date &...
WestFarmer's user avatar
0 votes
0 answers
409 views

I have written a class called ErrorHandingFiniteStateMachine, which basically does something like: https://developers.google.com/safe-browsing/developers_guide_v3#RequestFrequencyHashes Basically it ...
Peter Lee's user avatar
  • 13.9k
0 votes
2 answers
96 views

In my Java application, I use several libraries which invoke System.currentTimeMillis() and Instant.now(). These functions provide the current timestamp. I would like to set the time of the ...
Yash's user avatar
  • 1,008
235 votes
3 answers
44k views

I'm using Android Studio 2.1.2 and my Java setup is the following: >java -version > openjdk version "1.8.0_91" > OpenJDK Runtime Environment (build 1.8.0_91-8u91-b14-3ubuntu1~15.10....
kael's user avatar
  • 6,765
59 votes
8 answers
159k views

I have a function that uses the current time to make some calculations. I'd like to mock it using mockito. An example of the class I'd like to test: public class ClassToTest { public long ...
Jordi P.S.'s user avatar
  • 4,048
11 votes
6 answers
19k views

For some testing purposes I would like to predict exactly what System.currentTimeMillis() will return. Is there any way in which I can freeze or manually set what will return when System....
user22098's user avatar
  • 173
17 votes
4 answers
9k views

Aside from recompiling rt.jar is there any way I can replace the currentTimeMillis() call with one of my own? 1# The right way to do it is use a Clock object and abstract time. I know it but we'...
Frankie's user avatar
  • 25.2k
11 votes
2 answers
17k views

I want to unit test some code that calls System.currentTimeMillis(). As this answer points out, a good way to do this is to replace calls to System.currentTimeMillis() with Clock.getInstance()....
mkasberg's user avatar
  • 17.7k
3 votes
3 answers
7k views

I am writing unit tests using TestNG. The problem is when I mock System.currentTimeMillis, it returns the actual value instead of the mocked one. Ideally, it should return 0L , but it returns the ...
Dawson Smith's user avatar
2 votes
2 answers
4k views

I have started to work with unit tests and still I do not know how to test somethings . My app has a method that receives 2 params, the opening and the closing time of a venue and returns true if the ...
Androider's user avatar
  • 451
-1 votes
1 answer
10k views

how to mock following code? i dont want to change my code. Date date = new Date(); String res_timestamp=new Timestamp(date.getTime()).toString(); my code: SimpleDateFormat sdf = new ...
karthick S's user avatar
3 votes
2 answers
3k views

In Joda we have setCurrentMillisFixed method which can be used to set current system time: DateTimeUtils.setCurrentMillisSystem(); In Java 8 i am trying : ZonedDateTime.now(Clock.systemDefaultZone())...
Parameswar's user avatar
  • 2,109
5 votes
2 answers
2k views

I'm using AspectJ to intercept java.net.Socket calls. I've created very simple aspect after(): call(* java.net.Socket.connect(..)) { System.out.println("Connect intercepted!"); } and aop.xml &...
stackoverflower's user avatar
1 vote
3 answers
5k views

I need to set the system clock on certain date in my tests. This way I must simulate a behavior happening that date under a test. I found this article http://www.javapractices.com/topic/TopicAction.do?...
mjgirl's user avatar
  • 1,234
2 votes
1 answer
2k views

I have this fonction: /** * @return From november to december -> current year +1 else current year */ public static int getCurrentScolYear () { int month = Calendar.getInstance().get(...
Tyvain's user avatar
  • 2,780

15 30 50 per page