Java Code Examples for org.junit.Assert#assertFalse()

The following examples show how to use org.junit.Assert#assertFalse() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: Vector2DTest.java    From commons-geometry with Apache License 2.0 6 votes vote down vote up
@Test
public void testEquals() {
    // arrange
    Vector2D u1 = Vector2D.of(1, 2);
    Vector2D u2 = Vector2D.of(1, 2);

    // act/assert
    Assert.assertFalse(u1.equals(null));
    Assert.assertFalse(u1.equals(new Object()));

    Assert.assertEquals(u1, u1);
    Assert.assertEquals(u1, u2);

    Assert.assertNotEquals(u1, Vector2D.of(-1, -2));
    Assert.assertNotEquals(u1, Vector2D.of(1 + 10 * Precision.EPSILON, 2));
    Assert.assertNotEquals(u1, Vector2D.of(1, 2 + 10 * Precision.EPSILON));

    Assert.assertEquals(Vector2D.of(0, Double.NaN), Vector2D.of(Double.NaN, 0));

    Assert.assertEquals(Vector2D.of(0, Double.POSITIVE_INFINITY), Vector2D.of(0, Double.POSITIVE_INFINITY));
    Assert.assertNotEquals(Vector2D.of(Double.POSITIVE_INFINITY, 0), Vector2D.of(0, Double.POSITIVE_INFINITY));

    Assert.assertEquals(Vector2D.of(Double.NEGATIVE_INFINITY, 0), Vector2D.of(Double.NEGATIVE_INFINITY, 0));
    Assert.assertNotEquals(Vector2D.of(0, Double.NEGATIVE_INFINITY), Vector2D.of(Double.NEGATIVE_INFINITY, 0));
}
 
Example 2
Source File: TestLogSegment.java    From incubator-ratis with Apache License 2.0 6 votes vote down vote up
@Test
public void testZeroSizeInProgressFile() throws Exception {
  final RaftStorage storage = new RaftStorage(storageDir, StartupOption.REGULAR);
  final File file = storage.getStorageDir().getOpenLogFile(0);
  storage.close();

  // create zero size in-progress file
  LOG.info("file: " + file);
  Assert.assertTrue(file.createNewFile());
  final Path path = file.toPath();
  Assert.assertTrue(Files.exists(path));
  Assert.assertEquals(0, Files.size(path));

  // getLogSegmentFiles should remove it.
  final List<RaftStorageDirectory.LogPathAndIndex> logs = storage.getStorageDir().getLogSegmentFiles();
  Assert.assertEquals(0, logs.size());
  Assert.assertFalse(Files.exists(path));
}
 
Example 3
Source File: FileContextMainOperationsBaseTest.java    From big-c with Apache License 2.0 6 votes vote down vote up
@Test
public void testMkdirs() throws Exception {
  Path testDir = getTestRootPath(fc, "test/hadoop");
  Assert.assertFalse(exists(fc, testDir));
  Assert.assertFalse(isFile(fc, testDir));

  fc.mkdir(testDir, FsPermission.getDefault(), true);

  Assert.assertTrue(exists(fc, testDir));
  Assert.assertFalse(isFile(fc, testDir));
  
  fc.mkdir(testDir, FsPermission.getDefault(), true);

  Assert.assertTrue(exists(fc, testDir));
  Assert.assertFalse(isFile(fc, testDir));

  Path parentDir = testDir.getParent();
  Assert.assertTrue(exists(fc, parentDir));
  Assert.assertFalse(isFile(fc, parentDir));

  Path grandparentDir = parentDir.getParent();
  Assert.assertTrue(exists(fc, grandparentDir));
  Assert.assertFalse(isFile(fc, grandparentDir));
  
}
 
Example 4
Source File: AndIteratorTest.java    From datawave with Apache License 2.0 6 votes vote down vote up
@Test
public void testNegatedDeferred() {
    Set<NestedIterator<String>> includes = new HashSet<>();
    includes.add(getItr(Lists.newArrayList("a", "b"), false));
    
    Set<NestedIterator<String>> excludes = new HashSet<>();
    excludes.add(getItr(Lists.newArrayList("b"), true));
    
    AndIterator iterator = new AndIterator(includes, excludes);
    iterator.initialize();
    
    Assert.assertFalse(iterator.isContextRequired());
    Assert.assertTrue(iterator.hasNext());
    Assert.assertEquals("a", iterator.next());
    Assert.assertFalse(iterator.hasNext());
}
 
