### Question:
DefaultWidgetService implements WidgetService { @Override public SearchResult<Widget> getPublishedWidgetsByFreeTextSearch(String searchTerm, int offset, int pageSize) { return getWidgetsBySearchCriteria(searchTerm, null, WidgetStatus.PUBLISHED.getWidgetStatus(), offset, pageSize); } @Autowired  DefaultWidgetService(WidgetRepository widgetRepository, UserRepository userRepository, CategoryRepository categoryRepository); @Override SearchResult<Widget> getAll(); @Override SearchResult<Widget> getLimitedList(int offset, int pageSize); @Override SearchResult<Widget> getWidgetsByFreeTextSearch(String searchTerm,
                                                           int offset, int pageSize); @Override Widget getWidget(String id); @Override SearchResult<Widget> getPublishedWidgets(int offset, int pageSize); @Override SearchResult<Widget> getPublishedWidgetsByFreeTextSearch(String searchTerm,
                                                                    int offset, int pageSize); @Override SearchResult<Widget> getWidgetsBySearchCriteria(String searchTerm, String widgetType, String widgetStatus,
                                                           int offset, int pageSize); @Override SearchResult<Widget> getWidgetsByOwner(String ownerId, int offset, int pageSize); @Override Widget getWidgetByUrl(String widgetUrl); @Override boolean isRegisteredUrl(String widgetUrl); @Override @Transactional Widget registerNewWidget(Widget widget); @Override WidgetStatistics getWidgetStatistics(String widgetId, String userId); @Override Map<String, WidgetStatistics> getAllWidgetStatistics(String userId); @Override @Transactional void updateWidget(Widget widget); @Override SearchResult<Widget> getWidgetsByTag(String tagKeyWord, int offset, int pageSize); @Override SearchResult<Widget> getWidgetsByCategory(String categoryId, int offset, int pageSize); @Override WidgetTag getWidgetTag(String id); @Override @Transactional WidgetTag createWidgetTag(String widgetId, WidgetTag widgetTag); @Override WidgetTag getWidgetTagByWidgetIdAndKeyword(String widgetId, String keyword); @Override WidgetComment getWidgetComment(String widgetId, String commentId); @Override @Transactional void createWidgetComment(String widgetId, WidgetComment widgetComment); @Override @Transactional void updateWidgetComment(String widgetId, WidgetComment widgetComment); @Override @Transactional void removeWidgetComment(String widgetId, String commentId); @Override @Transactional int deleteAllWidgetComments(String userId); @Override WidgetRating getWidgetRatingByWidgetIdAndUserId(String widgetId, String userId); @Override @Transactional void updateWidgetRatingScore(String widgetId, WidgetRating widgetRating, Integer score); @Override @Transactional void saveWidgetRating(String widgetId, WidgetRating rating); @Override @Transactional void removeWidgetRating(String widgetId, String userId); @Override @Transactional int removeAllWidgetRatings(String userId);  }### Answer:
@Test public void getPublishedWidgetsForSearchTerm() { final String searchTerm = "gAdGet"; int offset = 0; int pageSize = 10; int totalResults = 2; WidgetImpl widget = new WidgetImpl("1"); widget.setWidgetStatus(WidgetStatus.PUBLISHED); List<Widget> widgets = new ArrayList<Widget>(); widgets.add(widget); expect(widgetRepository.getCountByStatusAndTypeAndFreeText(WidgetStatus.PUBLISHED, null, searchTerm)) .andReturn(totalResults); expect(widgetRepository.getByStatusAndTypeAndFreeTextSearch(WidgetStatus.PUBLISHED, null, searchTerm, offset, pageSize)).andReturn(widgets); replay(widgetRepository); SearchResult<Widget> result = widgetService.getPublishedWidgetsByFreeTextSearch(searchTerm, offset, pageSize); assertEquals(widget, result.getResultSet().get(0)); assertEquals(totalResults, result.getTotalResults()); assertEquals(pageSize, result.getPageSize()); verify(widgetRepository); }