### Question:
CodecFactory { public CompressionCodecName getCodec(String name, CompressionCodecName defaultCodec) { if (name == null) return defaultCodec; try { return CompressionCodecName.fromConf(name); } catch (IllegalArgumentException ie) { try { return CompressionCodecName.fromCompressionCodec(Class.forName(name)); } catch (ClassNotFoundException ce) { throw new IllegalArgumentException(String.format("Invalid codec: %s ", name)); } } }  CompressionCodecName getCodec(String name, CompressionCodecName defaultCodec); CompressionCodec getCodec(String name, Configuration conf); Class<? extends CompressionCodec> getCodecClass(String name, Configuration conf); boolean isCodecThreadSafe(String compCodec, String dataSource, Configuration configuration); static CodecFactory getInstance();  }### Answer:
@Test public void getCodecNoName() { thrown.expect(IllegalArgumentException.class); thrown.expectMessage("Compression codec some.bad.codec was not found."); Configuration conf = new Configuration(); String name = "some.bad.codec"; factory.getCodec(name, conf); }
@Test public void getCodecNoConf() { thrown.expect(NullPointerException.class); String name = "org.apache.hadoop.io.compress.GzipCodec"; factory.getCodec(name, (Configuration) null); }
@Test public void getCodecGzip() { Configuration conf = new Configuration(); String name = "org.apache.hadoop.io.compress.GzipCodec"; CompressionCodec codec = factory.getCodec(name, conf); assertNotNull(codec); assertEquals(".gz", codec.getDefaultExtension()); }