BooleanFormatter implements IValueFormatter { @Override public Value valueOf(String value, Type type, Map<String, Object> options) { VirtualMachine vm = type.virtualMachine(); return vm.mirrorOf(Boolean.parseBoolean(value)); }  @Override String toString(Object value, Map<String, Object> options); @Override boolean acceptType(Type type, Map<String, Object> options); @Override Value valueOf(String value, Type type, Map<String, Object> options);  }
@Test public void testValueOf() throws Exception { Map<String, Object> options = formatter.getDefaultOptions(); Value boolVar = getVM().mirrorOf(true); Value newValue = formatter.valueOf("true", boolVar.type(), options); assertTrue("should return boolean type", newValue instanceof BooleanValue); assertTrue("should return boolean type", ((BooleanValue)newValue).value()); assertEquals("Should be able to restore boolean value.", "true", formatter.toString(newValue, options)); newValue = formatter.valueOf("True", boolVar.type(), options); assertTrue("should return boolean type", newValue instanceof BooleanValue); assertTrue("should return boolean type", ((BooleanValue)newValue).value()); newValue = formatter.valueOf("false", boolVar.type(), options); assertTrue("should return boolean type", newValue instanceof BooleanValue); assertFalse("should return boolean 'false'", ((BooleanValue)newValue).value()); newValue = formatter.valueOf("False", boolVar.type(), options); assertTrue("should return boolean type", newValue instanceof BooleanValue); assertFalse("should return boolean 'false'", ((BooleanValue)newValue).value()); newValue = formatter.valueOf("abc", boolVar.type(), options); assertTrue("should return boolean type", newValue instanceof BooleanValue); assertFalse("should return boolean 'false'", ((BooleanValue)newValue).value()); }