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.