@Test public void shouldUpdateLogoWhenLogoUpdatedByData() throws Exception { SettingService settingService = mock(SettingService.class); FileService fileService = mock(FileService.class); FileInfo fileInfo = new FileInfo(1L, "myLogo", "image/png", BrandingServiceImpl.FILE_API_NAME_SPACE, "myLogo".getBytes().length, new Date(), "john", null, false); FileItem fileItem = new FileItem(fileInfo, null); when(fileService.writeFile(any(FileItem.class))).thenReturn(fileItem); when(fileService.getFileInfo(anyLong())).thenReturn(fileInfo); UploadService uploadService = mock(UploadService.class); InitParams initParams = new InitParams(); ValueParam companyName = new ValueParam(); companyName.setName(BrandingServiceImpl.BRANDING_COMPANY_NAME_INIT_PARAM); companyName.setValue("Default Company Name"); initParams.addParam(companyName); BrandingService brandingService = new BrandingServiceImpl(initParams, settingService, fileService, uploadService); Branding newBranding = new Branding(); Logo logo = new Logo(); logo.setData("myLogo".getBytes()); logo.setSize(logo.getData().length); newBranding.setLogo(logo); ArgumentCaptor<Context> settingContextArgumentCaptor = ArgumentCaptor.forClass(Context.class); ArgumentCaptor<Scope> settingScopeArgumentCaptor = ArgumentCaptor.forClass(Scope.class); ArgumentCaptor<String> settingKeyArgumentCaptor = ArgumentCaptor.forClass(String.class); ArgumentCaptor<SettingValue> settingValueArgumentCaptor = ArgumentCaptor.forClass(SettingValue.class); ArgumentCaptor<FileItem> fileItemArgumentCaptor = ArgumentCaptor.forClass(FileItem.class); brandingService.updateBrandingInformation(newBranding); verify(settingService, times(1)).set(settingContextArgumentCaptor.capture(), settingScopeArgumentCaptor.capture(), settingKeyArgumentCaptor.capture(), settingValueArgumentCaptor.capture()); verify(fileService, times(1)).writeFile(fileItemArgumentCaptor.capture()); List<Context> contexts = settingContextArgumentCaptor.getAllValues(); List<Scope> scopes = settingScopeArgumentCaptor.getAllValues(); List<String> keys = settingKeyArgumentCaptor.getAllValues(); List<SettingValue> values = settingValueArgumentCaptor.getAllValues(); assertEquals(Context.GLOBAL, contexts.get(0)); assertEquals(Scope.GLOBAL, scopes.get(0)); assertEquals(BrandingServiceImpl.BRANDING_LOGO_ID_SETTING_KEY, keys.get(0)); assertEquals("1", values.get(0).getValue()); List<FileItem> fileItems = fileItemArgumentCaptor.getAllValues(); assertEquals("myLogo", new String(fileItems.get(0).getAsByte())); }
@Override public void updateBrandingInformation(Branding branding) throws Exception { updateCompanyName(branding.getCompanyName()); updateTopBarTheme(branding.getTopBarTheme()); updateLogo(branding.getLogo()); }
BrandingServiceImpl implements BrandingService { @Override public void updateBrandingInformation(Branding branding) throws Exception { updateCompanyName(branding.getCompanyName()); updateTopBarTheme(branding.getTopBarTheme()); updateLogo(branding.getLogo()); } }
BrandingServiceImpl implements BrandingService { @Override public void updateBrandingInformation(Branding branding) throws Exception { updateCompanyName(branding.getCompanyName()); updateTopBarTheme(branding.getTopBarTheme()); updateLogo(branding.getLogo()); } BrandingServiceImpl(InitParams initParams,SettingService settingService, FileService fileService, UploadService uploadService); }
BrandingServiceImpl implements BrandingService { @Override public void updateBrandingInformation(Branding branding) throws Exception { updateCompanyName(branding.getCompanyName()); updateTopBarTheme(branding.getTopBarTheme()); updateLogo(branding.getLogo()); } BrandingServiceImpl(InitParams initParams,SettingService settingService, FileService fileService, UploadService uploadService); @Override Branding getBrandingInformation(); @Override void updateBrandingInformation(Branding branding); @Override String getCompanyName(); @Override void updateCompanyName(String companyName); @Override String getTopBarTheme(); @Override Long getLogoId(); @Override Logo getLogo(); @Override Logo getDefaultLogo(); @Override void updateTopBarTheme(String topBarTheme); @Override void updateLogo(Logo logo); }
BrandingServiceImpl implements BrandingService { @Override public void updateBrandingInformation(Branding branding) throws Exception { updateCompanyName(branding.getCompanyName()); updateTopBarTheme(branding.getTopBarTheme()); updateLogo(branding.getLogo()); } BrandingServiceImpl(InitParams initParams,SettingService settingService, FileService fileService, UploadService uploadService); @Override Branding getBrandingInformation(); @Override void updateBrandingInformation(Branding branding); @Override String getCompanyName(); @Override void updateCompanyName(String companyName); @Override String getTopBarTheme(); @Override Long getLogoId(); @Override Logo getLogo(); @Override Logo getDefaultLogo(); @Override void updateTopBarTheme(String topBarTheme); @Override void updateLogo(Logo logo); static final String BRANDING_COMPANY_NAME_INIT_PARAM; static final String BRANDING_LOGO_INIT_PARAM; static final String BRANDING_COMPANY_NAME_SETTING_KEY; static final String BRANDING_TOPBAR_THEME_SETTING_KEY; static final String BRANDING_LOGO_ID_SETTING_KEY; static final String FILE_API_NAME_SPACE; static final String BRANDING_DEFAULT_LOGO_PATH; static String LOGO_NAME; }