@Test
  public void castingStaticFieldInjection() throws Exception {
    final Field field = CastingInjectorTestCase.class.getField("stringField");
    final Injector<String> fieldInjector =
        new FieldInjector<String>(
            Values.<CastingInjectorTestCase>nullValue(), Values.immediateValue(field));
    final Injector<Object> castingInjector =
        new CastingInjector<String>(fieldInjector, String.class);
    castingInjector.inject("injection");
    assertEquals("injection", stringField);
    castingInjector.uninject();
    assertNull(stringField);

    castingInjector.inject(null);
    assertNull(listField);

    castingInjector.inject("");
    assertEquals("", stringField);

    try {
      castingInjector.inject(new StringBuffer());
      fail("InjectionException expected");
    } catch (InjectionException e) {
    }
  }
  @Test
  public void nullCastingInjector() throws Exception {
    final Field field = CastingInjectorTestCase.class.getField("stringField");
    final Injector<String> fieldInjector =
        new FieldInjector<String>(
            Values.<CastingInjectorTestCase>nullValue(), Values.immediateValue(field));
    Injector<Object> castingInjector = new CastingInjector<String>(null, String.class);
    try {
      castingInjector.inject("injection");
      fail("NullPointerException expected");
    } catch (NullPointerException e) {
    }

    castingInjector = new CastingInjector<String>(fieldInjector, null);
    try {
      castingInjector.inject("injection");
      fail("NullPointerException expected");
    } catch (NullPointerException e) {
    }

    castingInjector = new CastingInjector<String>(null, null);
    try {
      castingInjector.inject("injection");
      fail("NullPointerException expected");
    } catch (NullPointerException e) {
    }
  }
 private static Injector<Object> getPropertyInjector(
     final String propertyName,
     final List<ClassReflectionIndex> mBeanClassHierarchy,
     final Service<?> service,
     final Value<?> value) {
   final Method setterMethod = ReflectionUtils.getSetter(mBeanClassHierarchy, propertyName);
   return new MethodInjector<Object>(
       setterMethod, service, Values.nullValue(), Collections.singletonList(value));
 }