### Question:
ConfigurationTypeHelper { public static long getMemoryAsBytes(String str) { char lastChar = str.charAt(str.length() - 1); if (lastChar == '%') { try { int percent = Integer.parseInt(str.substring(0, str.length() - 1)); if (percent <= 0 || percent >= 100) { throw new IllegalArgumentException( "The value '" + str + "' is not a valid memory setting."); } return Runtime.getRuntime().maxMemory() * percent / 100; } catch (Exception ex) { throw new IllegalArgumentException( "The value '" + str + "' is not a valid memory setting."); } } return getFixedMemoryAsBytes(str); }  static long getFixedMemoryAsBytes(String str); static long getMemoryAsBytes(String str); static long getTimeInMillis(String str); static double getFraction(String str); static T getClassInstance(String context, String clazzName, Class<T> base,
      T defaultInstance); static T getClassInstance(String context, String clazzName, Class<T> base); static int getNumThreads(String threads);  }### Answer:
@Test public void testGetMemoryInBytes() { Arrays.<Function<String,Long>>asList(ConfigurationTypeHelper::getFixedMemoryAsBytes, ConfigurationTypeHelper::getMemoryAsBytes).stream().forEach(memFunc -> { assertEquals(42L, memFunc.apply("42").longValue()); assertEquals(42L, memFunc.apply("42b").longValue()); assertEquals(42L, memFunc.apply("42B").longValue()); assertEquals(42L * 1024L, memFunc.apply("42K").longValue()); assertEquals(42L * 1024L, memFunc.apply("42k").longValue()); assertEquals(42L * 1024L * 1024L, memFunc.apply("42M").longValue()); assertEquals(42L * 1024L * 1024L, memFunc.apply("42m").longValue()); assertEquals(42L * 1024L * 1024L * 1024L, memFunc.apply("42G").longValue()); assertEquals(42L * 1024L * 1024L * 1024L, memFunc.apply("42g").longValue()); }); assertEquals(Runtime.getRuntime().maxMemory() / 10, ConfigurationTypeHelper.getMemoryAsBytes("10%")); assertEquals(Runtime.getRuntime().maxMemory() / 5, ConfigurationTypeHelper.getMemoryAsBytes("20%")); }
@Test(expected = IllegalArgumentException.class) public void testGetMemoryAsBytesFailureCases1() { ConfigurationTypeHelper.getMemoryAsBytes("42x"); }
@Test(expected = IllegalArgumentException.class) public void testGetMemoryAsBytesFailureCases2() { ConfigurationTypeHelper.getMemoryAsBytes("FooBar"); }