org.testng.Assert类的使用及代码示例

x33g5p2x  于2022-01-15 转载在 其他  
字(12.7k)|赞(0)|评价(0)|浏览(169)

本文整理了Java中org.testng.Assert类的一些代码示例,展示了Assert类的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Assert类的具体详情如下:
包路径:org.testng.Assert
类名称:Assert

Assert介绍

[英]Assertion tool class. Presents assertion methods with a more natural parameter order. The order is always actualValue, expectedValue [, message].
[中]断言工具类。以更自然的参数顺序显示断言方法。顺序始终为actualValue,expectedValue[,message]。

代码示例

代码示例来源:origin: prestodb/presto

@Test
public void testCreateSchema()
{
  assertEquals(metadata.listSchemaNames(SESSION), ImmutableList.of("default"));
  metadata.createSchema(SESSION, "test", ImmutableMap.of());
  assertEquals(metadata.listSchemaNames(SESSION), ImmutableList.of("default", "test"));
}

代码示例来源:origin: prestodb/presto

@Test
public void testTableSampleBernoulli()
{
  DescriptiveStatistics stats = new DescriptiveStatistics();
  int total = computeExpected("SELECT orderkey FROM orders", ImmutableList.of(BIGINT)).getMaterializedRows().size();
  for (int i = 0; i < 100; i++) {
    List<MaterializedRow> values = computeActual("SELECT orderkey FROM orders TABLESAMPLE BERNOULLI (50)").getMaterializedRows();
    assertEquals(values.size(), ImmutableSet.copyOf(values).size(), "TABLESAMPLE produced duplicate rows");
    stats.addValue(values.size() * 1.0 / total);
  }
  double mean = stats.getGeometricMean();
  assertTrue(mean > 0.45 && mean < 0.55, format("Expected mean sampling rate to be ~0.5, but was %s", mean));
}

代码示例来源:origin: prestodb/presto

public void testInvalidGetPartitionsByNames()
{
  Map<String, Optional<Partition>> partitionsByNames = metastore.getPartitionsByNames(BAD_DATABASE, TEST_TABLE, ImmutableList.of(TEST_PARTITION1));
  assertEquals(partitionsByNames.size(), 1);
  Optional<Partition> onlyElement = Iterables.getOnlyElement(partitionsByNames.values());
  assertFalse(onlyElement.isPresent());
}

代码示例来源:origin: spring-projects/spring-framework

@Test
void autowiringFromConfigClass() {
  assertNotNull(employee, "The employee should have been autowired.");
  assertEquals(employee.getName(), "John Smith");
  assertNotNull(pet, "The pet should have been autowired.");
  assertEquals(pet.getName(), "Fido");
}

代码示例来源:origin: spring-projects/spring-framework

@Test
@Transactional(propagation = Propagation.NOT_SUPPORTED)
void verifyAnnotationAutowiredFields() {
  assertInTransaction(false);
  assertNull(nonrequiredLong, "The nonrequiredLong field should NOT have been autowired.");
  assertNotNull(pet, "The pet field should have been autowired.");
  assertEquals(pet.getName(), "Fido", "pet's name.");
}

代码示例来源:origin: prestodb/presto

@Test
public void testGroupingOperationSomeBitsSet()
{
  List<Integer> groupingOrdinals = ImmutableList.of(7, 2, 9, 3, 5);
  List<Set<Integer>> groupingSetOrdinals = ImmutableList.of(ImmutableSet.of(4, 2), ImmutableSet.of(9, 7, 14), ImmutableSet.of(5, 2, 7), ImmutableSet.of(3));
  List<Long> expectedResults = ImmutableList.of(23L, 11L, 6L, 29L);
  for (int groupId = 0; groupId < groupingSetOrdinals.size(); groupId++) {
    Set<Integer> groupingSet = groupingSetOrdinals.get(groupId);
    assertEquals(Long.valueOf(calculateGrouping(groupingSet, groupingOrdinals)), expectedResults.get(groupId));
  }
}

