NumericFormatter implements IValueFormatter { @Override public boolean acceptType(Type type, Map<String, Object> options) { if (type == null) { return false; } char signature0 = type.signature().charAt(0); return signature0 == LONG || signature0 == INT || signature0 == SHORT || signature0 == BYTE || signature0 == FLOAT || signature0 == DOUBLE; }  @Override String toString(Object obj, Map<String, Object> options); @Override Value valueOf(String value, Type type, Map<String, Object> options); @Override boolean acceptType(Type type, Map<String, Object> options); @Override Map<String, Object> getDefaultOptions(); static final String NUMERIC_FORMAT_OPTION; static final String NUMERIC_PRECISION_OPTION; }
@Test public void testAcceptType() throws Exception { LocalVariable i = this.getLocalVariable("i"); assertFalse("NumericFormatter should accept null.", formatter.acceptType(null, new HashMap<>())); assertTrue("NumericFormatter should accept int type.", formatter.acceptType(i.type(), new HashMap<>())); ObjectReference integer = this.getObjectReference("java.lang.Integer"); assertFalse("NumericFormatter should not accept Integer type.", formatter.acceptType(integer.type(), new HashMap<>())); assertFalse("NumericFormatter should not accept Object type.", formatter.acceptType(this.getLocalVariable("obj").type(), new HashMap<>())); assertFalse("NumericFormatter should not accept array type.", formatter.acceptType(this.getLocalVariable("arrays").type(), new HashMap<>())); assertFalse("NumericFormatter should not accept String type.", formatter.acceptType(this.getLocalVariable("str").type(), new HashMap<>())); VirtualMachine vm = getVM(); assertFalse("NumericFormatter should not accept boolean type.", formatter.acceptType(vm.mirrorOf(true).type(), new HashMap<>())); assertFalse("NumericFormatter should not accept char type.", formatter.acceptType(vm.mirrorOf('c').type(), new HashMap<>())); assertTrue("NumericFormatter should accept long type.", formatter.acceptType(vm.mirrorOf(1L).type(), new HashMap<>())); assertTrue("NumericFormatter should accept float type.", formatter.acceptType(vm.mirrorOf(1.2f).type(), new HashMap<>())); assertTrue("NumericFormatter should accept double type.", formatter.acceptType(vm.mirrorOf(1.2).type(), new HashMap<>())); assertTrue("NumericFormatter should accept byte type.", formatter.acceptType(vm.mirrorOf((byte)12).type(), new HashMap<>())); assertTrue("NumericFormatter should accept short type.", formatter.acceptType(vm.mirrorOf((short)12121).type(), new HashMap<>())); }