### Question:
SensitiveDataCodec { @VisibleForTesting static String mainHelper(String[] args, InputStream in, Function<String, char[]> readPassword) throws IOException { String securityLevelStr = System.getProperty("securityLevel"); SecurityLevel securityLevel; try { securityLevel = SecurityLevel.valueOf(securityLevelStr); } catch (IllegalArgumentException e) { throw new IOException("Security level input is not valid: " + securityLevelStr + ". Please use PLAIN_TEXT, OBFUSCATED or ENCRYPTED"); } catch (NullPointerException e) { throw new IOException( "Security level is not specified. Please use PLAIN_TEXT, OBFUSCATED or ENCRYPTED"); } SensitiveDataCodec sensitiveDataCodec = new SensitiveDataCodec(); boolean isQuiet = isParameterSet(args, "--quiet"); if (isQuiet) { BufferedReader reader = new BufferedReader(new InputStreamReader(in)); return sensitiveDataCodec.encodeData(reader.readLine(), securityLevel); } else { if (readPassword == null) { return null; } char[] valueToEncode = readPassword.apply("Sensitive Value: "); String encodedValue = sensitiveDataCodec.encodeData(new String(valueToEncode), securityLevel); return "Encoded value is: " + encodedValue; } } SensitiveDataCodec(); @VisibleForTesting  SensitiveDataCodec(SensitiveDataCodecHelper sensitiveDataCodecHelper); String encodeData(String readable, SecurityLevel securityLevel); String decodeData(String encrypted); static void main(String[] args);  }### Answer:
@Test public void mainHelper_isQuiet_succeeds() throws Exception { System.setProperty("securityLevel", "PLAIN_TEXT"); String[] args = new String[] { "--quiet" }; InputStream in = new ByteArrayInputStream("password".getBytes(UTF_8)); String result = SensitiveDataCodec.mainHelper(args, in, null); assertEquals("pl:password", result); }
@Test public void mainHelper_isNotQuiet_succeeds() throws Exception { System.setProperty("securityLevel", "PLAIN_TEXT"); String[] args = new String[] {}; InputStream in = new ByteArrayInputStream(new byte[] {}); String result = SensitiveDataCodec.mainHelper(args, in, prompt -> "password".toCharArray()); assertEquals("Encoded value is: pl:password", result); }
@Test public void mainHelper_noConsole_returnsNull() throws Exception { System.setProperty("securityLevel", "PLAIN_TEXT"); String[] args = new String[] {}; InputStream in = new ByteArrayInputStream(new byte[] {}); String result = SensitiveDataCodec.mainHelper(args, in, null); assertNull(result); }