### Question:
SensitiveDataCodec { public String encodeData(String readable, SecurityLevel securityLevel) throws IOException { checkNotNull(readable, "input message cannot be null"); checkNotNull(securityLevel, "security level cannot be null"); StringBuilder res = new StringBuilder(); res.append(securityLevel.getPrefix()); switch (securityLevel) { case PLAIN_TEXT: res.append(readable); break; case OBFUSCATED: res.append(encryptAndBase64(readable, createObfuscatingCipher(), OBFUSCATING_KEY)); break; case ENCRYPTED: KeyPair keyPair = sensitiveDataCodecHelper.getKeyPair(); res.append( encryptAndBase64(readable, createEncryptingCipher(keyPair), keyPair.getPublic())); break; default: throw new IOException("Invalid securityLevel " + securityLevel.getPrefix()); } return res.toString(); } SensitiveDataCodec(); @VisibleForTesting  SensitiveDataCodec(SensitiveDataCodecHelper sensitiveDataCodecHelper); String encodeData(String readable, SecurityLevel securityLevel); String decodeData(String encrypted); static void main(String[] args);  }### Answer:
@Test public void testPlainTextEncode() throws IOException { SensitiveDataCodec sensitiveDataCodec = new SensitiveDataCodec(); String readable = "obf:testPlainText"; String encrypt = sensitiveDataCodec.encodeData(readable, SecurityLevel.PLAIN_TEXT); assertEquals("pl:obf:testPlainText", encrypt); }
@Test public void testEncodeWithNullInputString() throws IOException { SensitiveDataCodec sensitiveDataCodec = new SensitiveDataCodec(); thrown.expect(NullPointerException.class); thrown.expectMessage("input message cannot be null"); sensitiveDataCodec.encodeData(null, SecurityLevel.PLAIN_TEXT); }
@Test public void testEncodeWithNullSecurityLevel() throws IOException { SensitiveDataCodec sensitiveDataCodec = new SensitiveDataCodec(); thrown.expect(NullPointerException.class); thrown.expectMessage("security level cannot be null"); sensitiveDataCodec.encodeData("testtest", null); }
@Test public void testKeyEncodeDecodeNullKey() throws IOException { SensitiveDataCodec sensitiveDataCodec = new SensitiveDataCodec(); String readable = "testObfEn&c$o#de"; thrown.expect(NullPointerException.class); sensitiveDataCodec.encodeData(readable, SecurityLevel.ENCRYPTED); }