### Question:
Streams { @Deprecated public static void write(String str, final OutputStream outputStream) throws IOException { write(str, outputStream, Charset.defaultCharset()); } private  Streams(); @Deprecated static InputStream wrapString(String str); static InputStream wrapString(String str, Charset charset); @Deprecated static String readAll(final InputStream inputStream); static String readAll(final InputStream inputStream, Charset charset); @Deprecated static void write(String str, final OutputStream outputStream); static void write(String str, final OutputStream outputStream, Charset charset); static void copy(final InputStream inputStream, final OutputStream outputStream);  }### Answer:
@SuppressWarnings({"javadoc", "deprecation"}) @Test public void testWriteStringOutputStream() throws Exception { String testString = "Testing©ÿ»"; byte[] stringBytes = testString.getBytes(); stringBytes = Arrays.copyOf(stringBytes, stringBytes.length); ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); Streams.write(testString, outputStream); outputStream.close(); String expectedTestString = new String(testString.getBytes()); String actual = new String(outputStream.toByteArray()); assertEquals(expectedTestString, actual); byte[] actualBytes = Arrays.copyOf(outputStream.toByteArray(), stringBytes.length); assertTrue( "Byte arrays should be equal", Arrays.equals(stringBytes, actualBytes)); }
@Test public void testWriteStringOutputStream_wrongCharset() throws Exception { String testString = "Testing©ÿ»"; ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); Streams.write(testString, outputStream, Charset.forName(UTF_8)); byte[] stringBytes = testString.getBytes(Charset.forName(ISO_8859_1)); stringBytes = Arrays.copyOf(stringBytes, stringBytes.length); assertFalse( "Byte arrays should be not equal", Arrays.equals(stringBytes, outputStream.toByteArray())); String actual = new String(outputStream.toByteArray(), Charset.forName(UTF_8)); assertEquals(testString, actual); }
@Test public void testWriteStringOutputStream_sameCharset() throws Exception { String testString = "Testing©ÿ»"; ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); Streams.write(testString, outputStream, Charset.forName(UTF_8)); byte[] stringBytes = testString.getBytes(Charset.forName(UTF_8)); stringBytes = Arrays.copyOf(stringBytes, stringBytes.length); assertTrue( "Byte arrays shoud be equal", Arrays.equals(stringBytes, outputStream.toByteArray())); String actual = new String(outputStream.toByteArray(), Charset.forName(UTF_8)); assertEquals(testString, actual); }