Example 5
Source File: TestLazyPersistFiles.java    From big-c with Apache License 2.0 6 votes vote down vote up
/**
 * Delete lazy-persist file that has not been persisted to disk.
 * Memory is freed up and file is gone.
 * @throws IOException
 */
@Test
public void testDeleteBeforePersist()
  throws Exception {
  startUpCluster(true, -1);
  final String METHOD_NAME = GenericTestUtils.getMethodName();
  FsDatasetTestUtil.stopLazyWriter(cluster.getDataNodes().get(0));

  Path path = new Path("/" + METHOD_NAME + ".dat");
  makeTestFile(path, BLOCK_SIZE, true);
  LocatedBlocks locatedBlocks =
    ensureFileReplicasOnStorageType(path, RAM_DISK);

  // Delete before persist
  client.delete(path.toString(), false);
  Assert.assertFalse(fs.exists(path));

  assertThat(verifyDeletedBlocks(locatedBlocks), is(true));

  verifyRamDiskJMXMetric("RamDiskBlocksDeletedBeforeLazyPersisted", 1);
}
 
Example 6
Source File: HistoricTransactionsTests.java    From bitcoin-verde with MIT License 6 votes vote down vote up
@Test
public void should_verify_transaction_54AED2D3ABC9B7F6337272649A8B61B774415D469CED1C218F8780BD644C02ED() {
    // NOTE: This transaction's LockTime failed to validate.  However, its lockTime should be ignore since all of its inputs' SequenceNumbers are "final"...

    // Setup
    final TestConfig testConfig = new TestConfig();
    testConfig.transactionBytes = "0100000001FEF8D1C268874475E874A2A3A664A4EB6F98D1D258B62A2800E4BEFA069C57AD010000008B483045022100B482783530D3EC73C97A5DC147EE3CF1705E355C17DD9DF7AD30D8E49712260D022059750222B33F45D80F5DC49C732786EBAED6C6FA72162A4632FEA7231339C15C0141045D443089B4587D355B4CB5AC39B0156AFC92152627693149DE16D0D2269CEA2417010C0BC6930E9B47573DAB76A951E01D884B2BED9EAF92CC2369B6DDC7F98CFFFFFFFF0200000000000000000B6A0942454E2072756C657A306F0100000000001976A9147038DC3B8533A422D1225ECBCC3C85E282FD92B388ACE4670600";
    testConfig.blockHeight = 419808L;

    final Context context = initContext(testConfig);

    final MedianBlockTime medianBlockTime = ImmutableMedianBlockTime.fromSeconds(1467969398L);
    final NetworkTime networkTime = ImmutableNetworkTime.fromSeconds(1529680230L);

    final TransactionValidatorCore transactionValidator = new TransactionValidatorCore(null, networkTime, medianBlockTime);

    // Action
    final Boolean shouldValidateLockTime = transactionValidator._shouldValidateLockTime(context.getTransaction());

    // Assert
    Assert.assertFalse(shouldValidateLockTime);
}
 
Example 7
Source File: AWSXRayRecorderTest.java    From aws-xray-sdk-java with Apache License 2.0 6 votes vote down vote up
@Test
public void testIsCurrentSubsegmentPresent() {
    Assert.assertFalse(AWSXRay.getCurrentSubsegmentOptional().isPresent());

    AWSXRay.beginSegment("test");
    Assert.assertFalse(AWSXRay.getCurrentSubsegmentOptional().isPresent());

    AWSXRay.beginSubsegment("test");
    Assert.assertTrue(AWSXRay.getCurrentSubsegmentOptional().isPresent());

    AWSXRay.endSubsegment();
    Assert.assertFalse(AWSXRay.getCurrentSubsegmentOptional().isPresent());

    AWSXRay.endSegment();
    Assert.assertFalse(AWSXRay.getCurrentSubsegmentOptional().isPresent());
}
 
Example 8
Source File: IpSubnetFilterTest.java    From netty-4.1.22 with Apache License 2.0 5 votes vote down vote up
@Test
public void testIp4SubnetFilterRule() throws Exception {
    IpSubnetFilterRule rule = new IpSubnetFilterRule("192.168.56.1", 24, IpFilterRuleType.ACCEPT);
    for (int i = 0; i <= 255; i++) {
        Assert.assertTrue(rule.matches(newSockAddress(String.format("192.168.56.%d", i))));
    }
    Assert.assertFalse(rule.matches(newSockAddress("192.168.57.1")));

    rule = new IpSubnetFilterRule("91.114.240.1", 23, IpFilterRuleType.ACCEPT);
    Assert.assertTrue(rule.matches(newSockAddress("91.114.240.43")));
    Assert.assertTrue(rule.matches(newSockAddress("91.114.240.255")));
    Assert.assertTrue(rule.matches(newSockAddress("91.114.241.193")));
    Assert.assertTrue(rule.matches(newSockAddress("91.114.241.254")));
    Assert.assertFalse(rule.matches(newSockAddress("91.115.241.2")));
}
 
