SimpleContext implements Context { @Override @SuppressWarnings("unchecked") public <T> T getService(final Class<T> serviceName) { Preconditions.checkNotNull(serviceName); final Object service = registry.get(serviceName); if (service == null) { throw new IllegalArgumentException("No service registered: " + serviceName.getCanonicalName()); } if (!serviceName.isAssignableFrom(service.getClass())) { throw new IllegalStateException( "Service " + service.getClass().getCanonicalName() + " is not of type " + serviceName.getCanonicalName()); } return (T) service; }  @Override @SuppressWarnings("unchecked") T getService(final Class<T> serviceName);  }
@Test(expected = IllegalArgumentException.class) public void gettingUnknownService_should_fail() { ctx.getService(Foo.class); }
@Test public void getTypeConversion_should_beRegistered() { assertThat(ctx.getService(TypeConversion.class), is(notNullValue())); }
@Test public void getTemplateValueFactory_should_beRegistered() { assertThat(ctx.getService(TemplateValueFactory.class), is(notNullValue())); }
@Test public void getTableTypeRepository_should_beRegistered() { assertThat(ctx.getService(TableTypeRepository.class), is(notNullValue())); }