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

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

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

AbstractIterableAssert.hasSize介绍

暂无

代码示例

代码示例来源:origin: facebook/litho

public LithoViewAssert containsTestKey(String testKey, OccurrenceCount count) {
 final Deque<TestItem> testItems = LithoViewTestHelper.findTestItems(actual, testKey);
 Java6Assertions.assertThat(testItems)
   .hasSize(count.times)
   .overridingErrorMessage(
     "Expected to find test key <%s> in LithoView <%s> %s, but %s.",
     testKey,
     actual,
     count,
     testItems.isEmpty() ?
       "couldn't find it" :
       String.format(Locale.ROOT, "saw it %d times instead", testItems.size()))
   .isNotNull();
 return this;
}

代码示例来源:origin: eclipse-vertx/vert.x

@Test
public void loadFactoriesWithVertxClassloader() throws Exception {
 // This test is a bit more tricky as we need to load the ServiceHelper class from a custom classloader.
 ClassLoader custom = new URLClassLoader(new URL[]{
   new File("target/classes").toURI().toURL(),
   new File("target/test-classes").toURI().toURL(),
   new File("target/externals").toURI().toURL(),
 }, null);
 Class serviceHelperClass = custom.loadClass(ServiceHelper.class.getName());
 Class someFactoryClass = custom.loadClass(SomeFactory.class.getName());
 assertThat(serviceHelperClass.getClassLoader()).isEqualTo(custom);
 assertThat(someFactoryClass.getClassLoader()).isEqualTo(custom);
 Method method = serviceHelperClass.getMethod("loadFactories", Class.class);
 Collection collection = (Collection) method.invoke(null, someFactoryClass);
 assertThat(collection).hasSize(1);
}

代码示例来源:origin: eclipse-vertx/vert.x

@Test
public void loadFactoriesWithClassloader() throws Exception {
 ClassLoader custom = new URLClassLoader(new URL[]{new File("target/externals").toURI().toURL()});
 // Try without the custom classloader.
 Collection<SomeFactory> factories = ServiceHelper.loadFactories(SomeFactory.class);
 assertThat(factories)
   .isNotNull()
   .hasSize(0);
 // Try with the custom classloader
 factories = ServiceHelper.loadFactories(SomeFactory.class, custom);
 assertThat(factories)
   .isNotNull()
   .hasSize(1);
 assertThat(factories.iterator().next().classloader()).isEqualTo(custom);
}

代码示例来源:origin: eclipse-vertx/vert.x

@Test
public void loadFactoriesFromTCCL() throws Exception {
 ClassLoader custom = new URLClassLoader(new URL[]{new File("target/externals").toURI().toURL()});
 // Try without the TCCL classloader.
 Collection<SomeFactory> factories = ServiceHelper.loadFactories(SomeFactory.class);
 assertThat(factories)
   .isNotNull()
   .hasSize(0);
 // Try with the TCCL classloader
 final ClassLoader originalTCCL = Thread.currentThread().getContextClassLoader();
 try {
  Thread.currentThread().setContextClassLoader(custom);
  factories = ServiceHelper.loadFactories(SomeFactory.class);
  assertThat(factories)
    .isNotNull()
    .hasSize(1);
  assertThat(factories.iterator().next().classloader()).isEqualTo(custom);
 } finally {
  Thread.currentThread().setContextClassLoader(originalTCCL);
 }
}

代码示例来源:origin: eclipse-vertx/vert.x

@Test
public void loadFactories() throws Exception {
 Collection<FakeFactory> factories = ServiceHelper.loadFactories(FakeFactory.class);
 assertThat(factories)
   .isNotNull()
   .hasSize(2);
 Collection<NotImplementedSPI> impl = ServiceHelper.loadFactories(NotImplementedSPI.class);
 assertThat(impl)
   .isNotNull()
   .hasSize(0);
}

代码示例来源:origin: json-path/JsonPath

@Test
  public void evaluation_listeners_can_be_cleared() {

    EvaluationListener listener = new EvaluationListener() {
      @Override
      public EvaluationContinuation resultFound(FoundResult found) {
        return EvaluationContinuation.CONTINUE;
      }
    };

    Configuration configuration1 = Configuration.builder().evaluationListener(listener).build();
    Configuration configuration2 = configuration1.setEvaluationListeners();

    assertThat(configuration1.getEvaluationListeners()).hasSize(1);
    assertThat(configuration2.getEvaluationListeners()).hasSize(0);
  }
}

代码示例来源:origin: facebook/litho

private void verifyErrors(int errorNumber, FieldModel... fields) {
  when(layoutSpecModel.getFields()).thenReturn(ImmutableList.of(fields));

  Collection<SpecModelValidationError> validationErrors =
    FieldsValidation.validate(layoutSpecModel);

  assertThat(validationErrors).hasSize(errorNumber);

  for (SpecModelValidationError validationError : validationErrors) {
   assertThat(validationError.element).isSameAs(representedObject);
   assertThat(validationError.message)
     .isEqualTo(FIELD_TEST_NAME + " should be declared static and final.");
  }
 }
}

