what do i do if i mock a dependency of the javautilrandom class?

Instead of using directly the java.util.Random class, create and call a MyRandomUtility class that you inject into your class.

In this class, you only need to have a method that wraps the java.util.Random class

class MyRandomUtility {

  public Int getRandom(){
      java.util.Random.nextInt().....
  }
}

And in your main class, you can include the MyRandomUtility.

In the tests, you can now easily mock it.

CLICK HERE to find out more related problems solutions.

Leave a Comment

Your email address will not be published.

Scroll to Top