### Question:
KVUtils { public static Long getLongValue(KVPairs kv, Long defaultValue, String... keys) { String v = findFirstNonNullValue(kv, keys); try { return v == null ? defaultValue : Long.parseLong(v); } catch (Exception e) { return defaultValue; } }  static String getValue(KVPairs kv, String defaultValue, String... keys); static Long getLongValue(KVPairs kv, Long defaultValue, String... keys); static boolean getBooleanValue(KVPairs kv, boolean defaultValue, String... keys); static Optional<String> getValueOpt(KVPairs kv, String key);  }### Answer:
@Test public void getLongValue() { kv.add("foo", "1"); kv.add("toto", "2"); assertEquals("primary key", new Long(1), KVUtils.getLongValue(kv, 0L, "foo", "toto")); assertEquals("secondary key", new Long(2), KVUtils.getLongValue(kv, 0L, "bogus", "toto")); assertEquals("default value", new Long(0), KVUtils.getLongValue(kv, 0L, "bogus", "bogus_too")); }
@Test public void getLongValue_FirstIsUsed() { kv.add("foo", "bogus_number"); kv.add("toto", "2"); assertEquals(new Long(0), KVUtils.getLongValue(kv, 0L, "foo", "toto")); }