@Test void shouldThrowForMappedClassThatIsNotChild() { ResolutionContext context = new ResolutionContext(null, new ObjectIdentifier(StandardResolutionType.SINGLETON, Number.class)); try { context.setIdentifier(new ObjectIdentifier(StandardResolutionType.SINGLETON, String.class)); fail("Expected exception to be thrown"); } catch (InjectorException e) { assertThat(e.getMessage(), containsString("New mapped class '" + String.class + "' is not a child of original class")); } }
public void setIdentifier(ObjectIdentifier identifier) { if (originalIdentifier.getTypeAsClass().isAssignableFrom(identifier.getTypeAsClass())) { this.identifier = identifier; } else { throw new InjectorException("New mapped class '" + identifier.getTypeAsClass() + "' is not a child of original class '" + originalIdentifier.getTypeAsClass() + "'"); } }
ResolutionContext { public void setIdentifier(ObjectIdentifier identifier) { if (originalIdentifier.getTypeAsClass().isAssignableFrom(identifier.getTypeAsClass())) { this.identifier = identifier; } else { throw new InjectorException("New mapped class '" + identifier.getTypeAsClass() + "' is not a child of original class '" + originalIdentifier.getTypeAsClass() + "'"); } } }
ResolutionContext { public void setIdentifier(ObjectIdentifier identifier) { if (originalIdentifier.getTypeAsClass().isAssignableFrom(identifier.getTypeAsClass())) { this.identifier = identifier; } else { throw new InjectorException("New mapped class '" + identifier.getTypeAsClass() + "' is not a child of original class '" + originalIdentifier.getTypeAsClass() + "'"); } } ResolutionContext(Injector injector, ObjectIdentifier identifier); }
ResolutionContext { public void setIdentifier(ObjectIdentifier identifier) { if (originalIdentifier.getTypeAsClass().isAssignableFrom(identifier.getTypeAsClass())) { this.identifier = identifier; } else { throw new InjectorException("New mapped class '" + identifier.getTypeAsClass() + "' is not a child of original class '" + originalIdentifier.getTypeAsClass() + "'"); } } ResolutionContext(Injector injector, ObjectIdentifier identifier); Injector getInjector(); ObjectIdentifier getOriginalIdentifier(); ObjectIdentifier getIdentifier(); List<ResolutionContext> getParents(); void setIdentifier(ObjectIdentifier identifier); ResolutionContext createChildContext(ObjectIdentifier identifier); }
ResolutionContext { public void setIdentifier(ObjectIdentifier identifier) { if (originalIdentifier.getTypeAsClass().isAssignableFrom(identifier.getTypeAsClass())) { this.identifier = identifier; } else { throw new InjectorException("New mapped class '" + identifier.getTypeAsClass() + "' is not a child of original class '" + originalIdentifier.getTypeAsClass() + "'"); } } ResolutionContext(Injector injector, ObjectIdentifier identifier); Injector getInjector(); ObjectIdentifier getOriginalIdentifier(); ObjectIdentifier getIdentifier(); List<ResolutionContext> getParents(); void setIdentifier(ObjectIdentifier identifier); ResolutionContext createChildContext(ObjectIdentifier identifier);  }