@Override public boolean supports( final Path path ) { return resourceType.accept( path ); }
@Override public Collection<PathPlaceRequest> getActivitiesForResourceType(final ResourceTypeDefinition type) { final ArrayList<PathPlaceRequest> activities = new ArrayList<>(); for (final PlaceRequest placeRequest : existingWorkbenchActivities.keySet()) { if (placeRequest instanceof PathPlaceRequest) { final PathPlaceRequest ppr = (PathPlaceRequest) placeRequest; if (type.accept(ppr.getPath())) { activities.add(ppr); } } } return unmodifiableCollection(activities); }
private boolean isSupportedByAnyResourceType(Path path) { org.uberfire.backend.vfs.Path convertedPath = convertPath(path); return this.getVisibleResourceTypes() .stream() .anyMatch(resourceTypeDefinition -> resourceTypeDefinition.accept(convertedPath)); }
@Before public void setup() { ResourceTypeDefinition resourceTypeDefinition = mock(ResourceTypeDefinition.class); when(resourceTypeDefinition.accept(any())).thenReturn(isAccepted); final Path p = mock(Path.class); when(p.getFileName()).thenReturn(fileName); this.definition = spy(new LibraryIndexer()); doReturn(this.isFolder).when(this.definition).isFolder(any()); doReturn(new HashSet<>(Arrays.asList(resourceTypeDefinition))).when(this.definition).getVisibleResourceTypes(); doReturn(p).when(this.definition).convertPath(any()); doReturn(fileName.startsWith(".")).when(this.definition).isHidden(any()); }
@Test public void testGetActivitiesForResourceType_NoMatches() throws Exception { final ObservablePath path = mock(ObservablePath.class); final PathPlaceRequest yellowBrickRoad = new FakePathPlaceRequest(path); final WorkbenchScreenActivity ozActivity = mock(WorkbenchScreenActivity.class); when(activityManager.getActivities(yellowBrickRoad)).thenReturn(singleton((Activity) ozActivity)); when(ozActivity.isType(ActivityResourceType.SCREEN.name())).thenReturn(true); placeManager.goTo(yellowBrickRoad); verifyActivityLaunchSideEffects(yellowBrickRoad, ozActivity, null); final ResourceTypeDefinition resourceType = mock(ResourceTypeDefinition.class); when(resourceType.accept(path)).thenReturn(false); final Collection<PathPlaceRequest> resolvedActivities = placeManager .getActivitiesForResourceType(resourceType); assertNotNull(resolvedActivities); assertEquals(0, resolvedActivities.size()); }
@Test public void testGetActivitiesForResourceType_NoMatches() throws Exception { final ObservablePath path = mock(ObservablePath.class); final PathPlaceRequest yellowBrickRoad = new FakePathPlaceRequest(path); final WorkbenchScreenActivity ozActivity = mock(WorkbenchScreenActivity.class); when(activityManager.getActivities(yellowBrickRoad)).thenReturn(singleton((Activity) ozActivity)); when(ozActivity.isType(ActivityResourceType.SCREEN.name())).thenReturn(true); placeManager.goTo(yellowBrickRoad); verifyActivityLaunchSideEffects(yellowBrickRoad, ozActivity, null); final ResourceTypeDefinition resourceType = mock(ResourceTypeDefinition.class); when(resourceType.accept(path)).thenReturn(false); final Collection<PathPlaceRequest> resolvedActivities = placeManager .getActivitiesForResourceType(resourceType); assertNotNull(resolvedActivities); assertEquals(0, resolvedActivities.size()); }
@Test public void testGetActivitiesForResourceType_Matches() throws Exception { final ObservablePath path = mock(ObservablePath.class); final PathPlaceRequest yellowBrickRoad = new FakePathPlaceRequest(path); final WorkbenchScreenActivity ozActivity = mock(WorkbenchScreenActivity.class); when(activityManager.getActivities(yellowBrickRoad)).thenReturn(singleton((Activity) ozActivity)); when(ozActivity.isType(ActivityResourceType.SCREEN.name())).thenReturn(true); placeManager.goTo(yellowBrickRoad); verifyActivityLaunchSideEffects(yellowBrickRoad, ozActivity, null); final ResourceTypeDefinition resourceType = mock(ResourceTypeDefinition.class); when(resourceType.accept(path)).thenReturn(true); final Collection<PathPlaceRequest> resolvedActivities = placeManager .getActivitiesForResourceType(resourceType); assertNotNull(resolvedActivities); assertEquals(1, resolvedActivities.size()); try { resolvedActivities.clear(); fail("PlaceManager.getActivitiesForResourceType() should return an unmodifiable collection."); } catch (UnsupportedOperationException uoe) { //This is correct. The result should be an unmodifiable collection } }
@Test public void testGetActivitiesForResourceType_Matches() throws Exception { final ObservablePath path = mock(ObservablePath.class); final PathPlaceRequest yellowBrickRoad = new FakePathPlaceRequest(path); final WorkbenchScreenActivity ozActivity = mock(WorkbenchScreenActivity.class); when(activityManager.getActivities(yellowBrickRoad)).thenReturn(singleton((Activity) ozActivity)); when(ozActivity.isType(ActivityResourceType.SCREEN.name())).thenReturn(true); placeManager.goTo(yellowBrickRoad); verifyActivityLaunchSideEffects(yellowBrickRoad, ozActivity, null); final ResourceTypeDefinition resourceType = mock(ResourceTypeDefinition.class); when(resourceType.accept(path)).thenReturn(true); final Collection<PathPlaceRequest> resolvedActivities = placeManager .getActivitiesForResourceType(resourceType); assertNotNull(resolvedActivities); assertEquals(1, resolvedActivities.size()); try { resolvedActivities.clear(); fail("PlaceManager.getActivitiesForResourceType() should return an unmodifiable collection."); } catch (UnsupportedOperationException uoe) { //This is correct. The result should be an unmodifiable collection } }