Example 9
Source File: TestCollectionCoerce.java    From arcusplatform with Apache License 2.0 5 votes vote down vote up
@Test
public void testInvalidCoerce() {
   // This is a bit odd, it can only tell the type is an array, not check the underlying type.
   Assert.assertTrue(typeCoercer.isSupportedCollectionType(Date.class, addressArray.getClass()));
   // With an actual object it can figure out it can't do this.
   Assert.assertFalse(typeCoercer.isCoercibleCollection(Date.class, addressArray));
   try {
      typeCoercer.coerceList(Date.class, addressArray);
   }
   catch (IllegalArgumentException iae) {
      // Expected
      return;
   }
   Assert.fail("Should have exited with an IllegalArgumentException");
}
 
Example 10
Source File: TestCommonToHttpServletRequest.java    From servicecomb-java-chassis with Apache License 2.0 5 votes vote down vote up
@Test
public void testGetHeadersEmpty() {
  Map<String, List<String>> httpHeaders = new HashMap<>();
  httpHeaders.put("name", Arrays.asList());

  HttpServletRequest request = new CommonToHttpServletRequest(null, null, httpHeaders, null, false);
  Assert.assertFalse(request.getHeaders("name").hasMoreElements());
}
 
Example 11
Source File: TestCreateTransaction.java    From iceberg with Apache License 2.0 5 votes vote down vote up
@Test
public void testCreateTransactionConflict() throws IOException {
  File tableDir = temp.newFolder();
  Assert.assertTrue(tableDir.delete());

  Transaction txn = TestTables.beginCreate(tableDir, "test_conflict", SCHEMA, SPEC);

  // append in the transaction to ensure a manifest file is created
  txn.newAppend().appendFile(FILE_A).commit();

  Assert.assertNull("Starting a create transaction should not commit metadata",
      TestTables.readMetadata("test_conflict"));
  Assert.assertNull("Should have no metadata version",
      TestTables.metadataVersion("test_conflict"));

  Table conflict = TestTables.create(tableDir, "test_conflict", SCHEMA, unpartitioned(), formatVersion);

  Assert.assertEquals("Table schema should match with reassigned IDs",
      TypeUtil.assignIncreasingFreshIds(SCHEMA).asStruct(), conflict.schema().asStruct());
  Assert.assertEquals("Table spec should match conflict table, not transaction table",
      unpartitioned(), conflict.spec());
  Assert.assertFalse("Table should not have any snapshots",
      conflict.snapshots().iterator().hasNext());

  AssertHelpers.assertThrows("Transaction commit should fail",
      CommitFailedException.class, "Commit failed: table was updated", txn::commitTransaction);

  Assert.assertEquals("Should clean up metadata", Sets.newHashSet(), Sets.newHashSet(listManifestFiles(tableDir)));
}
 
Example 12
Source File: UniqueListTest.java    From fastods with GNU General Public License v3.0 5 votes vote down vote up
@Test()
public final void testRemoveObject2() {
    final UniqueList<FirstLetter> ul = new UniqueList<FirstLetter>();
    final FirstLetter element = new FirstLetter("FastODS");
    ul.add(element);
    ul.add(new FirstLetter("GastODS"));

    Assert.assertFalse(ul.remove("foo"));
}
 
Example 13
Source File: BlueJiraIssueTest.java    From blueocean-plugin with MIT License 5 votes vote down vote up
@Test
public void issueEqualityAndHashCode()  {
    BlueJiraIssue issue1 = new BlueJiraIssue("TEST-123", "http://jira.example.com/browse/TEST-123");
    BlueJiraIssue issue2 = new BlueJiraIssue("TEST-124", "http://jira.example.com/browse/TEST-124");

    Assert.assertTrue(issue1.equals(issue1));
    Assert.assertFalse(issue1.equals(issue2));
    Assert.assertFalse(issue1.equals(new Object()));

    Assert.assertNotEquals(issue1.hashCode(), issue2.hashCode());
}
 
