### Question:
ViewURLResourceProvider extends AbstractAuthorizedResourceProvider { protected Resource toResource(ViewURLEntity viewURLEntity) { Resource resource = new ResourceImpl(Resource.Type.ViewURL); resource.setProperty(URL_NAME,viewURLEntity.getUrlName()); resource.setProperty(URL_SUFFIX,viewURLEntity.getUrlSuffix()); ViewInstanceEntity viewInstanceEntity = viewURLEntity.getViewInstanceEntity(); if(viewInstanceEntity == null) return resource; ViewEntity viewEntity = viewInstanceEntity.getViewEntity(); String viewName = viewEntity.getCommonName(); String version = viewEntity.getVersion(); String name = viewInstanceEntity.getName(); resource.setProperty(VIEW_INSTANCE_NAME,name); resource.setProperty(VIEW_INSTANCE_VERSION,version); resource.setProperty(VIEW_INSTANCE_COMMON_NAME,viewName); return resource; } ViewURLResourceProvider(); @Override Set<Resource> getResources(Request request, Predicate predicate); @Override Map<Resource.Type, String> getKeyPropertyIds(); static final String VIEW_URL_INFO; static final String URL_NAME_PROPERTY_ID; static final String URL_SUFFIX_PROPERTY_ID; static final String VIEW_INSTANCE_VERSION_PROPERTY_ID; static final String VIEW_INSTANCE_NAME_PROPERTY_ID; static final String VIEW_INSTANCE_COMMON_NAME_PROPERTY_ID; static final String URL_NAME; static final String URL_SUFFIX; static final String VIEW_INSTANCE_VERSION; static final String VIEW_INSTANCE_NAME; static final String VIEW_INSTANCE_COMMON_NAME; }### Answer:
@Test public void testToResource() throws Exception { ViewURLResourceProvider provider = new ViewURLResourceProvider(); Set<String> propertyIds = new HashSet<>(); propertyIds.add(ViewURLResourceProvider.URL_NAME); propertyIds.add(ViewURLResourceProvider.URL_SUFFIX); ViewURLEntity viewURLEntity = createNiceMock(ViewURLEntity.class); ViewEntity viewEntity = createNiceMock(ViewEntity.class); ViewInstanceEntity viewInstanceEntity = createNiceMock(ViewInstanceEntity.class); expect(viewURLEntity.getUrlName()).andReturn("test").once(); expect(viewURLEntity.getUrlSuffix()).andReturn("url").once(); expect(viewURLEntity.getViewInstanceEntity()).andReturn(viewInstanceEntity).once(); expect(viewInstanceEntity.getViewEntity()).andReturn(viewEntity).once(); expect(viewEntity.getCommonName()).andReturn("FILES").once(); expect(viewEntity.getVersion()).andReturn("1.0.0").once(); expect(viewInstanceEntity.getName()).andReturn("test").once(); replay(viewURLEntity, viewEntity, viewInstanceEntity); Resource resource = provider.toResource(viewURLEntity); assertEquals(resource.getPropertyValue(ViewURLResourceProvider.URL_NAME),"test"); assertEquals(resource.getPropertyValue(ViewURLResourceProvider.URL_SUFFIX),"url"); assertEquals(resource.getPropertyValue(ViewURLResourceProvider.VIEW_INSTANCE_NAME),"test"); assertEquals(resource.getPropertyValue(ViewURLResourceProvider.VIEW_INSTANCE_VERSION),"1.0.0"); assertEquals(resource.getPropertyValue(ViewURLResourceProvider.VIEW_INSTANCE_COMMON_NAME),"FILES"); verify(viewURLEntity,viewInstanceEntity,viewEntity); }