### Question:
Reader { public static <T> ReaderBuilder<T> of(Class<T> clazz) { return new ReaderBuilder<>(clazz); }  static String[] columnsOf(Class<T> clazz); static ReaderBuilder<T> of(Class<T> clazz);  }### Answer:
@Test public void testShouldThrowOnDuplicateIndex() { thrown.expect(ZeroCellException.class); thrown.expectMessage("Cannot map two columns to the same index: 0"); Reader.of(DuplicateIndex.class) .from(new File("src/test/resources/test_people.xlsx")) .sheet("uploads") .list(); }
@Test public void testShouldThrowOnIncorrectColumnName() { thrown.expect(ZeroCellException.class); thrown.expectMessage("Expected Column 'DOB' but found 'DATE_OF_BIRTH'"); Reader.of(Person2.class) .from(new File("src/test/resources/test_people.xlsx")) .sheet("uploads") .list(); }
@Test public void testShouldThrowForNonOpenXMLFile() throws IOException { File file = temporaryFolder.newFile(); thrown.expect(ZeroCellException.class); thrown.expectMessage("Cannot load file. The file must be an Excel 2007+ Workbook (.xlsx)"); Reader.of(Person.class) .from(file) .sheet("uploads") .list(); }
@Test public void testShouldExtractPeopleFromFile() { List<Person> people = Reader.of(Person.class) .from(new File("src/test/resources/test_people.xlsx")) .sheet("uploads") .list(); assertNotNull(people); assertFalse(people.isEmpty()); assertEquals(5, people.size()); Person zikani = people.get(0); assertEquals(1, zikani.getRowNumber()); assertEquals("Zikani", zikani.getFirstName()); }
@Test public void testShouldSkipFirst3RowsFromFile() { List<Person> people = Reader.of(Person.class) .from(new File("src/test/resources/test_people_with_offset_header.xlsx")) .sheet("uploads") .skipFirstNRows(3) .list(); assertNotNull(people); assertFalse(people.isEmpty()); assertEquals(5, people.size()); Person zikani = people.get(0); assertEquals(1, zikani.getRowNumber()); assertEquals("Zikani", zikani.getFirstName()); }
@Test public void testShouldReadFromInputStream() throws IOException { InputStream inputStream = Files.newInputStream( Paths.get("src", "test", "resources", "test_people.xlsx")); List<Person> persons = Reader.of(Person.class) .from(inputStream) .sheet("uploads") .using( new RowNumberInfo("rowNumber", Integer.class), new ColumnInfo("ID", "id", 0, String.class), new ColumnInfo("FIRST_NAME", "firstName", 1, String.class), new ColumnInfo("MIDDLE_NAME", "middleName", 2, String.class), new ColumnInfo("LAST_NAME", "lastName", 3, String.class), new ColumnInfo("DATE_OF_BIRTH", "dateOfBirth", 4, LocalDate.class), new ColumnInfo("FAV_NUMBER", "favouriteNumber", 5, Integer.class), new ColumnInfo("DATE_REGISTERED", "dateOfRegistration", 6, Date.class) ) .list(); assertNotNull(persons); assertSame(5, persons.size()); assertEquals("Mwafulirwa", persons.get(2).getLastName()); assertEquals(1, persons.get(4).getFavouriteNumber()); }
@Test public void testShouldThrowOnInvalidSheetName() { thrown.expect(ZeroCellException.class); thrown.expectMessage("Could not find sheet INVALID_SHEET_NAME"); Reader.of(Person.class) .from(new File("src/test/resources/test_people.xlsx")) .sheet("INVALID_SHEET_NAME") .list(); }