Sampling { public static Sampling valueOf(String samplerName) { if ("off".equalsIgnoreCase(samplerName)) return OFF; if ("on".equalsIgnoreCase(samplerName)) return ON; return null; }  abstract boolean trace(); static Sampling valueOf(String samplerName); static final Sampling ON; static final Sampling OFF; }
@Test public void testSamplingValueOfString() { assertNull(Sampling.valueOf(null)); assertNull(Sampling.valueOf("unknown")); assertEquals(Sampling.ON, Sampling.valueOf("on")); assertEquals(Sampling.ON, Sampling.valueOf("ON")); assertEquals(Sampling.ON, Sampling.valueOf("oN")); assertEquals(Sampling.OFF, Sampling.valueOf("off")); assertEquals(Sampling.OFF, Sampling.valueOf("OFF")); assertEquals(Sampling.OFF, Sampling.valueOf("oFf")); }