### Question:
AvroFileReaderFactory implements FileReaderFactory<T> { @Override public Iterator<T> read(FileSystem fs, final Path path) { this.mapFn.setConfigurationForTest(conf); this.mapFn.initialize(); try { FsInput fsi = new FsInput(path, fs.getConf()); final DataFileReader<T> reader = new DataFileReader<T>(fsi, recordReader); return new UnmodifiableIterator<T>() { @Override public boolean hasNext() { return reader.hasNext(); } @Override public T next() { return mapFn.map(reader.next()); } }; } catch (IOException e) { LOG.info("Could not read avro file at path: " + path, e); return Iterators.emptyIterator(); } } AvroFileReaderFactory(AvroType<T> atype, Configuration conf); @Override Iterator<T> read(FileSystem fs, final Path path);  }### Answer:
@Test public void testRead_SpecificReader() throws IOException { GenericRecord savedRecord = new GenericData.Record(Person.SCHEMA$); savedRecord.put("name", "John Doe"); savedRecord.put("age", 42); savedRecord.put("siblingnames", Lists.newArrayList("Jimmy", "Jane")); populateGenericFile(Lists.newArrayList(savedRecord), Person.SCHEMA$); AvroFileReaderFactory<Person> genericReader = new AvroFileReaderFactory<Person>( Avros.records(Person.class), new Configuration()); Iterator<Person> recordIterator = genericReader.read(FileSystem .getLocal(new Configuration()), new Path(this.avroFile.getAbsolutePath())); Person expectedPerson = new Person(); expectedPerson.setAge(42); expectedPerson.setName("John Doe"); List<CharSequence> siblingNames = Lists.newArrayList(); siblingNames.add("Jimmy"); siblingNames.add("Jane"); expectedPerson.setSiblingnames(siblingNames); Person person = recordIterator.next(); assertEquals(expectedPerson, person); assertFalse(recordIterator.hasNext()); }
@Test public void testRead_ReflectReader() throws IOException { Schema reflectSchema = ReflectData.get().getSchema(PojoPerson.class); GenericRecord savedRecord = new GenericData.Record(reflectSchema); savedRecord.put("name", "John Doe"); populateGenericFile(Lists.newArrayList(savedRecord), reflectSchema); AvroFileReaderFactory<PojoPerson> genericReader = new AvroFileReaderFactory<PojoPerson>( Avros.reflects(PojoPerson.class), new Configuration()); Iterator<PojoPerson> recordIterator = genericReader.read(FileSystem .getLocal(new Configuration()), new Path(this.avroFile.getAbsolutePath())); PojoPerson person = recordIterator.next(); assertEquals("John Doe", person.getName()); assertFalse(recordIterator.hasNext()); }
@Test public void testRead_GenericReader() throws IOException { GenericRecord savedRecord = new GenericData.Record(Person.SCHEMA$); savedRecord.put("name", "John Doe"); savedRecord.put("age", 42); savedRecord.put("siblingnames", Lists.newArrayList("Jimmy", "Jane")); populateGenericFile(Lists.newArrayList(savedRecord), Person.SCHEMA$); AvroFileReaderFactory<GenericData.Record> genericReader = new AvroFileReaderFactory<GenericData.Record>( Avros.generics(Person.SCHEMA$), new Configuration()); Iterator<GenericData.Record> recordIterator = genericReader.read( FileSystem.getLocal(new Configuration()), new Path( this.avroFile.getAbsolutePath())); GenericRecord genericRecord = recordIterator.next(); assertEquals(savedRecord, genericRecord); assertFalse(recordIterator.hasNext()); }