代码示例来源:origin: prestodb/presto

@Test
public void testNoMatch()
{
  ResourceGroupIdTemplate template = new ResourceGroupIdTemplate("test.pipeline.${pipeline}.${USER}");
  Pattern sourcePattern = Pattern.compile("scheduler.important.(?<pipeline>[^\\[]*).*");
  StaticSelector selector = new StaticSelector(Optional.empty(), Optional.of(sourcePattern), Optional.empty(), Optional.empty(), Optional.empty(), template);
  SelectionCriteria context = new SelectionCriteria(true, "user", Optional.of("scheduler.testpipeline[5]"), ImmutableSet.of(), EMPTY_RESOURCE_ESTIMATES, Optional.empty());
  assertFalse(selector.match(context).isPresent());
}

代码示例来源:origin: prestodb/presto

@Test
public void testProjectNoColumns()
{
  PageProcessor pageProcessor = new PageProcessor(Optional.empty(), ImmutableList.of(), OptionalInt.of(MAX_BATCH_SIZE));
  Page inputPage = new Page(createLongSequenceBlock(0, 100));
  Iterator<Optional<Page>> output = processAndAssertRetainedPageSize(pageProcessor, inputPage);
  List<Optional<Page>> outputPages = ImmutableList.copyOf(output);
  assertEquals(outputPages.size(), 1);
  Page outputPage = outputPages.get(0).orElse(null);
  assertEquals(outputPage.getChannelCount(), 0);
  assertEquals(outputPage.getPositionCount(), inputPage.getPositionCount());
}

代码示例来源:origin: prestodb/presto

private void validateMetadata(ExtendedHiveMetastore hiveMetastore)
{
  assertEquals(hiveMetastore.getDatabase("database"), Optional.of(DATABASE));
  assertEquals(hiveMetastore.getAllDatabases(), ImmutableList.of("database"));
  assertEquals(hiveMetastore.getTable("database", "table"), Optional.of(TABLE));
  assertEquals(hiveMetastore.getSupportedColumnStatistics(createVarcharType(123)), ImmutableSet.of(MIN_VALUE, MAX_VALUE));
  assertEquals(hiveMetastore.getTableStatistics("database", "table"), PARTITION_STATISTICS);
  assertEquals(hiveMetastore.getPartitionStatistics("database", "table", ImmutableSet.of("value")), ImmutableMap.of("value", PARTITION_STATISTICS));
  assertEquals(hiveMetastore.getAllTables("database"), Optional.of(ImmutableList.of("table")));
  assertEquals(hiveMetastore.getAllViews("database"), Optional.empty());
  assertEquals(hiveMetastore.getPartition("database", "table", ImmutableList.of("value")), Optional.of(PARTITION));
  assertEquals(hiveMetastore.getPartitionNames("database", "table"), Optional.of(ImmutableList.of("value")));
  assertEquals(hiveMetastore.getPartitionNamesByParts("database", "table", ImmutableList.of("value")), Optional.of(ImmutableList.of("value")));
  assertEquals(hiveMetastore.getPartitionsByNames("database", "table", ImmutableList.of("value")), ImmutableMap.of("value", Optional.of(PARTITION)));
  assertEquals(hiveMetastore.getRoles("user"), ImmutableSet.of("role1", "role2"));
  assertEquals(hiveMetastore.getDatabasePrivileges("user", "database"), ImmutableSet.of(PRIVILEGE_INFO));
  assertEquals(hiveMetastore.getTablePrivileges("user", "database", "table"), ImmutableSet.of(PRIVILEGE_INFO));
}

代码示例来源:origin: prestodb/presto