代码示例来源:origin: eclipse-vertx/vert.x

assertThat(command.states).hasSize(3).containsExactly(Thread.State.NEW, Thread.State.BLOCKED,
  Thread.State.RUNNABLE);
assertThat(command.ints).hasSize(3).containsExactly(1, 2, 3);
assertThat(command.strings).hasSize(1).containsExactly("a");

代码示例来源:origin: eclipse-vertx/vert.x

@Test
public void testMissingRequiredOption() throws Exception {
 String[] args = new String[]{"-a"};
 TypedOption<String> b = new TypedOption<String>().setShortName("b").setLongName("bfile")
   .setSingleValued(true)
   .setDescription("set the value of [b]").setType(String.class).setRequired(true);
 cli.removeOption("b").addOption(b);
 try {
  cli.parse(Arrays.asList(args));
  fail("exception expected");
 } catch (MissingOptionException e) {
  assertThat(e.getExpected()).hasSize(1);
 }
}

代码示例来源:origin: lingochamp/okdownload

ArgumentCaptor.forClass(Collection.class);
verify(OkDownload.with().callbackDispatcher()).endTasksWithCanceled(callCaptor.capture());
assertThat(callCaptor.getValue()).hasSize(12);
for (DownloadCall call : mockReadyAsyncCalls) {
  verify(call, never()).cancel();

代码示例来源:origin: facebook/litho

@Test
public void testFieldExtraction() {
 final TypeElement element =
   compilationRule.getElements().getTypeElement(TwoFieldsClass.class.getCanonicalName());
 ImmutableList<FieldModel> fieldModels = FieldsExtractor.extractFields(element);
 assertThat(fieldModels).hasSize(2);
 FieldSpec extractedIntField = fieldModels.get(0).field;
 assertThat(extractedIntField.name).isEqualTo("intField");
 assertThat(extractedIntField.modifiers).hasSize(3);
 assertThat(extractedIntField.hasModifier(Modifier.PRIVATE));
 assertThat(extractedIntField.hasModifier(Modifier.STATIC));
 assertThat(extractedIntField.hasModifier(Modifier.FINAL));
 FieldSpec extractedFloatField = fieldModels.get(1).field;
 assertThat(extractedFloatField.name).isEqualTo("floatField");
 assertThat(extractedFloatField.modifiers).hasSize(1);
 assertThat(extractedFloatField.hasModifier(Modifier.STATIC));
}

代码示例来源:origin: lingochamp/okdownload

@Test
public void addHeader_getRequestHeaderFiles_meet() throws IOException {
  assertThat(connection.getRequestProperty("no-exist-key")).isNull();
  DownloadOkHttp3Connection.Factory creator = new DownloadOkHttp3Connection.Factory();
  DownloadOkHttp3Connection connection = (DownloadOkHttp3Connection) creator.create(URL);
  connection.addHeader("mock", "mock");
  connection.addHeader("mock1", "mock2");
  connection.addHeader("mock1", "mock3");
  assertThat(connection.getRequestProperty("mock")).isEqualTo("mock");
  Map<String, List<String>> headers = connection.getRequestProperties();
  assertThat(headers.keySet()).hasSize(2).contains("mock", "mock1");
  List<String> allValues = new ArrayList<>();
  Collection<List<String>> valueList = headers.values();
  for (List<String> values : valueList) {
    allValues.addAll(values);
  }
  assertThat(allValues).hasSize(3).contains("mock", "mock2", "mock3");
}

代码示例来源:origin: eclipse-vertx/vert.x

@Test
public void testMissingRequiredOptions() throws CLIException {
 String[] args = new String[]{"-a"};
 TypedOption<String> b = new TypedOption<String>().setShortName("b").setLongName("bfile").setSingleValued(true)
   .setDescription("set the value of [b]").setType(String.class).setRequired(true);
 TypedOption<Boolean> c = new TypedOption<Boolean>().setShortName("c").setLongName("copt").setSingleValued(false)
   .setDescription("turn [c] on or off").setType(Boolean.class).setRequired(true);
 cli.removeOption("b").addOption(b).removeOption("c").addOption(c);
 try {
  CommandLine evaluated = cli.parse(Arrays.asList(args));
  fail("exception expected");
 } catch (MissingOptionException e) {
  assertThat(e.getExpected()).hasSize(2);
 }
}

代码示例来源:origin: facebook/litho

assertThat(set).hasSize(1);
set.remove(testElt1);
assertThat(set)
  .doesNotContain(testElt4)
  .doesNotContain(testElt5)
  .hasSize(3)
  .isNotEmpty();
assertThat(checkIterator(set)).isTrue();
  .contains(testElt3)
  .doesNotContain(testElt4)
  .hasSize(2);
assertThat(checkIterator(set)).isTrue();
  .contains(testElt3)
  .contains(testElt4)
  .hasSize(3);
assertThat(checkIterator(set)).isTrue();
assertThat(set)
  .contains(testElt5)
  .hasSize(4);
assertThat(checkIterator(set)).isTrue();
assertThat(set.remove(testElt5)).isTrue();
  .contains(testElt3)
  .contains(testElt4)
  .hasSize(3);

代码示例来源:origin: io.vertx/vertx-core

@Test
public void loadFactoriesWithVertxClassloader() throws Exception {
 // This test is a bit more tricky as we need to load the ServiceHelper class from a custom classloader.
 ClassLoader custom = new URLClassLoader(new URL[]{
   new File("target/classes").toURI().toURL(),
   new File("target/test-classes").toURI().toURL(),
   new File("target/externals").toURI().toURL(),
 }, null);
 Class serviceHelperClass = custom.loadClass(ServiceHelper.class.getName());
 Class someFactoryClass = custom.loadClass(SomeFactory.class.getName());
 assertThat(serviceHelperClass.getClassLoader()).isEqualTo(custom);
 assertThat(someFactoryClass.getClassLoader()).isEqualTo(custom);
 Method method = serviceHelperClass.getMethod("loadFactories", Class.class);
 Collection collection = (Collection) method.invoke(null, someFactoryClass);
 assertThat(collection).hasSize(1);
}

代码示例来源:origin: io.vertx/vertx-core

@Test
public void loadFactoriesWithClassloader() throws Exception {
 ClassLoader custom = new URLClassLoader(new URL[]{new File("target/externals").toURI().toURL()});
 // Try without the custom classloader.
 Collection<SomeFactory> factories = ServiceHelper.loadFactories(SomeFactory.class);
 assertThat(factories)
   .isNotNull()
   .hasSize(0);
 // Try with the custom classloader
 factories = ServiceHelper.loadFactories(SomeFactory.class, custom);
 assertThat(factories)
   .isNotNull()
   .hasSize(1);
 assertThat(factories.iterator().next().classloader()).isEqualTo(custom);
}

代码示例来源:origin: io.vertx/vertx-core

@Test
public void loadFactories() throws Exception {
 Collection<FakeFactory> factories = ServiceHelper.loadFactories(FakeFactory.class);
 assertThat(factories)
   .isNotNull()
   .hasSize(2);
 Collection<NotImplementedSPI> impl = ServiceHelper.loadFactories(NotImplementedSPI.class);
 assertThat(impl)
   .isNotNull()
   .hasSize(0);
}

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

private void checkRangesPerHost(String keyspace, int replicationFactor) {
 List<TokenRange> allRangesWithReplicas = Lists.newArrayList();
 // Get each host's ranges, the count should match the replication factor
 for (int i = 1; i <= 3; i++) {
  Host host = TestUtils.findHost(cluster(), i);
  Set<TokenRange> hostRanges = cluster().getMetadata().getTokenRanges(keyspace, host);
  // Special case: When using vnodes the tokens are not evenly assigned to each replica.
  if (!useVnodes) {
   assertThat(hostRanges).hasSize(replicationFactor * numTokens);
  }
  allRangesWithReplicas.addAll(hostRanges);
 }
 // Special case check for vnodes to ensure that total number of replicated ranges is correct.
 assertThat(allRangesWithReplicas).hasSize(3 * numTokens * replicationFactor);
 // Once we ignore duplicates, the number of ranges should match the number of nodes.
 Set<TokenRange> allRanges = new HashSet<TokenRange>(allRangesWithReplicas);
 assertThat(allRanges).hasSize(3 * numTokens);
 // And the ranges should cover the whole ring and no ranges intersect.
 assertThat(cluster()).hasValidTokenRanges(keyspace);
}

代码示例来源:origin: io.vertx/vertx-core

@Test
public void testMissingRequiredOption() throws Exception {
 String[] args = new String[]{"-a"};
 TypedOption<String> b = new TypedOption<String>().setShortName("b").setLongName("bfile")
   .setSingleValued(true)
   .setDescription("set the value of [b]").setType(String.class).setRequired(true);
 cli.removeOption("b").addOption(b);
 try {
  cli.parse(Arrays.asList(args));
  fail("exception expected");
 } catch (MissingOptionException e) {
  assertThat(e.getExpected()).hasSize(1);
 }
}

代码示例来源:origin: io.vertx/vertx-core

@Test
public void testMissingRequiredOptions() throws CLIException {
 String[] args = new String[]{"-a"};
 TypedOption<String> b = new TypedOption<String>().setShortName("b").setLongName("bfile").setSingleValued(true)
   .setDescription("set the value of [b]").setType(String.class).setRequired(true);
 TypedOption<Boolean> c = new TypedOption<Boolean>().setShortName("c").setLongName("copt").setSingleValued(false)
   .setDescription("turn [c] on or off").setType(Boolean.class).setRequired(true);
 cli.removeOption("b").addOption(b).removeOption("c").addOption(c);
 try {
  CommandLine evaluated = cli.parse(Arrays.asList(args));
  fail("exception expected");
 } catch (MissingOptionException e) {
  assertThat(e.getExpected()).hasSize(2);
 }
}

相关文章

微信公众号

最新文章

更多