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

x33g5p2x  于2022-01-20 转载在 其他  
字(9.2k)|赞(0)|评价(0)|浏览(160)

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

IterableAssert.hasSize介绍

暂无

代码示例

代码示例来源:origin: SonarSource/sonarqube

@Test
public void each_call_must_return_a_new_ceworker_with_unique_uuid() {
 Set<CeWorker> ceWorkers = new HashSet<>();
 Set<String> ceWorkerUUIDs = new HashSet<>();
 for (int i = 0; i < 10; i++) {
  CeWorker ceWorker = underTest.create(i);
  ceWorkers.add(ceWorker);
  ceWorkerUUIDs.add(ceWorker.getUUID());
 }
 assertThat(ceWorkers).hasSize(10);
 assertThat(ceWorkerUUIDs).hasSize(10);
}

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

private String getAttribute() {
    MessageSecurityMetadataSource source = messages.createMetadataSource();
    Collection<ConfigAttribute> attrs = source.getAttributes(message);
    if (attrs == null) {
      return null;
    }
    assertThat(attrs).hasSize(1);
    return attrs.iterator().next().toString();
  }
}

代码示例来源:origin: stagemonitor/stagemonitor

@Test
public void mergeDefinitions_EncodedObjects_RetainsFieldsOnlySpecifiedInSource() throws Exception {
  // Given
  JsonNode a = mapper.readTree("{\"a\": \"{\\\"a1\\\": \\\"a1source\\\",\\\"a2\\\": \\\"a2source\\\"}\"}");
  JsonNode b = mapper.readTree("{\"a\": \"{}\"}");
  // When
  JsonNode result = JsonMerger.merge(a, b, mergeStrategy().mergeEncodedObjects("a"));
  assertThat(result).hasSize(1);
  // Then
  JsonNode encodedObject = mapper.readTree(result.get("a").textValue());
  assertThat(encodedObject).hasSize(2);
  assertThat(encodedObject.get("a1").textValue()).isEqualTo("a1source");
  assertThat(encodedObject.get("a2").textValue()).isEqualTo("a2source");
}

代码示例来源:origin: cbeust/testng

private ITestResult runAssertions(Set<ITestResult> results, String methodName) {
 assertThat(results).hasSize(1);
 ITestResult firstResult = results.iterator().next();
 assertThat(firstResult.getMethod().getMethodName()).isEqualToIgnoringCase(methodName);
 return firstResult;
}

代码示例来源:origin: evernote/android-job

private void verifyScheduleInNextHour(Clock clock) {
  JobConfig.setClock(clock);
  Calendar calendar = Calendar.getInstance();
  calendar.setTimeInMillis(clock.currentTimeMillis());
  int hour = calendar.get(Calendar.HOUR_OF_DAY);
  int minute = calendar.get(Calendar.MINUTE);
  long start = TimeUnit.HOURS.toMillis(hour + 1) + TimeUnit.MINUTES.toMillis(minute);
  long end = start + TimeUnit.HOURS.toMillis(1);
  DailyJob.schedule(DummyJobs.createBuilder(DummyJobs.SuccessJob.class), start, end);
  assertThat(manager().getAllJobRequests()).hasSize(1);
  JobRequest request = manager().getAllJobRequests().iterator().next();
  assertThat(request.getStartMs()).isEqualTo(TimeUnit.HOURS.toMillis(1));
  assertThat(request.getEndMs()).isEqualTo(TimeUnit.HOURS.toMillis(2));
}

代码示例来源:origin: evernote/android-job

@Test
public void verifyScheduledImmediatelyIsNotOverridden() {
  long time = 1L;
  DailyJob.startNowOnce(DummyJobs.createBuilder(DummyJobs.SuccessJob.class));
  DailyJob.schedule(DummyJobs.createBuilder(DummyJobs.SuccessJob.class), time, time);
  Set<JobRequest> requests = manager().getAllJobRequests();
  assertThat(requests).hasSize(2);
  for (JobRequest request : requests) {
    assertThat(request.getTag()).isEqualTo(DummyJobs.SuccessJob.TAG);
  }
}

代码示例来源:origin: stagemonitor/stagemonitor

@Test
public void mergeDefinitions_EncodedObjects_ReplacesFieldsSpecifiedInBoth() throws Exception {
  // Given
  JsonNode a = mapper.readTree("{\"a\": \"{\\\"a1\\\": \\\"a1source\\\",\\\"a2\\\": \\\"a2source\\\"}\"}");
  JsonNode b = mapper.readTree("{\"a\": \"{\\\"b1\\\": \\\"b1replacement\\\",\\\"a1\\\": \\\"a1replacement\\\"}\"}");
  // When
  JsonNode result = JsonMerger.merge(a, b, mergeStrategy().mergeEncodedObjects("a"));
  assertThat(result).hasSize(1);
  // Then
  JsonNode encodedObject = mapper.readTree(result.get("a").textValue());
  assertThat(encodedObject).hasSize(3);
  assertThat(encodedObject.get("a1").textValue()).isEqualTo("a1replacement");
  assertThat(encodedObject.get("a2").textValue()).isEqualTo("a2source");
  assertThat(encodedObject.get("b1").textValue()).isEqualTo("b1replacement");
}

代码示例来源:origin: square/leakcanary

@Test
public void ensureUniqueRoots() {
 Snapshot snapshot = createSnapshot(DUP_ROOTS);
 heapAnalyzer.deduplicateGcRoots(snapshot);
 Collection<RootObj> uniqueRoots = snapshot.getGCRoots();
 assertThat(uniqueRoots).hasSize(4);
 List<Long> rootIds = new ArrayList<>();
 for (RootObj root : uniqueRoots) {
  rootIds.add(root.getId());
 }
 Collections.sort(rootIds);
 // 3 appears twice because even though two RootObjs have the same id, they're different types.
 assertThat(rootIds).containsExactly(3L, 3L, 5L, 6L);
}