@Test
public void testSchemaEvolutionIntToLong()
    throws Exception
{
  byte[] originalIntData = buildAvroData(new Schema.Parser().parse(
      getAvroSchema("int_to_long_field", "\"int\"")),
      "int_to_long_field", 100);
  DecoderTestColumnHandle longColumnReadingIntData = new DecoderTestColumnHandle(0, "row0", BIGINT, "int_to_long_field", null, null, false, false, false);
  String changedTypeSchema = getAvroSchema("int_to_long_field", "\"long\"");
  Map<DecoderColumnHandle, FieldValueProvider> decodedEvolvedRow = decodeRow(
      originalIntData,
      ImmutableSet.of(longColumnReadingIntData),
      ImmutableMap.of(DATA_SCHEMA, changedTypeSchema));
  assertEquals(decodedEvolvedRow.size(), 1);
  checkValue(decodedEvolvedRow, longColumnReadingIntData, 100);
}

代码示例来源:origin: prestodb/presto

@Test
public void tableIsCreatedAfterCommits()
{
  assertNoTables();
  SchemaTableName schemaTableName = new SchemaTableName("default", "temp_table");
  ConnectorOutputTableHandle table = metadata.beginCreateTable(
      SESSION,
      new ConnectorTableMetadata(schemaTableName, ImmutableList.of(), ImmutableMap.of()),
      Optional.empty());
  metadata.finishCreateTable(SESSION, table, ImmutableList.of(), ImmutableList.of());
  List<SchemaTableName> tables = metadata.listTables(SESSION, Optional.empty());
  assertTrue(tables.size() == 1, "Expected only one table");
  assertTrue(tables.get(0).getTableName().equals("temp_table"), "Expected table with name 'temp_table'");
}

代码示例来源:origin: prestodb/presto

@Test
public void testNoCaching()
{
  ImmutableList.Builder<RowExpression> projectionsBuilder = ImmutableList.builder();
  ArrayType arrayType = new ArrayType(VARCHAR);
  Signature signature = new Signature("concat", SCALAR, arrayType.getTypeSignature(), arrayType.getTypeSignature(), arrayType.getTypeSignature());
  projectionsBuilder.add(new CallExpression(signature, arrayType, ImmutableList.of(field(0, arrayType), field(1, arrayType))));
  ImmutableList<RowExpression> projections = projectionsBuilder.build();
  PageProcessor pageProcessor = compiler.compilePageProcessor(Optional.empty(), projections).get();
  PageProcessor pageProcessor2 = compiler.compilePageProcessor(Optional.empty(), projections).get();
  assertTrue(pageProcessor != pageProcessor2);
}

代码示例来源:origin: prestodb/presto

@Test
public void testGetTimeTableHandle()
{
  JmxTableHandle handle = metadata.getTableHandle(SESSION, RUNTIME_HISTORY_TABLE);
  assertEquals(handle.getObjectNames(), ImmutableList.of(RUNTIME_OBJECT));
  List<JmxColumnHandle> columns = handle.getColumnHandles();
  assertTrue(columns.contains(new JmxColumnHandle("timestamp", TIMESTAMP)));
  assertTrue(columns.contains(new JmxColumnHandle("node", createUnboundedVarcharType())));
  assertTrue(columns.contains(new JmxColumnHandle("Name", createUnboundedVarcharType())));
  assertTrue(columns.contains(new JmxColumnHandle("StartTime", BIGINT)));
}

代码示例来源:origin: jclouds/legacy-jclouds

public void testMetadataStatic() {
 CreateContainerOptions options = CreateContainerOptions.Builder
      .withMetadata(ImmutableMap.of("test", "foo"));
 assertEquals(ImmutableList.of("foo"), options.buildRequestHeaders().get(
     SwiftHeaders.CONTAINER_METADATA_PREFIX + "test"));
}

代码示例来源:origin: prestodb/presto

