Util { public static Map<String, String> parseMap(String str) { if (str != null) { StringTokenizer tok = new StringTokenizer(str, ", \t\n\r"); HashMap<String, String> map = new HashMap<>(); while (tok.hasMoreTokens()) { String record = tok.nextToken(); int endIndex = record.indexOf('='); if (endIndex == -1) { throw new RuntimeException("Failed to parse Map from String"); } String key = record.substring(0, endIndex); String value = record.substring(endIndex + 1); map.put(key.trim(), value.trim()); } return Collections.unmodifiableMap(map); } else { return Collections.emptyMap(); } }  static Future<T> async(Vertx vertx, Supplier<T> supplier); static Future<Void> waitFor(Vertx vertx, String logContext, String logState, long pollIntervalMs, long timeoutMs, BooleanSupplier completed); static Future<Void> waitFor(Vertx vertx, String logContext, String logState, long pollIntervalMs, long timeoutMs, BooleanSupplier completed,
                                       Predicate<Throwable> failOnError); static Map<String, String> parseMap(String str); static RuntimeException missingSecretException(String namespace, String secretName); static File createFileStore(String prefix, String suffix, byte[] bytes); static byte[] decodeFromSecret(Secret secret, String key); static File createFileTrustStore(String prefix, String suffix, X509Certificate certificate, char[] password); static void printEnvInfo(); static String maskPassword(String key, String value); @SafeVarargs static Map<String, String> mergeLabelsOrAnnotations(Map<String, String> base, Map<String, String>... overrides); static Future<T> kafkaFutureToVertxFuture(Vertx vertx, KafkaFuture<T> kf); static ConfigResource getBrokersConfig(int podId); static ConfigResource getBrokersLogging(int podId); static ConfigResource getBrokersConfig(String podId); static ConfigResource getBrokersLogging(String podId); static String stringHash(String toBeHashed); static String getLoggingDynamicallyUnmodifiableEntries(String loggingConfiguration); static String expandVars(String env); static String expandVar(String value, Map<String, String> env);  }
@Test public void testParseMap() { String stringMap = "key1=value1\n" + "key2=value2"; Map<String, String> m = parseMap(stringMap); assertThat(m, aMapWithSize(2)); assertThat(m, hasEntry("key1", "value1")); assertThat(m, hasEntry("key2", "value2")); }
@Test public void testParseMapNull() { Map<String, String> m = parseMap(null); assertThat(m, aMapWithSize(0)); }
@Test public void testParseMapEmptyString() { String stringMap = ""; Map<String, String> m = parseMap(null); assertThat(m, aMapWithSize(0)); }
@Test public void testParseMapEmptyValue() { String stringMap = "key1=value1\n" + "key2="; Map<String, String> m = parseMap(stringMap); assertThat(m, aMapWithSize(2)); assertThat(m, hasEntry("key1", "value1")); assertThat(m, hasEntry("key2", "")); }
@Test public void testParseMapInvalid() { assertThrows(RuntimeException.class, () -> { String stringMap = "key1=value1\n" + "key2"; Map<String, String> m = parseMap(stringMap); assertThat(m, aMapWithSize(2)); assertThat(m, hasEntry("key1", "value1")); assertThat(m, hasEntry("key2", "")); }); }
@Test public void testParseMapValueWithEquals() { String stringMap = "key1=value1\n" + "key2=value2=value3"; Map<String, String> m = parseMap(stringMap); assertThat(m, aMapWithSize(2)); assertThat(m, hasEntry("key1", "value1")); assertThat(m, hasEntry("key2", "value2=value3")); }