Example 14
Source File: FieldLUDecompositionTest.java    From hipparchus with Apache License 2.0 5 votes vote down vote up
/** test singular */
@Test
public void testSingular() {
    FieldLUDecomposition<Fraction> lu =
        new FieldLUDecomposition<Fraction>(new Array2DRowFieldMatrix<Fraction>(FractionField.getInstance(), testData));
    Assert.assertTrue(lu.getSolver().isNonSingular());
    lu = new FieldLUDecomposition<Fraction>(new Array2DRowFieldMatrix<Fraction>(FractionField.getInstance(), singular));
    Assert.assertFalse(lu.getSolver().isNonSingular());
    lu = new FieldLUDecomposition<Fraction>(new Array2DRowFieldMatrix<Fraction>(FractionField.getInstance(), bigSingular));
    Assert.assertFalse(lu.getSolver().isNonSingular());
}
 
Example 15
Source File: AvmTransactionExecutorTest.java    From aion with MIT License 5 votes vote down vote up
@Before
public void setup() throws Exception {
    if (!AvmProvider.holdsLock()) {
        Assert.assertTrue(AvmProvider.tryAcquireLock(1, TimeUnit.MINUTES));
    }
    disableAndShutdownAllVersions();

    // Verify the state of the versions.
    Assert.assertFalse(AvmProvider.isVersionEnabled(AvmVersion.VERSION_1));
    Assert.assertFalse(AvmProvider.isAvmRunning(AvmVersion.VERSION_1));
    Assert.assertFalse(AvmProvider.isVersionEnabled(AvmVersion.VERSION_2));
    Assert.assertFalse(AvmProvider.isAvmRunning(AvmVersion.VERSION_2));

    AvmProvider.releaseLock();
}
 
Example 16
Source File: NexmarkQueryModel.java    From beam with Apache License 2.0 5 votes vote down vote up
/** Return assertion to use on results of pipeline for this query. */
public SerializableFunction<Iterable<TimestampedValue<T>>, Void> assertionFor() {
  final Collection<String> expectedStrings = toCollection(simulator().results());
  Assert.assertFalse(expectedStrings.isEmpty());

  return new SerializableFunction<Iterable<TimestampedValue<T>>, Void>() {
    @Override
    @Nullable
    public Void apply(Iterable<TimestampedValue<T>> actual) {
      Collection<String> actualStrings = toCollection(relevantResults(actual).iterator());
      Assert.assertThat("wrong pipeline output", actualStrings, IsEqual.equalTo(expectedStrings));
      return null;
    }
  };
}
 
Example 17
Source File: CopyOnWriteStateMapTest.java    From flink with Apache License 2.0 5 votes vote down vote up
/**
 * This test triggers incremental rehash and tests for corruptions.
 */
@Test
public void testIncrementalRehash() {
	final CopyOnWriteStateMap<Integer, Integer, ArrayList<Integer>> stateMap =
		new CopyOnWriteStateMap<>(new ArrayListSerializer<>(IntSerializer.INSTANCE));

	int insert = 0;
	int remove = 0;
	while (!stateMap.isRehashing()) {
		stateMap.put(insert++, 0, new ArrayList<Integer>());
		if (insert % 8 == 0) {
			stateMap.remove(remove++, 0);
		}
	}
	Assert.assertEquals(insert - remove, stateMap.size());
	while (stateMap.isRehashing()) {
		stateMap.put(insert++, 0, new ArrayList<Integer>());
		if (insert % 8 == 0) {
			stateMap.remove(remove++, 0);
		}
	}
	Assert.assertEquals(insert - remove, stateMap.size());

	for (int i = 0; i < insert; ++i) {
		if (i < remove) {
			Assert.assertFalse(stateMap.containsKey(i, 0));
		} else {
			Assert.assertTrue(stateMap.containsKey(i, 0));
		}
	}
}
 
