MortarScope { public <T> T getService(String serviceName) { T service = findService(serviceName, true); if (service == null) { throw new IllegalArgumentException(format("No service found named \"%s\"", serviceName)); } return service; } MortarScope(String name, MortarScope parent, Map<String, Object> services); static MortarScope getScope(Context context); static MortarScope findChild(Context context, String name); static Builder buildChild(Context context); static boolean isDestroyed(Context context); static Builder buildRootScope(); final String getName(); String getPath(); boolean hasService(String serviceName); T getService(String serviceName); void register(Scoped scoped); MortarScope findChild(String childName); Builder buildChild(); Context createContext(Context parentContext); boolean isDestroyed(); void destroy(); @Override String toString(); static final String DIVIDER; }
@Test public void throwIfNoServiceFoundForGivenName() { Object dummyService = new Object(); MortarScope rootScope = scopeBuilder.withService("ServiceOne", dummyService).build("Root"); assertThat(rootScope.getService("ServiceOne")).isNotNull(); try { rootScope.getService("SearchThis"); fail(); } catch (IllegalArgumentException e) { assertThat(e).hasMessage("No service found named \"SearchThis\""); } }