DefaultDummyInstanceProvider implements DummyInstanceProvider { @Override public Object getInstance(Class<?> c10nInterface, Method method, Class<?> paramType, int paramIndex) { if (paramType.isAssignableFrom(String.class) || paramType.isAssignableFrom(CharSequence.class)) { return String.format("{%d}", paramIndex); } else if (paramType.equals(byte.class) || paramType.equals(Byte.class)) { return (byte) paramIndex; } else if (paramType.equals(short.class) || paramType.equals(Short.class)) { return (short) paramIndex; } else if (paramType.equals(int.class) || paramType.equals(Integer.class)) { return paramIndex; } else if (paramType.equals(long.class) || paramType.equals(Long.class)) { return (long) paramIndex; } else if (paramType.equals(float.class) || paramType.equals(Float.class)) { return (float) paramIndex; } else if (paramType.equals(double.class) || paramType.equals(Double.class)) { return (double) paramIndex; } else if (paramType.equals(boolean.class) || paramType.equals(Boolean.class)) { return false; } else if (paramType.equals(char.class) || paramType.equals(Character.class)) { return Character.forDigit(paramIndex, 10); } else { return null; } }  @Override Object getInstance(Class<?> c10nInterface, Method method, Class<?> paramType, int paramIndex);  }
@Test public void primitiveTypeTest() { assertThat((Byte) prov.getInstance(null, null, byte.class, 1), is((byte) 1)); assertThat((Byte) prov.getInstance(null, null, Byte.class, 1), is(Byte.valueOf((byte) 1))); assertThat((Short) prov.getInstance(null, null, short.class, 2), is((short) 2)); assertThat((Short) prov.getInstance(null, null, Short.class, 2), is(Short.valueOf((short) 2))); assertThat((Integer) prov.getInstance(null, null, int.class, 3), is(3)); assertThat((Integer) prov.getInstance(null, null, Integer.class, 3), is(Integer.valueOf(3))); assertThat((Long) prov.getInstance(null, null, long.class, 4), is(4L)); assertThat((Long) prov.getInstance(null, null, Long.class, 4), is(Long.valueOf(4L))); assertThat((Float) prov.getInstance(null, null, float.class, 5), is(5f)); assertThat((Float) prov.getInstance(null, null, Float.class, 5), is(Float.valueOf(5f))); assertThat((Double) prov.getInstance(null, null, double.class, 6), is(6d)); assertThat((Double) prov.getInstance(null, null, Double.class, 6), is(Double.valueOf(6d))); assertThat((Character) prov.getInstance(null, null, char.class, 7), is('7')); assertThat((Character) prov.getInstance(null, null, Character.class, 7), is(Character.valueOf('7'))); assertThat((Boolean) prov.getInstance(null, null, boolean.class, 8), is(false)); assertThat((Boolean) prov.getInstance(null, null, Boolean.class, 8), is(Boolean.FALSE)); }
@Test public void stringAndCharSequenceTypes() { assertThat((String) prov.getInstance(null, null, String.class, 9), is("{9}")); assertThat((CharSequence) prov.getInstance(null, null, CharSequence.class, 10), is((CharSequence) "{10}")); }
@Test public void returnsNullForUnknownObjectTypes() { assertThat(prov.getInstance(null, null, DefaultDummyInstanceProviderTest.class, 123), is(nullValue())); }