org.assertj.core.api.AbstractIterableAssert.hasOnlyElementsOfType()方法的使用及代码示例

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

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

AbstractIterableAssert.hasOnlyElementsOfType介绍

[英]Verifies that all elements in the actual Iterable have the specified type (matching includes subclasses of the given type).

Example:

List<Number> numbers = new ArrayList<Number>(); 
numbers.add(1); 
numbers.add(2); 
numbers.add(3); 
// successful assertions: 
assertThat(numbers).hasOnlyElementsOfType(Number.class); 
assertThat(numbers).hasOnlyElementsOfType(Integer.class); 
// assertion failure: 
assertThat(numbers).hasOnlyElementsOfType(Long.class);

[中]验证实际Iterable中的所有元素是否具有指定的类型(匹配包括给定类型的子类)。
例子:

List<Number> numbers = new ArrayList<Number>(); 
numbers.add(1); 
numbers.add(2); 
numbers.add(3); 
// successful assertions: 
assertThat(numbers).hasOnlyElementsOfType(Number.class); 
assertThat(numbers).hasOnlyElementsOfType(Integer.class); 
// assertion failure: 
assertThat(numbers).hasOnlyElementsOfType(Long.class);

代码示例

代码示例来源:origin: com.datastax.cassandra/cassandra-driver-core

@Test(groups = "short", dataProvider = "connectionErrors")
public void should_retry_on_connection_error_if_statement_idempotent(
  ClosedConnectionConfig.CloseType closeType) {
 simulateError(1, closed_connection, new ClosedConnectionConfig(closeType));
 simulateError(2, closed_connection, new ClosedConnectionConfig(closeType));
 simulateError(3, closed_connection, new ClosedConnectionConfig(closeType));
 try {
  session.execute(new SimpleStatement("mock query").setIdempotent(true));
  Fail.fail("expected a TransportException");
 } catch (NoHostAvailableException e) {
  assertThat(e.getErrors().keySet())
    .hasSize(3)
    .containsOnly(
      host1.getSocketAddress(), host2.getSocketAddress(), host3.getSocketAddress());
  assertThat(e.getErrors().values()).hasOnlyElementsOfType(TransportException.class);
 }
 assertOnRequestErrorWasCalled(3, TransportException.class);
 assertThat(errors.getRetries().getCount()).isEqualTo(3);
 assertThat(errors.getConnectionErrors().getCount()).isEqualTo(3);
 assertThat(errors.getIgnoresOnConnectionError().getCount()).isEqualTo(0);
 assertThat(errors.getRetriesOnConnectionError().getCount()).isEqualTo(3);
 assertQueried(1, 1);
 assertQueried(2, 1);
 assertQueried(3, 1);
}

代码示例来源:origin: com.datastax.cassandra/cassandra-driver-core

@Test(groups = "short", dataProvider = "serverSideErrors")
public void should_try_next_host_on_server_side_error(
  Result error, Class<? extends DriverException> exception) {
 simulateError(1, error);
 simulateError(2, error);
 simulateError(3, error);
 try {
  query();
  Fail.fail("expected a NoHostAvailableException");
 } catch (NoHostAvailableException e) {
  assertThat(e.getErrors().keySet())
    .hasSize(3)
    .containsOnly(
      host1.getSocketAddress(), host2.getSocketAddress(), host3.getSocketAddress());
  assertThat(e.getErrors().values()).hasOnlyElementsOfType(exception);
 }
 assertOnRequestErrorWasCalled(3, exception);
 assertThat(errors.getOthers().getCount()).isEqualTo(3);
 assertThat(errors.getRetries().getCount()).isEqualTo(3);
 assertThat(errors.getRetriesOnOtherErrors().getCount()).isEqualTo(3);
 assertQueried(1, 1);
 assertQueried(2, 1);
 assertQueried(3, 1);
}

代码示例来源:origin: com.datastax.cassandra/cassandra-driver-core

