ProvidenceConfigUtil { static boolean asBoolean(Object value) throws ProvidenceConfigException { if (value instanceof Boolean) { return (Boolean) value; } else if (value instanceof Double || value instanceof Float) { throw new ProvidenceConfigException("Unable to convert real value to boolean"); } else if (value instanceof Number) { long l = ((Number) value).longValue(); if (l == 0L) return false; if (l == 1L) return true; throw new ProvidenceConfigException("Unable to convert number " + l + " to boolean"); } throw new ProvidenceConfigException("Unable to convert " + value.getClass().getSimpleName() + " to a boolean"); } private  ProvidenceConfigUtil(); static Path canonicalFileLocation(@Nonnull Path file); static final String UNDEFINED; }
@Test public void testAsBoolean() throws ProvidenceConfigException { assertThat(asBoolean(true), is(true)); assertThat(asBoolean(1L), is(true)); assertThat(asBoolean((byte) 0), is(false)); try { asBoolean(new Object()); fail("no exception"); } catch (ProvidenceConfigException e) { assertThat(e.getMessage(), is("Unable to convert Object to a boolean")); } try { asBoolean("foo"); fail("no exception"); } catch (ProvidenceConfigException e) { assertThat(e.getMessage(), is("Unable to convert String to a boolean")); } try { asBoolean(111); fail("no exception"); } catch (ProvidenceConfigException e) { assertThat(e.getMessage(), is("Unable to convert number 111 to boolean")); } try { asBoolean(1.0); fail("no exception"); } catch (ProvidenceConfigException e) { assertThat(e.getMessage(), is("Unable to convert real value to boolean")); } }