@Test public void givenFloatValue_generateDefault_shouldReturn0() { Float floatValue = 3f; float primitiveFloat = 4; Object result = defaultValueGenerator.generate(floatValue); Object primitiveResult = defaultValueGenerator.generate(primitiveFloat); assertEquals(0f, result); assertEquals(0f, primitiveResult); }
public Object generate(Object value) { if (value != null) { Class<?> clazz = value.getClass(); if (clazz.isPrimitive()) { return Defaults.defaultValue(clazz); } else { Object defaultValue = BoxedDefaults.defaultValue(clazz); if (defaultValue == null) { try { defaultValue = clazz.newInstance(); } catch (InstantiationException e) { return null; } catch (IllegalAccessException e) { return null; } } return defaultValue; } } return null; }
DefaultValueGenerator { public Object generate(Object value) { if (value != null) { Class<?> clazz = value.getClass(); if (clazz.isPrimitive()) { return Defaults.defaultValue(clazz); } else { Object defaultValue = BoxedDefaults.defaultValue(clazz); if (defaultValue == null) { try { defaultValue = clazz.newInstance(); } catch (InstantiationException e) { return null; } catch (IllegalAccessException e) { return null; } } return defaultValue; } } return null; } }
DefaultValueGenerator { public Object generate(Object value) { if (value != null) { Class<?> clazz = value.getClass(); if (clazz.isPrimitive()) { return Defaults.defaultValue(clazz); } else { Object defaultValue = BoxedDefaults.defaultValue(clazz); if (defaultValue == null) { try { defaultValue = clazz.newInstance(); } catch (InstantiationException e) { return null; } catch (IllegalAccessException e) { return null; } } return defaultValue; } } return null; }  }
DefaultValueGenerator { public Object generate(Object value) { if (value != null) { Class<?> clazz = value.getClass(); if (clazz.isPrimitive()) { return Defaults.defaultValue(clazz); } else { Object defaultValue = BoxedDefaults.defaultValue(clazz); if (defaultValue == null) { try { defaultValue = clazz.newInstance(); } catch (InstantiationException e) { return null; } catch (IllegalAccessException e) { return null; } } return defaultValue; } } return null; }  Object generate(Object value); }
DefaultValueGenerator { public Object generate(Object value) { if (value != null) { Class<?> clazz = value.getClass(); if (clazz.isPrimitive()) { return Defaults.defaultValue(clazz); } else { Object defaultValue = BoxedDefaults.defaultValue(clazz); if (defaultValue == null) { try { defaultValue = clazz.newInstance(); } catch (InstantiationException e) { return null; } catch (IllegalAccessException e) { return null; } } return defaultValue; } } return null; }  Object generate(Object value);  }