WidgetFileBasedLoader extends JsonFileBasedLoader<Widget> { @Override public List<Widget> findByObjectId(Path directory, String objectId) throws IOException { List<Widget> findIn = new ArrayList<>(); List<Widget> widgets = getAll(directory); for (Widget otherWidget : widgets) { if (otherWidget.getTemplate().contains("<" + Widget.spinalCase(objectId))) { findIn.add(otherWidget); } } return findIn; } @Inject  WidgetFileBasedLoader(JacksonObjectMapper objectMapper); @Override Widget get(Path path); @Override List<Widget> findByObjectId(Path directory, String objectId); @Override boolean contains(Path directory, String widgetId); List<Widget> loadAllCustom(Path widgetsFolder); @Override Widget getByUUID(Path directory, String uuid); @Override Widget load(Path path);  }
@Test public void should_find_widget_which_not_use_another_widget() throws Exception { Widget input = aWidget().id("input").build(); Widget label = aWidget().id("label").template("use <input>").build(); addToDirectory(widgetDirectory, input, label); assertThat(widgetLoader.findByObjectId(widgetDirectory, "label")).isEmpty(); }