### Question:
Asn1Object { public String getString() throws IOException { String encoding; switch (type) { case DerParser.NUMERIC_STRING: case DerParser.PRINTABLE_STRING: case DerParser.VIDEOTEX_STRING: case DerParser.IA5_STRING: case DerParser.GRAPHIC_STRING: case DerParser.ISO646_STRING: case DerParser.GENERAL_STRING: encoding = "ISO-8859-1"; break; case DerParser.BMP_STRING: encoding = "UTF-16BE"; break; case DerParser.UTF8_STRING: encoding = "UTF-8"; break; case DerParser.UNIVERSAL_STRING: throw new IOException("Invalid DER: can't handle UCS-4 string"); default: throw new IOException("Invalid DER: object is not a string"); } return new String(value, encoding); } Asn1Object(int tag, int length, byte[] value); int getType(); int getLength(); byte[] getValue(); boolean isConstructed(); DerParser getParser(); BigInteger getInteger(); String getString();  }### Answer:
@Test public void testGetStringType1() throws Exception { final String TEST_STRING = "my fancy test string"; Asn1Object asn1Object = new Asn1Object(DerParser.GENERAL_STRING, TEST_STRING.length(), TEST_STRING.getBytes("ISO-8859-1")); assertEquals(TEST_STRING, asn1Object.getString()); }
@Test public void testGetStringType2() throws Exception { final String TEST_STRING = "my fancy test string"; Asn1Object asn1Object = new Asn1Object(DerParser.BMP_STRING, TEST_STRING.length(), TEST_STRING.getBytes("UTF-16BE")); assertEquals(TEST_STRING, asn1Object.getString()); }
@Test public void testGetStringType3() throws Exception { final String TEST_STRING = "my fancy test string"; Asn1Object asn1Object = new Asn1Object(DerParser.UTF8_STRING, TEST_STRING.length(), TEST_STRING.getBytes("UTF-8")); assertEquals(TEST_STRING, asn1Object.getString()); }
@Test(expected=IOException.class) public void testGetStringBad1() throws Exception { final String TEST_STRING = "my fancy test string"; Asn1Object asn1Object = new Asn1Object(DerParser.UNIVERSAL_STRING, TEST_STRING.length(), TEST_STRING.getBytes()); asn1Object.getString(); }
@Test(expected=IOException.class) public void testGetStringBad2() throws Exception { final String TEST_STRING = "my fancy test string"; Asn1Object asn1Object = new Asn1Object(DerParser.INTEGER, TEST_STRING.length(), TEST_STRING.getBytes()); asn1Object.getString(); }