### Question:
SingleThreadJsonFactory extends JsonFactory { @Override public JsonGenerator createGenerator(Writer w) { throw new UnsupportedOperationException("Writer not supported. Use OutputStream"); } SingleThreadJsonFactory();  SingleThreadJsonFactory(SingleThreadJsonFactory factory, ObjectCodec codec); @Override JsonGenerator createGenerator(Writer w); @Override JsonGenerator createGenerator(File f, JsonEncoding enc); @Override JsonGenerator createGenerator(OutputStream out, JsonEncoding enc); @Override final JsonFactory setCharacterEscapes(CharacterEscapes esc); @Override JsonFactory setRootValueSeparator(String sep); @Override SingleThreadJsonFactory copy();  }### Answer:
@Test public void createFileBasedGeneratorNotSupported() { SingleThreadJsonFactory factory = new SingleThreadJsonFactory(); expectedException.expect(UnsupportedOperationException.class); expectedException.expectMessage("File not supported. Use OutputStream"); factory.createGenerator(mock(File.class), JsonEncoding.UTF8); }
@Test public void createGeneratorWithNonUtf8EncodingNotSupported() throws IOException { SingleThreadJsonFactory factory = new SingleThreadJsonFactory(); expectedException.expect(UnsupportedEncodingException.class); expectedException.expectMessage("Encoding not supported: " + JsonEncoding.UTF16_BE.getJavaName()); factory.createGenerator(mock(OutputStream.class), JsonEncoding.UTF16_BE); }
@Test public void createWriterBasedGeneratorNotSupported() { SingleThreadJsonFactory factory = new SingleThreadJsonFactory(); expectedException.expect(UnsupportedOperationException.class); expectedException.expectMessage("Writer not supported. Use OutputStream"); factory.createGenerator(mock(Writer.class)); }
@Test public void canCreateOutputStreamBasedGenerator() throws IOException { SingleThreadJsonFactory factory = new SingleThreadJsonFactory(); OutputStream os1 = mock(OutputStream.class); JsonGenerator generator1 = factory.createGenerator(os1, JsonEncoding.UTF8); assertNotNull(generator1); }
@Test public void createOutputStreamBasedGeneratorReplacesDelegateTarget() throws IOException { SingleThreadJsonFactory factory = new SingleThreadJsonFactory(); OutputStream os1 = mock(OutputStream.class); factory.createGenerator(os1, JsonEncoding.UTF8); assertSame(factory.outputStreamDelegate.getDelegate(), os1); OutputStream os2 = mock(OutputStream.class); factory.createGenerator(os2, JsonEncoding.UTF8); assertSame(factory.outputStreamDelegate.getDelegate(), os2); }
@Test public void createGeneratorCallsReturnSameInstanceEveryTime() throws IOException { SingleThreadJsonFactory factory = new SingleThreadJsonFactory(); JsonGenerator generator1 = factory.createGenerator(mock(OutputStream.class), JsonEncoding.UTF8); JsonGenerator generator2 = factory.createGenerator(mock(OutputStream.class), JsonEncoding.UTF8); assertNotNull(generator1); assertSame(generator1, generator2); }