| 13 | import static org.junit.Assert.assertThat; |
| 14 | |
| 15 | public class CodeTest extends AbstractFakerTest { |
| 16 | |
| 17 | private static final ISBNValidator ISBN_VALIDATOR = ISBNValidator.getInstance(false); |
| 18 | |
| 19 | @Test |
| 20 | @Repeat(times = 1000) |
| 21 | public void isbn10DefaultIsNoSeparator() { |
| 22 | String isbn10 = faker.code().isbn10(); |
| 23 | |
| 24 | assertIsValidISBN10(isbn10); |
| 25 | assertThat(isbn10, not(containsString("-"))); |
| 26 | } |
| 27 | |
| 28 | @Test |
| 29 | @Repeat(times = 1000) |
| 30 | public void isbn13DefaultIsNoSeparator() { |
| 31 | String isbn13 = faker.code().isbn13(); |
| 32 | |
| 33 | assertIsValidISBN13(isbn13); |
| 34 | assertThat(isbn13, not(containsString("-"))); |
| 35 | } |
| 36 | |
| 37 | @Test |
| 38 | @Repeat(times = 1000) |
| 39 | public void testIsbn10() { |
| 40 | final String isbn10NoSep = faker.code().isbn10(false); |
| 41 | final String isbn10Sep = faker.code().isbn10(true); |
| 42 | |
| 43 | assertThat(isbn10NoSep + " is not null", isbn10NoSep, is(not(nullValue()))); |
| 44 | assertThat(isbn10NoSep + " has length of 10", isbn10NoSep.length(), is(10)); |
| 45 | assertIsValidISBN10(isbn10NoSep); |
| 46 | |
| 47 | assertThat(isbn10Sep + " is not null", isbn10Sep, is(not(nullValue()))); |
| 48 | assertThat(isbn10Sep + " has length of 13", isbn10Sep.length(), is(13)); |
| 49 | assertIsValidISBN10(isbn10Sep); |
| 50 | } |
| 51 | |
| 52 | @Test |
| 53 | @Repeat(times = 1000) |
| 54 | public void testIsbn13() { |
| 55 | final String isbn13NoSep = faker.code().isbn13(false); |
| 56 | final String isbn13Sep = faker.code().isbn13(true); |
| 57 | |
| 58 | assertThat(isbn13NoSep + " is not null", isbn13NoSep, is(not(nullValue()))); |
| 59 | assertThat(isbn13NoSep + " has length of 13", isbn13NoSep.length(), is(13)); |
| 60 | assertIsValidISBN13(isbn13NoSep); |
| 61 | |
| 62 | assertThat(isbn13Sep + " is not null", isbn13Sep, is(not(nullValue()))); |
| 63 | assertThat(isbn13Sep + " has length of 17", isbn13Sep.length(), is(17)); |
| 64 | assertIsValidISBN13(isbn13Sep); |
| 65 | } |
| 66 | |
| 67 | private void assertIsValidISBN10(String isbn10) { |
| 68 | assertThat(isbn10 + " is valid", ISBN_VALIDATOR.isValidISBN10(isbn10), is(true)); |
| 69 | } |
| 70 | |
| 71 | private void assertIsValidISBN13(String isbn13) { |
| 72 | assertThat(isbn13 + " is valid", ISBN_VALIDATOR.isValidISBN13(isbn13), is(true)); |
nothing calls this directly
no outgoing calls
no test coverage detected