Example 18
Source File: ResourceMoveTest.java    From xtext-eclipse with Eclipse Public License 2.0 4 votes vote down vote up
@Test
public void testMoveFiles() {
  try {
    StringConcatenation _builder = new StringConcatenation();
    _builder.append("package foo.bar");
    _builder.newLine();
    _builder.append("element X {");
    _builder.newLine();
    _builder.append("\t");
    _builder.append("ref X");
    _builder.newLine();
    _builder.append("}");
    _builder.newLine();
    final IFile x = this.file("foo/bar/X.fileawaretestlanguage", _builder);
    StringConcatenation _builder_1 = new StringConcatenation();
    _builder_1.append("package foo");
    _builder_1.newLine();
    _builder_1.append("element Y {");
    _builder_1.newLine();
    _builder_1.append("\t");
    _builder_1.append("ref bar.X");
    _builder_1.newLine();
    _builder_1.append("}");
    _builder_1.newLine();
    final IFile y = this.file("foo/Y.fileawaretestlanguage", _builder_1);
    this.performMove(this.folder("foo/baz"), x, y);
    Assert.assertFalse(y.exists());
    StringConcatenation _builder_2 = new StringConcatenation();
    _builder_2.append("package foo.baz");
    _builder_2.newLine();
    _builder_2.append("element X {");
    _builder_2.newLine();
    _builder_2.append("\t");
    _builder_2.append("ref X");
    _builder_2.newLine();
    _builder_2.append("}");
    _builder_2.newLine();
    this.assertFileContents("foo/baz/X.fileawaretestlanguage", _builder_2.toString());
    StringConcatenation _builder_3 = new StringConcatenation();
    _builder_3.append("package foo.baz");
    _builder_3.newLine();
    _builder_3.append("element Y {");
    _builder_3.newLine();
    _builder_3.append("\t");
    _builder_3.append("ref X");
    _builder_3.newLine();
    _builder_3.append("}");
    _builder_3.newLine();
    this.assertFileContents("foo/baz/Y.fileawaretestlanguage", _builder_3.toString());
  } catch (Throwable _e) {
    throw Exceptions.sneakyThrow(_e);
  }
}
 
Example 19
Source File: HiveTableTest.java    From iceberg with Apache License 2.0 4 votes vote down vote up
@Test
public void testDrop() {
  Assert.assertTrue("Table should exist", catalog.tableExists(TABLE_IDENTIFIER));
  Assert.assertTrue("Drop should return true and drop the table", catalog.dropTable(TABLE_IDENTIFIER));
  Assert.assertFalse("Table should not exist", catalog.tableExists(TABLE_IDENTIFIER));
}
 
Example 20
Source File: TestScrLazyPersistFiles.java    From hadoop with Apache License 2.0 4 votes vote down vote up
private void doShortCircuitReadAfterEvictionTest() throws IOException,
    InterruptedException {
  final String METHOD_NAME = GenericTestUtils.getMethodName();
  Path path1 = new Path("/" + METHOD_NAME + ".01.dat");
  Path path2 = new Path("/" + METHOD_NAME + ".02.dat");

  final int SEED = 0xFADED;
  makeRandomTestFile(path1, BLOCK_SIZE, true, SEED);

  // Verify short-circuit read from RAM_DISK.
  ensureFileReplicasOnStorageType(path1, RAM_DISK);
  File metaFile = cluster.getBlockMetadataFile(0,
      DFSTestUtil.getFirstBlock(fs, path1));
  assertTrue(metaFile.length() <= BlockMetadataHeader.getHeaderSize());
  assertTrue(verifyReadRandomFile(path1, BLOCK_SIZE, SEED));

  // Sleep for a short time to allow the lazy writer thread to do its job.
  Thread.sleep(3 * LAZY_WRITER_INTERVAL_SEC * 1000);

  // Verify short-circuit read from RAM_DISK once again.
  ensureFileReplicasOnStorageType(path1, RAM_DISK);
  metaFile = cluster.getBlockMetadataFile(0,
      DFSTestUtil.getFirstBlock(fs, path1));
  assertTrue(metaFile.length() <= BlockMetadataHeader.getHeaderSize());
  assertTrue(verifyReadRandomFile(path1, BLOCK_SIZE, SEED));

  // Create another file with a replica on RAM_DISK, which evicts the first.
  makeRandomTestFile(path2, BLOCK_SIZE, true, SEED);
  Thread.sleep(3 * LAZY_WRITER_INTERVAL_SEC * 1000);
  triggerBlockReport();

  // Verify short-circuit read still works from DEFAULT storage.  This time,
  // we'll have a checksum written during lazy persistence.
  ensureFileReplicasOnStorageType(path1, DEFAULT);
  metaFile = cluster.getBlockMetadataFile(0,
      DFSTestUtil.getFirstBlock(fs, path1));
  assertTrue(metaFile.length() > BlockMetadataHeader.getHeaderSize());
  assertTrue(verifyReadRandomFile(path1, BLOCK_SIZE, SEED));

  // In the implementation of legacy short-circuit reads, any failure is
  // trapped silently, reverts back to a remote read, and also disables all
  // subsequent legacy short-circuit reads in the ClientContext.  If the test
  // uses legacy, then assert that it didn't get disabled.
  ClientContext clientContext = client.getClientContext();
  if (clientContext.getUseLegacyBlockReaderLocal()) {
    Assert.assertFalse(clientContext.getDisableLegacyBlockReaderLocal());
  }
}