@SuppressWarnings("UnusedParameters")
@Test(groups = "short", dataProvider = "serverSideErrors")
public void should_retry_on_server_error_if_statement_idempotent(
  Result error, Class<? extends DriverException> exception) {
 simulateError(1, error);
 simulateError(2, error);
 simulateError(3, error);
 try {
  session.execute(new SimpleStatement("mock query").setIdempotent(true));
  fail("expected a NoHostAvailableException");
 } catch (NoHostAvailableException e) {
  assertThat(e.getErrors().keySet())
    .hasSize(3)
    .containsOnly(
      host1.getSocketAddress(), host2.getSocketAddress(), host3.getSocketAddress());
  assertThat(e.getErrors().values()).hasOnlyElementsOfType(exception);
 }
 assertOnRequestErrorWasCalled(3, exception);
 assertThat(errors.getOthers().getCount()).isEqualTo(3);
 assertThat(errors.getRetries().getCount()).isEqualTo(3);
 assertThat(errors.getRetriesOnOtherErrors().getCount()).isEqualTo(3);
 assertQueried(1, 1);
 assertQueried(2, 1);
 assertQueried(3, 1);
}

代码示例来源:origin: com.datastax.cassandra/cassandra-driver-core

@Test(groups = "short", dataProvider = "connectionErrors")
public void should_try_next_host_on_connection_error(ClosedConnectionConfig.CloseType closeType) {
 simulateError(1, closed_connection, new ClosedConnectionConfig(closeType));
 simulateError(2, closed_connection, new ClosedConnectionConfig(closeType));
 simulateError(3, closed_connection, new ClosedConnectionConfig(closeType));
 try {
  query();
  Fail.fail("expected a NoHostAvailableException");
 } catch (NoHostAvailableException e) {
  assertThat(e.getErrors().keySet())
    .hasSize(3)
    .containsOnly(
      host1.getSocketAddress(), host2.getSocketAddress(), host3.getSocketAddress());
  assertThat(e.getErrors().values()).hasOnlyElementsOfType(TransportException.class);
 }
 assertOnRequestErrorWasCalled(3, TransportException.class);
 assertThat(errors.getRetries().getCount()).isEqualTo(3);
 assertThat(errors.getConnectionErrors().getCount()).isEqualTo(3);
 assertThat(errors.getIgnoresOnConnectionError().getCount()).isEqualTo(0);
 assertThat(errors.getRetriesOnConnectionError().getCount()).isEqualTo(3);
 assertQueried(1, 1);
 assertQueried(2, 1);
 assertQueried(3, 1);
}

代码示例来源:origin: com.datastax.cassandra/cassandra-driver-core

/**
 * Ensures that when handling a connection error caused by the connection closing during a request
 * in a way described by {@link #connectionErrors} that the next host is tried.
 *
 * @param closeType The way the connection should be closed during the request.
 */
@Test(groups = "short", dataProvider = "connectionErrors")
public void should_try_next_host_on_connection_error(ClosedConnectionConfig.CloseType closeType) {
 simulateError(1, closed_connection, new ClosedConnectionConfig(closeType));
 simulateError(2, closed_connection, new ClosedConnectionConfig(closeType));
 simulateError(3, closed_connection, new ClosedConnectionConfig(closeType));
 try {
  query();
  Fail.fail("expected a TransportException");
 } catch (NoHostAvailableException e) {
  assertThat(e.getErrors().keySet())
    .hasSize(3)
    .containsOnly(
      host1.getSocketAddress(), host2.getSocketAddress(), host3.getSocketAddress());
  assertThat(e.getErrors().values()).hasOnlyElementsOfType(TransportException.class);
 }
 assertOnRequestErrorWasCalled(3, TransportException.class);
 assertThat(errors.getRetries().getCount()).isEqualTo(3);
 assertThat(errors.getConnectionErrors().getCount()).isEqualTo(3);
 assertThat(errors.getIgnoresOnConnectionError().getCount()).isEqualTo(0);
 assertThat(errors.getRetriesOnConnectionError().getCount()).isEqualTo(3);
 assertQueried(1, 1);
 assertQueried(2, 1);
 assertQueried(3, 1);
}

代码示例来源:origin: com.datastax.cassandra/cassandra-driver-core

.containsOnly(
    host1.getSocketAddress(), host2.getSocketAddress(), host3.getSocketAddress());
assertThat(e.getErrors().values()).hasOnlyElementsOfType(exception);

代码示例来源:origin: com.datastax.cassandra/cassandra-driver-core