@Test(timeOut = 60 * 1000)
public void testTopologyAwareScheduling()
    throws Exception
  InMemoryNodeManager nodeManager = new InMemoryNodeManager();
  ImmutableList.Builder<Node> nodeBuilder = ImmutableList.builder();
  nodeBuilder.add(new PrestoNode("node1", URI.create("http://host1.rack1:11"), NodeVersion.UNKNOWN, false));
  nodeBuilder.add(new PrestoNode("node2", URI.create("http://host2.rack1:12"), NodeVersion.UNKNOWN, false));
  nonRackLocalSplits = Sets.difference(nonRackLocalSplits, new HashSet<>(assignments.values()));
  assertEquals(nonRackLocalSplits.size(), 3);
  assertEquals(unassigned.size(), 3);
  int rack1 = 0;
  int rack2 = 0;
        break;
      default:
        fail();
  assertEquals(rack1, 2);
  assertEquals(rack2, 1);
  assertEquals(assignments.size(), 3);
  assertEquals(assignments.keySet().size(), 3);

代码示例来源:origin: prestodb/presto

@Test
public void testMaxSplitsPerNodePerTask()
  nodeManager.addNode(CONNECTOR_ID, newNode);
  ImmutableList.Builder<Split> initialSplits = ImmutableList.builder();
  for (int i = 0; i < 20; i++) {
    initialSplits.add(new Split(CONNECTOR_ID, transactionHandle, new TestSplitRemote()));
    splits.add(new Split(CONNECTOR_ID, transactionHandle, new TestSplitRemote()));
  Multimap<Node, Split> assignments = nodeSelector.computeAssignments(splits, ImmutableList.copyOf(taskMap.values())).getAssignments();
  assertEquals(assignments.keySet().size(), 3); // Splits should be scheduled on the other three nodes
  assertFalse(assignments.keySet().contains(newNode)); // No splits scheduled on the maxed out node
  assertEquals(nodeTaskMap.getPartitionedSplitsOnNode(newNode), 0);

代码示例来源:origin: jclouds/legacy-jclouds

public void testTagsStatic() {
   CreateServiceOfferingOptions options = tags(ImmutableSet.<String>of("tag1", "tag2"));
   assertEquals(ImmutableSet.of("tag1", "tag2"), options.buildQueryParameters().get("tags"));
  }
}

代码示例来源:origin: prestodb/presto

@Test
public void testScheduleLocal()
{
  Split split = new Split(CONNECTOR_ID, TestingTransactionHandle.create(), new TestSplitLocal());
  Set<Split> splits = ImmutableSet.of(split);
  Map.Entry<Node, Split> assignment = Iterables.getOnlyElement(nodeSelector.computeAssignments(splits, ImmutableList.copyOf(taskMap.values())).getAssignments().entries());
  assertEquals(assignment.getKey().getHostAndPort(), split.getAddresses().get(0));
  assertEquals(assignment.getValue(), split);
}

代码示例来源:origin: prestodb/presto

@Test
public void testBasicAssignment()
{
  // One split for each node
  Set<Split> splits = new HashSet<>();
  for (int i = 0; i < 3; i++) {
    splits.add(new Split(CONNECTOR_ID, TestingTransactionHandle.create(), new TestSplitRemote()));
  }
  Multimap<Node, Split> assignments = nodeSelector.computeAssignments(splits, ImmutableList.copyOf(taskMap.values())).getAssignments();
  assertEquals(assignments.entries().size(), 3);
  for (Node node : nodeManager.getActiveConnectorNodes(CONNECTOR_ID)) {
    assertTrue(assignments.keySet().contains(node));
  }
}

代码示例来源:origin: prestodb/presto

@Test
public void testEmptyCursor()
{
  ListBasedRecordSet recordSet = new ListBasedRecordSet(ImmutableList.of(), ImmutableList.of(BIGINT, INTEGER));
  assertEquals(recordSet.getColumnTypes(), ImmutableList.of(BIGINT, INTEGER));
  RecordCursor cursor = recordSet.cursor();
  assertFalse(cursor.advanceNextPosition());
}

相关文章