Files
jfaker/src/test/java/com/github/javafaker/service/RandomServiceTest.java
T
Trever Shick dee2a88a3f Ensure error messages are useful (#141)
* Add corner case test for CryptoTest

* Add RandomService tests using default constructor

* Improve FakeValueService error messaging and add tests
2016-10-17 09:30:08 +11:00

59 lines
1.6 KiB
Java

package com.github.javafaker.service;
import com.github.javafaker.AbstractFakerTest;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.Parameterized;
import java.util.Arrays;
import java.util.Collection;
import java.util.Random;
import static org.hamcrest.CoreMatchers.is;
import static org.hamcrest.Matchers.greaterThan;
import static org.hamcrest.Matchers.lessThan;
import static org.junit.Assert.assertThat;
/**
* @author pmiklos
*
*/
@RunWith(Parameterized.class)
public class RandomServiceTest extends AbstractFakerTest {
private RandomService randomService;
public RandomServiceTest(String ignoredTitle, RandomService service) {
this.randomService = service;
}
@Parameterized.Parameters(name = "Created via {0}")
public static Collection<Object[]> data() {
Object[][] data = new Object[][]{
{"RandomService(Random)", new RandomService(new Random())},
{"RandomService()", new RandomService()}
};
return Arrays.asList(data);
}
@Test(expected = IllegalArgumentException.class)
public void testPositiveBoundariesOnly() {
randomService.nextLong(0L);
}
@Test
public void testLongWithinBoundary() {
assertThat(randomService.nextLong(1), is(0L));
for (int i = 1; i < 10; i++) {
assertThat(randomService.nextLong(2), lessThan(2L));
}
}
@Test
public void testLongMaxBoundary() {
assertThat(randomService.nextLong(Long.MAX_VALUE), greaterThan(0L));
assertThat(randomService.nextLong(Long.MAX_VALUE), lessThan(Long.MAX_VALUE));
}
}