host1.getSocketAddress(), host2.getSocketAddress(), host3.getSocketAddress());
assertThat(e.getErrors().values())
  .hasOnlyElementsOfType(OperationTimedOutException.class)
  .extractingResultOf("getMessage")
  .containsOnlyOnce(

代码示例来源:origin: com.datastax.cassandra/cassandra-driver-core

host1.getSocketAddress(), host2.getSocketAddress(), host3.getSocketAddress());
assertThat(e.getErrors().values())
  .hasOnlyElementsOfType(OperationTimedOutException.class)
  .extractingResultOf("getMessage")
  .containsOnlyOnce(

代码示例来源:origin: com.datastax.dse/dse-java-driver-core

@Test(groups = "short", dataProvider = "serverSideErrors")
public void should_try_next_host_on_server_side_error(
  Result error, Class<? extends DriverException> exception) {
 simulateError(1, error);
 simulateError(2, error);
 simulateError(3, error);
 try {
  query();
  Fail.fail("expected a NoHostAvailableException");
 } catch (NoHostAvailableException e) {
  assertThat(e.getErrors().keySet())
    .hasSize(3)
    .containsOnly(
      host1.getSocketAddress(), host2.getSocketAddress(), host3.getSocketAddress());
  assertThat(e.getErrors().values()).hasOnlyElementsOfType(exception);
 }
 assertOnRequestErrorWasCalled(3, exception);
 assertThat(errors.getOthers().getCount()).isEqualTo(3);
 assertThat(errors.getRetries().getCount()).isEqualTo(3);
 assertThat(errors.getRetriesOnOtherErrors().getCount()).isEqualTo(3);
 assertQueried(1, 1);
 assertQueried(2, 1);
 assertQueried(3, 1);
}

代码示例来源:origin: com.datastax.dse/dse-java-driver-core

@SuppressWarnings("UnusedParameters")
@Test(groups = "short", dataProvider = "serverSideErrors")
public void should_retry_on_server_error_if_statement_idempotent(
  Result error, Class<? extends DriverException> exception) {
 simulateError(1, error);
 simulateError(2, error);
 simulateError(3, error);
 try {
  session.execute(new SimpleStatement("mock query").setIdempotent(true));
  fail("expected a NoHostAvailableException");
 } catch (NoHostAvailableException e) {
  assertThat(e.getErrors().keySet())
    .hasSize(3)
    .containsOnly(
      host1.getSocketAddress(), host2.getSocketAddress(), host3.getSocketAddress());
  assertThat(e.getErrors().values()).hasOnlyElementsOfType(exception);
 }
 assertOnRequestErrorWasCalled(3, exception);
 assertThat(errors.getOthers().getCount()).isEqualTo(3);
 assertThat(errors.getRetries().getCount()).isEqualTo(3);
 assertThat(errors.getRetriesOnOtherErrors().getCount()).isEqualTo(3);
 assertQueried(1, 1);
 assertQueried(2, 1);
 assertQueried(3, 1);
}

代码示例来源:origin: com.datastax.dse/dse-java-driver-core

@Test(groups = "short", dataProvider = "connectionErrors")
public void should_try_next_host_on_connection_error(ClosedConnectionConfig.CloseType closeType) {
 simulateError(1, closed_connection, new ClosedConnectionConfig(closeType));
 simulateError(2, closed_connection, new ClosedConnectionConfig(closeType));
 simulateError(3, closed_connection, new ClosedConnectionConfig(closeType));
 try {
  query();
  Fail.fail("expected a NoHostAvailableException");
 } catch (NoHostAvailableException e) {
  assertThat(e.getErrors().keySet())
    .hasSize(3)
    .containsOnly(
      host1.getSocketAddress(), host2.getSocketAddress(), host3.getSocketAddress());
  assertThat(e.getErrors().values()).hasOnlyElementsOfType(TransportException.class);
 }
 assertOnRequestErrorWasCalled(3, TransportException.class);
 assertThat(errors.getRetries().getCount()).isEqualTo(3);
 assertThat(errors.getConnectionErrors().getCount()).isEqualTo(3);
 assertThat(errors.getIgnoresOnConnectionError().getCount()).isEqualTo(0);
 assertThat(errors.getRetriesOnConnectionError().getCount()).isEqualTo(3);
 assertQueried(1, 1);
 assertQueried(2, 1);
 assertQueried(3, 1);
}

代码示例来源:origin: com.datastax.dse/dse-java-driver-core

@Test(groups = "short", dataProvider = "connectionErrors")
public void should_retry_on_connection_error_if_statement_idempotent(
  ClosedConnectionConfig.CloseType closeType) {
 simulateError(1, closed_connection, new ClosedConnectionConfig(closeType));
 simulateError(2, closed_connection, new ClosedConnectionConfig(closeType));
 simulateError(3, closed_connection, new ClosedConnectionConfig(closeType));
 try {
  session.execute(new SimpleStatement("mock query").setIdempotent(true));
  Fail.fail("expected a TransportException");
 } catch (NoHostAvailableException e) {
  assertThat(e.getErrors().keySet())
    .hasSize(3)
    .containsOnly(
      host1.getSocketAddress(), host2.getSocketAddress(), host3.getSocketAddress());
  assertThat(e.getErrors().values()).hasOnlyElementsOfType(TransportException.class);
 }
 assertOnRequestErrorWasCalled(3, TransportException.class);
 assertThat(errors.getRetries().getCount()).isEqualTo(3);
 assertThat(errors.getConnectionErrors().getCount()).isEqualTo(3);
 assertThat(errors.getIgnoresOnConnectionError().getCount()).isEqualTo(0);
 assertThat(errors.getRetriesOnConnectionError().getCount()).isEqualTo(3);
 assertQueried(1, 1);
 assertQueried(2, 1);
 assertQueried(3, 1);
}

代码示例来源:origin: com.datastax.dse/dse-java-driver-core

/**
 * Ensures that when handling a connection error caused by the connection closing during a request
 * in a way described by {@link #connectionErrors} that the next host is tried.
 *
 * @param closeType The way the connection should be closed during the request.
 */
@Test(groups = "short", dataProvider = "connectionErrors")
public void should_try_next_host_on_connection_error(ClosedConnectionConfig.CloseType closeType) {
 simulateError(1, closed_connection, new ClosedConnectionConfig(closeType));
 simulateError(2, closed_connection, new ClosedConnectionConfig(closeType));
 simulateError(3, closed_connection, new ClosedConnectionConfig(closeType));
 try {
  query();
  Fail.fail("expected a TransportException");
 } catch (NoHostAvailableException e) {
  assertThat(e.getErrors().keySet())
    .hasSize(3)
    .containsOnly(
      host1.getSocketAddress(), host2.getSocketAddress(), host3.getSocketAddress());
  assertThat(e.getErrors().values()).hasOnlyElementsOfType(TransportException.class);
 }
 assertOnRequestErrorWasCalled(3, TransportException.class);
 assertThat(errors.getRetries().getCount()).isEqualTo(3);
 assertThat(errors.getConnectionErrors().getCount()).isEqualTo(3);
 assertThat(errors.getIgnoresOnConnectionError().getCount()).isEqualTo(0);
 assertThat(errors.getRetriesOnConnectionError().getCount()).isEqualTo(3);
 assertQueried(1, 1);
 assertQueried(2, 1);
 assertQueried(3, 1);
}

代码示例来源:origin: com.datastax.dse/dse-java-driver-core

.containsOnly(
    host1.getSocketAddress(), host2.getSocketAddress(), host3.getSocketAddress());
assertThat(e.getErrors().values()).hasOnlyElementsOfType(exception);

代码示例来源:origin: com.datastax.dse/dse-java-driver-core

host1.getSocketAddress(), host2.getSocketAddress(), host3.getSocketAddress());
assertThat(e.getErrors().values())
  .hasOnlyElementsOfType(OperationTimedOutException.class)
  .extractingResultOf("getMessage")
  .containsOnlyOnce(

代码示例来源:origin: com.datastax.dse/dse-java-driver-core

host1.getSocketAddress(), host2.getSocketAddress(), host3.getSocketAddress());
assertThat(e.getErrors().values())
  .hasOnlyElementsOfType(OperationTimedOutException.class)
  .extractingResultOf("getMessage")
  .containsOnlyOnce(

相关文章

微信公众号

最新文章

更多