@Test public void isPageSharedWithOtherBranches() throws IOException, GitAPIException { register(globalRepoManager.createProjectCentralRepository(PROJECT, USER)); register(globalRepoManager.createProjectBranchRepository(PROJECT, BRANCH_1, null)); saveRandomPage(BRANCH_1, PAGE); assertFalse(isPageSharedWithOtherBranches(BRANCH_1)); register(globalRepoManager.createProjectBranchRepository(PROJECT, BRANCH_2, BRANCH_1)); register(globalRepoManager.createProjectBranchRepository(PROJECT, BRANCH_3, BRANCH_1)); assertTrue(isPageSharedWithOtherBranches(BRANCH_1)); assertTrue(isPageSharedWithOtherBranches(BRANCH_2)); assertTrue(isPageSharedWithOtherBranches(BRANCH_3)); saveRandomPage(BRANCH_1, "page_2"); // $NON-NLS-1$ saveRandomPage(BRANCH_2, "page_3"); // $NON-NLS-1$ saveRandomPage(BRANCH_3, "page_4"); // $NON-NLS-1$ assertTrue(isPageSharedWithOtherBranches(BRANCH_1)); assertTrue(isPageSharedWithOtherBranches(BRANCH_2)); assertTrue(isPageSharedWithOtherBranches(BRANCH_3)); saveRandomPage(BRANCH_1, PAGE); assertFalse(isPageSharedWithOtherBranches(BRANCH_1)); assertTrue(isPageSharedWithOtherBranches(BRANCH_2)); assertTrue(isPageSharedWithOtherBranches(BRANCH_3)); saveRandomPage(BRANCH_2, PAGE); assertFalse(isPageSharedWithOtherBranches(BRANCH_1)); assertFalse(isPageSharedWithOtherBranches(BRANCH_2)); assertFalse(isPageSharedWithOtherBranches(BRANCH_3)); }
@Test public void deleteAttachment() throws IOException, GitAPIException { register(globalRepoManager.createProjectCentralRepository(PROJECT, USER)); ILockedRepository repo = globalRepoManager.createProjectBranchRepository(PROJECT, BRANCH_1, null); register(repo); saveRandomPage(BRANCH_1, PAGE); Page attachment = Page.fromData(new byte[] {1, 2, 3}, "application/octet-stream"); // $NON-NLS-1$ pageStore.saveAttachment(PROJECT, BRANCH_1, PAGE, "test.dat", attachment, USER); // $NON-NLS-1$ assertFalse(pageStore.listPageAttachments(PROJECT, BRANCH_1, PAGE).isEmpty()); File pageFile = new File( new File(new File(RepositoryUtil.getWorkingDir(repo.r()), "attachments"), PAGE), "test.dat.page"); //$NON-NLS-1$ //$NON-NLS-2$ File metaFile = new File( new File(new File(RepositoryUtil.getWorkingDir(repo.r()), "attachments"), PAGE), "test.dat.meta"); //$NON-NLS-1$ //$NON-NLS-2$ assertTrue(pageFile.exists()); assertTrue(metaFile.exists()); pageStore.deleteAttachment(PROJECT, BRANCH_1, PAGE, "test.dat", USER); // $NON-NLS-1$ assertTrue(pageStore.listPageAttachments(PROJECT, BRANCH_1, PAGE).isEmpty()); assertFalse(pageFile.exists()); assertFalse(metaFile.exists()); assertClean(repo.r()); }
/** * Test method for {@link net.sf.hajdbc.balancer.load.LoadBalancer#add(net.sf.hajdbc.Database)}. */ @Test public void add() { Balancer<Void, MockDatabase> balancer = this.factory.createBalancer(Collections.<MockDatabase>emptySet()); boolean result = balancer.add(this.databases[1]); assertTrue(result); assertCollectionEquals(Collections.singleton(this.databases[1]), balancer); balancer = this.factory.createBalancer(Collections.singleton(this.databases[0])); result = balancer.add(this.databases[1]); assertTrue(result); assertCollectionEquals(Arrays.asList(this.databases[0], this.databases[1]), balancer); balancer = this.factory.createBalancer( new HashSet<MockDatabase>(Arrays.asList(this.databases[0], this.databases[1]))); result = balancer.add(this.databases[1]); assertFalse(result); assertCollectionEquals(Arrays.asList(this.databases[0], this.databases[1]), balancer); balancer = this.factory.createBalancer(new HashSet<MockDatabase>(Arrays.asList(this.databases))); result = balancer.add(this.databases[1]); assertFalse(result); assertCollectionEquals(Arrays.asList(this.databases), balancer); }
@Test public void shouldIgnoreDerivedResourcesEvents() throws CoreException { when(resource.isDerived()).thenReturn(true); assertFalse(deltaVisitor.visit(resourceDelta(CONTENT))); assertFalse(deltaVisitor.savedResourceFound()); }
@Test public void testIntegerField() { IntField field = new IntField("n"); assertOut(field, "<input type='number' name='n' value=''>"); field.setName("ifield"); when(request.getParameter("ifield")).thenReturn("a"); assertFalse(field.read(request)); assertEquals(Control.Status.PARSE_ERROR, field.getStatus()); assertTrue(field.getError() instanceof NumberFormatException); assertNull(field.getValue()); assertEquals("a", field.getErrorValue()); assertEquals("a", field.format()); field.setReadOnly(true); assertFalse(field.read(request)); field.setReadOnly(false); when(request.getParameter("ifield")).thenReturn(""); assertTrue(field.read(request)); assertEquals(null, field.getValue()); field.setRequired(true); assertFalse(field.read(request)); assertEquals(null, field.getValue()); field = new IntField("n"); field.setMin(20); field.setMax(30); field.setStep(2); assertOut(field, "<input type='number' name='n' value='' min='20' max='30' step='2'>"); }
@Test public void shouldIgnoreMarkerOnlyChanges() throws CoreException { when(resource.getType()).thenReturn(IResource.FILE); when(resource.isDerived()).thenReturn(false); assertFalse(deltaVisitor.visit(resourceDelta(MARKERS))); assertFalse(deltaVisitor.savedResourceFound()); }
@Test public void testIsLastPosition() { testItems = new LinkedList<>(); TestItem.populateList(testItems, NUM_ITEMS); delegate = new TimelineDelegate<>(mockTimeline, mockObservable, testItems); assertFalse(delegate.isLastPosition(0)); assertFalse(delegate.isLastPosition(NUM_ITEMS - 2)); assertTrue(delegate.isLastPosition(NUM_ITEMS - 1)); }
@Test public void isAMatchOfFilterTest() { PropertyEditorFieldInfo field = new PropertyEditorFieldInfo("label", PropertyEditorType.TEXT); assertTrue(PropertyEditorHelper.isAMatchOfFilter("l", field)); assertTrue(PropertyEditorHelper.isAMatchOfFilter("label", field)); assertTrue(PropertyEditorHelper.isAMatchOfFilter("LABEL", field)); assertTrue(PropertyEditorHelper.isAMatchOfFilter("abel", field)); assertFalse(PropertyEditorHelper.isAMatchOfFilter("LABELL", field)); assertFalse(PropertyEditorHelper.isAMatchOfFilter("LASBELL", field)); assertFalse(PropertyEditorHelper.isAMatchOfFilter("p", field)); }
@Test public void testIsRunning() throws Exception { FitNesseContext context = FitNesseUtil.makeTestContext(); FitNesse fitnesse = context.fitNesse.dontMakeDirs(); assertFalse(fitnesse.isRunning()); fitnesse.start(); assertTrue(fitnesse.isRunning()); fitnesse.stop(); assertFalse(fitnesse.isRunning()); }
@Test public void shouldEnableAndThenDisableAccessibility() throws Exception { // given Field privateField = SomeObject.class.getDeclaredField("privateField"); assertFalse(privateField.isAccessible()); // when tool.copyToMock(from, to); // then privateField = SomeObject.class.getDeclaredField("privateField"); assertFalse(privateField.isAccessible()); }
@Test public void assertWorkspaceIsDeletedFromMap() throws Exception { when(server.execute(isA(MaskedArgumentListBuilder.class))).thenReturn(new StringReader("")); Workspaces workspaces = new Workspaces(server); // Populate the map in test object assertFalse( "The workspace was reported as existant", workspaces.exists(new Workspace(server, "name"))); Workspace workspace = workspaces.newWorkspace("name"); assertTrue( "The workspace was reported as non existant", workspaces.exists(new Workspace(server, "name"))); workspaces.deleteWorkspace(workspace); assertFalse("The workspace was reported as existant", workspaces.exists(workspace)); }
@Test public void testZipFileWrite() throws Exception { String outputFileName = null; try { // Get somewhere temporary to write out to outputFileName = File.createTempFile("ItemWriterTest-", ".csv.zip").getAbsolutePath(); // Configure the ItemWriter C24ItemWriter itemWriter = new C24ItemWriter(); itemWriter.setSink(new TextualSink()); itemWriter.setWriterSource(new ZipFileWriterSource()); itemWriter.setup(getStepExecution(outputFileName)); // Write the employees out itemWriter.write(employees); // Close the file itemWriter.cleanup(); // Check that we wrote out what was expected ZipFile zipFile = new ZipFile(outputFileName); Enumeration<? extends ZipEntry> entries = zipFile.entries(); assertNotNull(entries); // Make sure there's at least one entry assertTrue(entries.hasMoreElements()); ZipEntry entry = entries.nextElement(); // Make sure that the trailing .zip has been removed and the leading path has been removed assertFalse(entry.getName().contains(System.getProperty("file.separator"))); assertFalse(entry.getName().endsWith(".zip")); // Make sure that there aren't any other entries assertFalse(entries.hasMoreElements()); try { compareCsv(zipFile.getInputStream(entry), employees); } finally { if (zipFile != null) { zipFile.close(); } } } finally { if (outputFileName != null) { // Clear up our temporary file File file = new File(outputFileName); file.delete(); } } }
public void testAuthenticationFailed_AuthenticationException() throws Exception { InitialDirContextFactory mockFactory = mock(InitialDirContextFactory.class); when(mockFactory.create(Matchers.isA(Hashtable.class))) .thenThrow(new AuthenticationException()); authenticator.initialDirContextFactory = mockFactory; assertFalse(authenticator.isAuthenticated("username", "password")); }
@SuppressWarnings({"JNDIResourceOpenedButNotSafelyClosed"}) public void testNullDirContext() throws Exception { InitialDirContextFactory mockFactory = mock(InitialDirContextFactory.class); when(mockFactory.create(Matchers.isA(Hashtable.class))).thenReturn(null); authenticator.initialDirContextFactory = mockFactory; assertFalse(authenticator.isAuthenticated("username", "password")); }
@Test public void ball_rolls_for_a_random_time_between_30_and_40_seconds() throws Exception { when(rng.generate(30, 40)).thenReturn(33); rt.roll(); timer.moveTime(33001); assertFalse(rt.isBallRolling()); }
@Test public void removeNonContainedPart() { WorkbenchPartPresenter mockPresenter = mock(WorkbenchPartPresenter.class); WorkbenchPartPresenter.View mockPartView = mock(WorkbenchPartPresenter.View.class); PartDefinition mockPartDefinition = new PartDefinitionImpl(new DefaultPlaceRequest("mock1")); when(mockPartView.getPresenter()).thenReturn(mockPresenter); when(mockPresenter.getDefinition()).thenReturn(mockPartDefinition); WorkbenchPartPresenter mockPresenter2 = mock(WorkbenchPartPresenter.class); WorkbenchPartPresenter.View mockPartView2 = mock(WorkbenchPartPresenter.View.class); PartDefinition mockPartDefinition2 = new PartDefinitionImpl(new DefaultPlaceRequest("mock2")); when(mockPartView2.getPresenter()).thenReturn(mockPresenter2); when(mockPresenter2.getDefinition()).thenReturn(mockPartDefinition2); when(view.panel.getPartView()).thenReturn(null); view.addPart(mockPartView); when(view.panel.getPartView()).thenReturn(mockPartView); boolean removed = view.removePart(mockPartDefinition2); assertFalse(removed); verify(panel, never()).clear(); }
@Test public void getMembersWhenNestedGroup() throws Exception { setUpBaseMocks(); DocumentReference groupReference1 = new DocumentReference("groupwiki", "XWiki", "grouppage1"); DocumentReference userReference1 = new DocumentReference("userwiki", "XWiki", "user1"); DocumentReference userReference2 = new DocumentReference("userwiki", "XWiki", "user2"); DocumentReference groupReference2 = new DocumentReference("groupwiki", "XWiki", "grouppage2"); DocumentReference userReference3 = new DocumentReference("userwiki", "XWiki", "user3"); DocumentReference userReference4 = new DocumentReference("userwiki", "XWiki", "user4"); setUpGroupPageMocks(groupReference1, userReference1, userReference2, groupReference2); setUpGroupPageMocks(groupReference2, userReference3, userReference4); Iterator<DocumentReference> iterator = new ReferenceUserIterator(groupReference1, this.resolver, this.execution); assertTrue(iterator.hasNext()); assertEquals(userReference1, iterator.next()); assertTrue(iterator.hasNext()); assertEquals(userReference2, iterator.next()); assertTrue(iterator.hasNext()); assertEquals(userReference3, iterator.next()); assertTrue(iterator.hasNext()); assertEquals(userReference4, iterator.next()); assertFalse(iterator.hasNext()); }
@Test public void getMembersWhenSingleUserWithoutCallingHasNextFirst() throws Exception { Iterator<DocumentReference> iterator = setUpSingleUser(); assertEquals(new DocumentReference("userwiki", "XWiki", "userpage"), iterator.next()); assertFalse(iterator.hasNext()); }
@Test public void deleteMacro() throws IOException { scanner.deleteMacro(MACRO_NAME); File file = new File(macrosDir, MACRO_NAME + ".groovy"); // $NON-NLS-1$ assertFalse(file.exists()); }
@Test(expected = IllegalArgumentException.class) public void verifyDeleteServiceNoService() throws Exception { final MockHttpServletResponse response = new MockHttpServletResponse(); this.controller.deleteRegisteredService(1200, response); assertNull(this.servicesManager.findServiceBy(1200)); assertFalse(response.getContentAsString().contains("serviceName")); }
@Test public void testFromAccumulateCompositePatternMissingValuesWithExistingFrom() throws Exception { FactPattern pattern1 = new FactPattern("Person"); SingleFieldConstraint constraint1 = new SingleFieldConstraint("name"); constraint1.setOperator("=="); pattern1.addConstraint(constraint1); FactPattern pattern2 = new FactPattern("Address"); SingleFieldConstraint constraint2 = new SingleFieldConstraint("street"); constraint2.setOperator("!="); pattern2.addConstraint(constraint2); FromAccumulateCompositeFactPattern fromAccumulateCompositeFactPattern = new FromAccumulateCompositeFactPattern(); fromAccumulateCompositeFactPattern.setSourcePattern(pattern1); fromAccumulateCompositeFactPattern.setFactPattern(pattern2); fromAccumulateCompositeFactPattern.setInitCode("int i = 0"); fromAccumulateCompositeFactPattern.setActionCode(" i++;"); fromAccumulateCompositeFactPattern.setReverseCode("i--;"); fromAccumulateCompositeFactPattern.setResultCode("return i"); model.lhs = new IPattern[] {fromAccumulateCompositeFactPattern}; assertFalse(validator.isValid()); assertEquals(2, validator.getErrors().size()); verify(constants, never()).WhenUsingFromTheSourceNeedsToBeSet(); verify(constants) .FactType0HasAField1ThatHasAnOperatorSetButNoValuePleaseAddAValueOrRemoveTheOperator( "Person", "name"); verify(constants) .FactType0HasAField1ThatHasAnOperatorSetButNoValuePleaseAddAValueOrRemoveTheOperator( "Address", "street"); }
@Test public void testMissingValueInFrom() throws Exception { FactPattern boundPattern = new FactPattern("Person"); boundPattern.setBoundName("person"); boundPattern.addConstraint(new SingleFieldConstraint("addresses")); FactPattern pattern = new FactPattern("Address"); SingleFieldConstraint constraint = new SingleFieldConstraint("street"); constraint.setOperator("!="); pattern.addConstraint(constraint); FromCompositeFactPattern fromCompositeFactPattern = new FromCompositeFactPattern(); fromCompositeFactPattern.setFactPattern(pattern); ExpressionFormLine expression = new ExpressionFormLine(); expression.setBinding("person.addresses"); fromCompositeFactPattern.setExpression(expression); model.lhs = new IPattern[] {boundPattern, fromCompositeFactPattern}; assertFalse(validator.isValid()); assertEquals(1, validator.getErrors().size()); assertEquals(MISSING_VALUE_WHEN_OPERATOR_IS_SET, validator.getErrors().get(0)); verify(constants) .FactType0HasAField1ThatHasAnOperatorSetButNoValuePleaseAddAValueOrRemoveTheOperator( "Address", "street"); }
@Test public void shouldDealWithRecordBecomingInvalidDueToOverwrite() { final int length = 8; final int recordLength = length + HEADER_LENGTH; final int recordLengthAligned = align(recordLength, RECORD_ALIGNMENT); final long tail = recordLengthAligned; final long latestRecord = tail - recordLengthAligned; final int recordOffset = (int) latestRecord; when(buffer.getLongVolatile(TAIL_INTENT_COUNTER_OFFSET)) .thenReturn(tail) .thenReturn(tail + (CAPACITY - (recordLengthAligned))); when(buffer.getLongVolatile(TAIL_COUNTER_INDEX)).thenReturn(tail); when(buffer.getInt(lengthOffset(recordOffset))).thenReturn(recordLength); when(buffer.getInt(typeOffset(recordOffset))).thenReturn(MSG_TYPE_ID); assertTrue(broadcastReceiver.receiveNext()); assertThat(broadcastReceiver.typeId(), is(MSG_TYPE_ID)); assertThat(broadcastReceiver.buffer(), is(buffer)); assertThat(broadcastReceiver.offset(), is(msgOffset(recordOffset))); assertThat(broadcastReceiver.length(), is(length)); assertFalse( broadcastReceiver.validate()); // Need to receiveNext() to catch up with transmission again. final InOrder inOrder = inOrder(buffer); inOrder.verify(buffer).getLongVolatile(TAIL_COUNTER_INDEX); }
@Test public void testWorkbenchRunningPredicateTrue() { IWorkbench wb = mock(IWorkbench.class); when(wb.isClosing()).thenReturn(true); sut = new WorkbenchRunningPredicate(wb); assertFalse(sut.apply(status)); }
@Test public void testHistoryRunningPredicateFalse() { ReportHistory history = createTestHistory(); // history not running sut = new HistoryReadyPredicate(history); assertFalse(sut.apply(status)); }
public void testSerial( int handlerCount, boolean handlerSleep, int clientCount, int callerCount, int callCount) throws Exception { Server server = new TestServer(handlerCount, handlerSleep); InetSocketAddress addr = NetUtils.getConnectAddress(server); server.start(); Client[] clients = new Client[clientCount]; for (int i = 0; i < clientCount; i++) { clients[i] = new Client(LongWritable.class, conf); } SerialCaller[] callers = new SerialCaller[callerCount]; for (int i = 0; i < callerCount; i++) { callers[i] = new SerialCaller(clients[i % clientCount], addr, callCount); callers[i].start(); } for (int i = 0; i < callerCount; i++) { callers[i].join(); assertFalse(callers[i].failed); } for (int i = 0; i < clientCount; i++) { clients[i].stop(); } server.stop(); }
@Test public void getMembersWhenSingleUserButBothUserAndGroupReference() throws Exception { setUpBaseMocks(); DocumentReference reference = new DocumentReference("wiki", "XWiki", "page"); XWikiDocument document = mock(XWikiDocument.class); when(document.isNew()).thenReturn(false); when(document.getDocumentReference()).thenReturn(reference); when(this.xwiki.getDocument(reference, this.xwikiContext)).thenReturn(document); // It's a user reference BaseObject bo1 = mock(BaseObject.class); when(document.getXObject(new DocumentReference("wiki", "XWiki", "XWikiUsers"))).thenReturn(bo1); // It's also a group reference (with one user in it) List<BaseObject> memberObjects = new ArrayList<>(); BaseObject bo2 = mock(BaseObject.class); when(bo2.getStringValue("member")).thenReturn("XWiki.user"); memberObjects.add(bo2); when(document.getXObjects(new DocumentReference("wiki", "XWiki", "XWikiGroups"))) .thenReturn(memberObjects); DocumentReference userReference = new DocumentReference("wiki", "XWiki", "user"); when(this.resolver.resolve("XWiki.user", reference)).thenReturn(userReference); setUpUserPageMocks(userReference); Iterator<DocumentReference> iterator = new ReferenceUserIterator(reference, this.resolver, this.execution); assertTrue(iterator.hasNext()); assertEquals(new DocumentReference("wiki", "XWiki", "page"), iterator.next()); assertTrue(iterator.hasNext()); assertEquals(new DocumentReference("wiki", "XWiki", "user"), iterator.next()); assertFalse(iterator.hasNext()); }
private void check(AssertionError error) throws Exception { createComparisonFailure(verify(constructorInvoker)); assertFalse(error instanceof ComparisonFailure); assertEquals( "[Jedi] \nExpecting:\n <\"Yoda\">\nto be equal to:\n <\"Luke\">\nbut was not.", error.getMessage()); }
@Test public void testEquals_WithoutWrapper() { Connection wrapped = wrap(connection, closeHandler); assertFalse(wrapped.equals(connection)); assertTrue(wrapped.equals(wrapped)); }
@Test public void isCorrectPlayerInGameNoPlayer() { when(service.isAuthorized(anyString())).thenReturn(true); when(service.getUserBySession(anyString())).thenReturn(null); assertFalse(gameServer.isCorrectPlayerInGame("aa")); }