### Question:
AbstractFileFormatter extends AbstractOutputFormatter implements FileFormatter { public String getFinalOutputPath() { return finalPath.toString(); }  @Override void init(QueryContext ctx, LensResultSetMetadata metadata); @Override Integer getNumRows(); @Override Long getFileSize(); @Override void writeHeader(); @Override void writeFooter(); String getFinalOutputPath(); @Override void writeExternal(ObjectOutput out); @Override void readExternal(ObjectInput in);  }### Answer:
@Test public void testFormatter() throws IOException { Configuration conf = new Configuration(); setConf(conf); testFormatter(conf, "UTF8", LensConfConstants.RESULT_SET_PARENT_DIR_DEFAULT, ".csv", getMockedResultSet()); Assert.assertEquals(readFinalOutputFile(new Path(formatter.getFinalOutputPath()), conf, "UTF-8"), getExpectedCSVRows()); }
@Test public void testCompression() throws IOException { Configuration conf = new Configuration(); conf.setBoolean(LensConfConstants.QUERY_OUTPUT_ENABLE_COMPRESSION, true); setConf(conf); testFormatter(conf, "UTF8", LensConfConstants.RESULT_SET_PARENT_DIR_DEFAULT, ".csv.gz", getMockedResultSet()); Assert.assertEquals(readCompressedFile(new Path(formatter.getFinalOutputPath()), conf, "UTF-8"), getExpectedCSVRows()); }
@Test public void testCustomCompression() throws IOException { Configuration conf = new Configuration(); conf.setBoolean(LensConfConstants.QUERY_OUTPUT_ENABLE_COMPRESSION, true); conf.set(LensConfConstants.QUERY_OUTPUT_COMPRESSION_CODEC, org.apache.hadoop.io.compress.DefaultCodec.class.getCanonicalName()); setConf(conf); testFormatter(conf, "UTF8", LensConfConstants.RESULT_SET_PARENT_DIR_DEFAULT, ".csv.deflate", getMockedResultSet()); Assert.assertEquals(readCompressedFile(new Path(formatter.getFinalOutputPath()), conf, "UTF-8"), getExpectedCSVRows()); }
@Test public void testEncoding() throws IOException { Configuration conf = new Configuration(); conf.set(LensConfConstants.QUERY_OUTPUT_CHARSET_ENCODING, "UTF-16LE"); setConf(conf); testFormatter(conf, "UnicodeLittleUnmarked", LensConfConstants.RESULT_SET_PARENT_DIR_DEFAULT, ".csv", getMockedResultSet()); Assert.assertEquals(readFinalOutputFile(new Path(formatter.getFinalOutputPath()), conf, "UTF-16LE"), getExpectedCSVRows()); }
@Test public void testCompressionAndEncoding() throws IOException { Configuration conf = new Configuration(); conf.set(LensConfConstants.QUERY_OUTPUT_CHARSET_ENCODING, "UTF-16LE"); conf.setBoolean(LensConfConstants.QUERY_OUTPUT_ENABLE_COMPRESSION, true); setConf(conf); testFormatter(conf, "UnicodeLittleUnmarked", LensConfConstants.RESULT_SET_PARENT_DIR_DEFAULT, ".csv.gz", getMockedResultSet()); Assert.assertEquals(readCompressedFile(new Path(formatter.getFinalOutputPath()), conf, "UTF-16LE"), getExpectedCSVRows()); }
@Test public void testOutputPath() throws IOException { Configuration conf = new Configuration(); String outputParent = "target/" + getClass().getSimpleName(); conf.set(LensConfConstants.RESULT_SET_PARENT_DIR, outputParent); setConf(conf); testFormatter(conf, "UTF8", outputParent, ".csv", getMockedResultSet()); Assert.assertEquals(readFinalOutputFile(new Path(formatter.getFinalOutputPath()), conf, "UTF-8"), getExpectedCSVRows()); }
@Test public void testCompressionWithCustomOutputPath() throws IOException { Configuration conf = new Configuration(); String outputParent = "target/" + getClass().getSimpleName(); conf.set(LensConfConstants.RESULT_SET_PARENT_DIR, outputParent); conf.setBoolean(LensConfConstants.QUERY_OUTPUT_ENABLE_COMPRESSION, true); setConf(conf); testFormatter(conf, "UTF8", outputParent, ".csv.gz", getMockedResultSet()); Assert.assertEquals(readCompressedFile(new Path(formatter.getFinalOutputPath()), conf, "UTF-8"), getExpectedCSVRows()); }