-
-
Notifications
You must be signed in to change notification settings - Fork 47
Creating a MockNeat object
Andrei Ciobanu edited this page Jan 10, 2019
·
6 revisions
Important Note: The library the documentation has moved to www.mockneat.com. The information found on this wiki is quite outdated. Please check the new site.
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 seeding.
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)
Using the library:
Real World Examples: