@Test public void exists() { boolean exists = container.exists(location); assertFalse(exists); when(workspace.hasResource(location)).thenReturn(true); exists = container.exists(location); assertTrue(exists); }
@Before public void setUp() throws Exception { MockitoAnnotations.initMocks(this); when(workspace.getRepository()).thenReturn(repository); when(workspace.getRoot()).thenReturn(root); when(workspace.getLocation()).thenReturn(location); when(repository.getCollection(anyString())).thenReturn(expectedEntity); when(root.getLocation()).thenReturn(path); when(root.toString()).thenReturn(""); when(path.append(any(IPath.class))).thenReturn(path); when(path.append(anyString())).thenReturn(path); when(location.append(any(IPath.class))).thenReturn(location); when(location.append(anyString())).thenReturn(location); container = new Container(path, workspace); }
@Test public void findMemberByString() { IResource expectedMember = Mockito.mock(IResource.class); when(workspace.newResource(any(IPath.class))).thenReturn(expectedMember); when(expectedMember.exists()).thenReturn(true); IResource actualMember = container.findMember("test"); assertNotNull(actualMember); assertEquals(expectedMember, actualMember); }
@Test public void whenFindingMemberThatDoNotExsitsShouldReturnNull() { IResource expectedMember = Mockito.mock(IResource.class); when(workspace.newResource(any(IPath.class))).thenReturn(expectedMember); when(workspace.newResource(any(IPath.class))).thenReturn(null); IResource actualMember = container.findMember(path); assertNull(actualMember); actualMember = container.findMember(path); assertNull(actualMember); }