代码示例来源:origin: evernote/android-job

private void verifyScheduleOverMidnight(Clock clock) {
  JobConfig.setClock(clock);
  long start = TimeUnit.HOURS.toMillis(24) - 1L;
  long end = 1L;
  DailyJob.schedule(DummyJobs.createBuilder(DummyJobs.SuccessJob.class), start, end);
  assertThat(manager().getAllJobRequests()).hasSize(1);
  JobRequest request = manager().getAllJobRequests().iterator().next();
  Calendar calendar = Calendar.getInstance();
  calendar.setTimeInMillis(clock.currentTimeMillis());
  int hour = calendar.get(Calendar.HOUR_OF_DAY);
  long maxStart = TimeUnit.HOURS.toMillis(24 - hour);
  assertThat(request.getStartMs()).isLessThan(maxStart);
  assertThat(request.getEndMs()).isLessThan(maxStart + 3);
}

代码示例来源:origin: SonarSource/sonarqube

@Test
public void define_controller() {
 assertThat(controller).isNotNull();
 assertThat(controller.since()).isEqualTo("2.10");
 assertThat(controller.description()).isNotEmpty();
 assertThat(controller.actions()).hasSize(1);
}

代码示例来源:origin: SonarSource/sonarqube

@Test
 public void should_findOldest() {
  db.prepareDbUnit(getClass(), "should_findOldest.xml");

  Collection<NotificationQueueDto> result = dao.selectOldest(3);
  assertThat(result).hasSize(3);
  assertThat(result).extracting("id").containsOnly(1L, 2L, 3L);

  result = dao.selectOldest(6);
  assertThat(result).hasSize(4);
 }
}

代码示例来源:origin: SonarSource/sonarqube

@Test
public void define_controller() {
 assertThat(controller).isNotNull();
 assertThat(controller.description()).isNotEmpty();
 assertThat(controller.since()).isEqualTo("5.2");
 assertThat(controller.actions()).hasSize(2);
}

代码示例来源:origin: SonarSource/sonarqube

@Test
public void define_ws() {
 WebService.Controller controller = ws.controller("api/metrics");
 assertThat(controller).isNotNull();
 assertThat(controller.description()).isNotEmpty();
 assertThat(controller.actions()).hasSize(6);
}

代码示例来源:origin: SonarSource/sonarqube

@Test
public void define_controller() {
 assertThat(controller).isNotNull();
 assertThat(controller.since()).isEqualTo("2.10");
 assertThat(controller.description()).isNotEmpty();
 assertThat(controller.actions()).hasSize(1);
}

代码示例来源:origin: SonarSource/sonarqube

@Test
public void define_search_action() {
 WebService.Action action = controller.action("search");
 assertThat(action).isNotNull();
 assertThat(action.responseExampleAsString()).isNotEmpty();
 assertThat(action.params()).hasSize(5);
}

代码示例来源:origin: SonarSource/sonarqube

@Test
public void define_controller() {
 assertThat(controller).isNotNull();
 assertThat(controller.description()).isNotEmpty();
 assertThat(controller.since()).isEqualTo("3.6");
 assertThat(controller.actions()).hasSize(4);
}

代码示例来源:origin: SonarSource/sonarqube

@Test
public void test_ws_definition() {
 WebService.Action action = ws.getDef();
 assertThat(action).isNotNull();
 assertThat(action.isInternal()).isFalse();
 assertThat(action.isPost()).isTrue();
 assertThat(action.responseExampleAsString()).isNotEmpty();
 assertThat(action.params()).hasSize(2);
}

代码示例来源:origin: SonarSource/sonarqube

@Test
public void generate_returns_unique_values_without_common_initial_letter_given_more_than_one_millisecond_between_generate_calls() throws InterruptedException {
 Base64.Encoder encoder = Base64.getEncoder();
 int count = 30;
 Set<String> uuids = new HashSet<>(count);
 for (int i = 0; i < count; i++) {
  Thread.sleep(5);
  uuids.add(encoder.encodeToString(underTest.generate()));
 }
 assertThat(uuids).hasSize(count);
 Iterator<String> iterator = uuids.iterator();
 String firstUuid = iterator.next();
 String base = firstUuid.substring(0, firstUuid.length() - 4);
 for (int i = 1; i < count; i++) {
  assertThat(iterator.next()).describedAs("i=" + i).doesNotStartWith(base);
 }
}

代码示例来源:origin: SonarSource/sonarqube

@Test
public void define_create_action() {
 WebService.Action action = ws.getDef();
 assertThat(action).isNotNull();
 assertThat(action.isPost()).isTrue();
 assertThat(action.handler()).isNotNull();
 assertThat(action.responseExampleAsString()).isNotEmpty();
 assertThat(action.params()).hasSize(4);
}

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

@Test
public void createExpressionMessageMetadataSourceMatchFirst() {
  when(matcher1.matches(message)).thenReturn(true);
  Collection<ConfigAttribute> attrs = source.getAttributes(message);
  assertThat(attrs).hasSize(1);
  ConfigAttribute attr = attrs.iterator().next();
  assertThat(attr).isInstanceOf(MessageExpressionConfigAttribute.class);
  assertThat(
      ((MessageExpressionConfigAttribute) attr).getAuthorizeExpression()
          .getValue(rootObject)).isEqualTo(true);
}

相关文章