### Question:
WidgetService implements IWidgetService, GroupServiceUtilizer<WidgetDto>, ServletContextAware { @Override public WidgetDto addWidget(WidgetRequest widgetRequest) { WidgetType widgetType = new WidgetType(); this.processWidgetType(widgetType, widgetRequest); WidgetType oldWidgetType = this.getWidgetManager().getWidgetType(widgetType.getCode()); BeanPropertyBindingResult bindingResult = new BeanPropertyBindingResult(widgetType, "widget"); if (null != oldWidgetType) { bindingResult.reject(WidgetValidator.ERRCODE_WIDGET_ALREADY_EXISTS, new String[]{widgetType.getCode()}, "widgettype.exists"); throw new ValidationGenericException(bindingResult); } else if (null == this.getGroupManager().getGroup(widgetRequest.getGroup())) { bindingResult.reject(WidgetValidator.ERRCODE_WIDGET_GROUP_INVALID, new String[]{widgetRequest.getGroup()}, "widgettype.group.invalid"); throw new ValidationGenericException(bindingResult); } try { this.getWidgetManager().addWidgetType(widgetType); this.createAndAddFragment(widgetType, widgetRequest); WidgetDto widgetDto = this.dtoBuilder.convert(widgetType); this.addFragments(widgetDto); return widgetDto; } catch (Exception e) { logger.error("Failed to add widget type for request {} ", widgetRequest, e); throw new RestServerError("error in add widget", e); } }  void setWidgetManager(IWidgetTypeManager widgetManager); void setPageManager(IPageManager pageManager); void setGroupManager(IGroupManager groupManager); void setGuiFragmentManager(IGuiFragmentManager guiFragmentManager); void setDtoBuilder(IDtoBuilder<WidgetType, WidgetDto> dtoBuilder); PagedMetadataMapper getPagedMetadataMapper(); void setPagedMetadataMapper(PagedMetadataMapper pagedMetadataMapper); @Override PagedMetadata<WidgetDto> getWidgets(RestListRequest restListReq); @Override WidgetDto getWidget(String widgetCode); @Override WidgetInfoDto getWidgetInfo(String widgetCode); @Override WidgetDto addWidget(WidgetRequest widgetRequest); @Override WidgetDto updateWidget(String widgetCode, WidgetRequest widgetRequest); @Override void removeWidget(String widgetCode); @Override String getManagerName(); @Override List<WidgetDto> getGroupUtilizer(String groupCode); @Override Integer getComponentUsage(String componentCode); @Override PagedMetadata<ComponentUsageEntity> getComponentUsageDetails(String componentCode, RestListRequest restListRequest); @Override void setServletContext(ServletContext srvCtx);  }### Answer:
@Test public void shouldAddNewWidget() throws Exception { WidgetRequest widgetRequest = getWidgetRequest1(); when(groupManager.getGroup(widgetRequest.getGroup())).thenReturn(mock(Group.class)); WidgetDto widgetDto = widgetService.addWidget(widgetRequest); ArgumentCaptor<WidgetType> argumentCaptor = ArgumentCaptor.forClass(WidgetType.class); verify(widgetManager).addWidgetType(argumentCaptor.capture()); WidgetType argument = argumentCaptor.getValue(); assertThat(argument.getCode()).isEqualTo(widgetRequest.getCode()); assertThat(argument.getConfigUi()).isEqualTo(objectMapper.writeValueAsString(widgetRequest.getConfigUi())); assertThat(argument.getBundleId()).isEqualTo(widgetRequest.getBundleId()); assertThat(widgetDto.getCode()).isEqualTo(widgetRequest.getCode()); assertThat(widgetDto.getConfigUi()).isEqualTo(widgetRequest.getConfigUi()); assertThat(widgetDto.getBundleId()).isEqualTo(widgetRequest.getBundleId()); }