@Test
public void testEncode() throws Exception {

	Assert.assertEquals(
		ByteBuffer.wrap("abc".getBytes("US-ASCII")),
		CharsetEncoderUtil.encode(
			"US-ASCII", CodingErrorAction.REPORT, CharBuffer.wrap("abc")));
	try {
		CharsetEncoderUtil.encode(
			"US-ASCII", CodingErrorAction.REPORT, CharBuffer.wrap("测试"));
		Assert.fail();
	}
	catch (UnmappableCharacterException unmappableCharacterException) {
		Assert.assertEquals(
			1, unmappableCharacterException.getInputLength());
	}
	TestCharset testCharset = new TestCharset();
	Object cache1 = ReflectionTestUtil.getAndSetFieldValue(
		Charset.class, "cache1",
		new Object[] {testCharset.name(), testCharset});
	try {
		CharsetEncoderUtil.encode(
			testCharset.name(), CharBuffer.wrap(new char[0]));
		Assert.fail();
	}
	catch (Error e) {
		Assert.assertSame(
			testCharset.getCharacterCodingException(), e.getCause());
	}
	finally {
		ReflectionTestUtil.setFieldValue(Charset.class, "cache1", cache1);
	}
}