### Question:
MongoDbCategory extends CategoryImpl { @Override public List<Widget> getWidgets() { List<Widget> widgets = super.getWidgets(); if(widgets == null) { widgets = widgetTemplate.find(query(where("categoryIds").is(this.getId()))); super.setWidgets(widgets); } return widgets; }  MongoWidgetOperations getWidgetRepository(); void setWidgetRepository(MongoWidgetOperations widgetRepository); @Override List<Widget> getWidgets();  }### Answer:
@Test public void getWidgets_Widgets_Null() { List<Widget> widgets = new ArrayList<Widget>(); expect(widgetOperations.find(query(where("categoryIds").is(category.getId())))).andReturn(widgets); replay(widgetOperations); assertThat(category.getWidgets(), is(sameInstance(widgets))); }
@Test public void getWidgets_Widgets_Set() { List<Widget> widgets = new ArrayList<Widget>(); category.setWidgets(widgets); assertThat(category.getWidgets(), is(sameInstance(widgets))); }