Skip to content

Creating a MockNeat object

Andrei Ciobanu edited this page Nov 13, 2018 · 6 revisions

MockNeat is the main class of the library and the source of all evil.

To obtain a MockNeat instance:

  • Re-use the default instance of a MockNeat class that internally uses a ThreadLocalRandom implementation from the Java library.
MockNeat mock = MockNeat.threadLocal();
  • Re-use the default instance of a MockNeat class that internally uses a SecureRandom implementation from the Java library.
MockNeat mock = MockNeat.secure();
  • Re-use the default instance of a MockNeat class that internally uses the old Random class from the Java library.
MockNeat mock = MockNeat.old();
  • Call the constructor:
Long seed = 123l;
MockNeat mock = new MockNeat(RandomType.SECURE, seed);

RandomType.SECURE is the only type that supports seed. If you try to create a MockNeat object of other type (eg.: RandomType.THREAD_LOCAL) an exception will be thrown:

Exception in thread "main" java.lang.UnsupportedOperationException
	at java.base/java.util.concurrent.ThreadLocalRandom.setSeed(ThreadLocalRandom.java:191)
	at net.andreinc.mockneat.MockNeat.<init>(MockNeat.java:151)
	at net.andreinc.mockneat.examples.Secure.main(Secure.java:8)