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

x33g5p2x  于2022-01-23 转载在 其他  
字(11.3k)|赞(0)|评价(0)|浏览(118)

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

ListAssert.allSatisfy介绍

暂无

代码示例

代码示例来源:origin: reactor/reactor-core

@SuppressWarnings("unchecked")
private void validateSubscribers(int size) {
  List<Throwable> errors = Collections.synchronizedList(new ArrayList<>(size));
  Subscriber<Integer>[] subs = new Subscriber[size];
  for (int i = 0; i < subs.length; i++) {
    subs[i] = new BaseSubscriber<Integer>() {
      @Override
      protected void hookOnSubscribe(Subscription subscription) { requestUnbounded(); }
      @Override
      protected void hookOnNext(Integer value) { }
      @Override
      protected void hookOnError(Throwable throwable) {
        errors.add(throwable);
      }
    };
  }
  Flux.range(1, 3)
    .parallel(3)
    .validate(subs);
  assertThat(errors)
       .hasSize(size)
       .allSatisfy(e -> assertThat(e).hasMessage("parallelism = 3, subscribers = " + size));
}

代码示例来源:origin: reactor/reactor-core

@Test
public void fluxApiErrorContinue() {
  List<String> valueDropped = new ArrayList<>();
  List<Throwable> errorDropped = new ArrayList<>();
  Flux<String> test = Flux.just("foo", "", "bar", "baz")
              .filter(s -> 3 / s.length() == 1)
              .onErrorContinue((t, v) -> {
                errorDropped.add(t);
                valueDropped.add((String) v);
              });
  StepVerifier.create(test)
        .expectNext("foo", "bar", "baz")
        .expectComplete()
        .verifyThenAssertThat()
        .hasNotDroppedElements()
        .hasNotDroppedErrors();
  assertThat(valueDropped).containsExactly("");
  assertThat(errorDropped)
      .hasSize(1)
      .allSatisfy(e -> assertThat(e).hasMessage("/ by zero"));
}

代码示例来源:origin: reactor/reactor-core

@Test
  public void nextError() {
    List<Tuple2<Signal, Context>> signalsAndContext = new ArrayList<>();
    Mono.just(0)
      .map(i -> 10 / i)
      .doOnEach(s -> signalsAndContext.add(Tuples.of(s,s.getContext())))
      .subscriberContext(Context.of("foo", "bar"))
      .subscribe();

    assertThat(signalsAndContext)
        .hasSize(1)
        .allSatisfy(t2 -> {
          assertThat(t2.getT1())
              .isNotNull();
          assertThat(t2.getT2().getOrDefault("foo", "baz"))
              .isEqualTo("bar");
        });

    assertThat(signalsAndContext.stream().map(t2 -> t2.getT1().getType()))
        .containsExactly(SignalType.ON_ERROR);
  }
}

代码示例来源:origin: reactor/reactor-core

@Test
public void fluxApiErrorContinueConditionalByClass() {
  List<String> valueDropped = new ArrayList<>();
  List<Throwable> errorDropped = new ArrayList<>();
  Flux<String> test = Flux.just("foo", "", "bar", "baz")
      .filter(s -> 3 / s.length() == 1)
      .onErrorContinue(ArithmeticException.class,
                  (t, v) -> {
                    errorDropped.add(t);
                    valueDropped.add((String) v);
                  });
  StepVerifier.create(test)
      .expectNext("foo", "bar", "baz")
      .expectComplete()
      .verifyThenAssertThat()
      .hasNotDroppedElements()
      .hasNotDroppedErrors();
  assertThat(valueDropped).containsExactly("");
  assertThat(errorDropped)
      .hasSize(1)
      .allSatisfy(e -> assertThat(e).hasMessage("/ by zero"));
}

代码示例来源:origin: reactor/reactor-core

@Test
public void nextComplete() {
  List<Tuple2<Signal, Context>> signalsAndContext = new ArrayList<>();
  Mono.just(1)
    .hide()
    .doOnEach(s -> signalsAndContext.add(Tuples.of(s, s.getContext())))
    .subscriberContext(Context.of("foo", "bar"))
    .subscribe();
  assertThat(signalsAndContext)
      .hasSize(2)
      .allSatisfy(t2 -> {
        assertThat(t2.getT1())
            .isNotNull();
        assertThat(t2.getT2().getOrDefault("foo", "baz"))
            .isEqualTo("bar");
      });
  assertThat(signalsAndContext.stream().map(t2 -> t2.getT1().getType()))
      .containsExactly(SignalType.ON_NEXT, SignalType.ON_COMPLETE);
}

代码示例来源:origin: reactor/reactor-core

@Test
public void fluxApiErrorContinueConditional() {
  List<String> valueDropped = new ArrayList<>();
  List<Throwable> errorDropped = new ArrayList<>();
  Flux<String> test = Flux.just("foo", "", "bar", "baz")
              .filter(s -> 3 / s.length() == 1)
              .onErrorContinue(
                  t -> t instanceof ArithmeticException,
                  (t, v) -> {
                    errorDropped.add(t);
                    valueDropped.add((String) v);
                  });
  StepVerifier.create(test)
        .expectNext("foo", "bar", "baz")
        .expectComplete()
        .verifyThenAssertThat()
        .hasNotDroppedElements()
        .hasNotDroppedErrors();
  assertThat(valueDropped).containsExactly("");
  assertThat(errorDropped)
      .hasSize(1)
      .allSatisfy(e -> assertThat(e).hasMessage("/ by zero"));
}

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

void assertAllRunningTasksMatch(final String environmentName, final String taskDefinition)
   throws InterruptedException {
  waitOrTimeout(
    RECONCILIATION_INTERVAL * 3 / 2,
    () ->
      assertThat(stack.describeTasks())
        .as("Tasks launched by blox")
        .allSatisfy(
          t ->
            assertThat(t)
              .hasFieldOrPropertyWithValue("group", environmentName)
              .hasFieldOrPropertyWithValue("taskDefinitionArn", taskDefinition)));
 }
}

代码示例来源:origin: reactor/reactor-core

assertThat(errorsDropped)
    .hasSize(1)
    .allSatisfy(e -> assertThat(e)
        .isInstanceOf(ArithmeticException.class)
        .hasMessage("/ by zero"));

代码示例来源:origin: reactor/reactor-core

.as("wip-requested padding")
.hasSize(15)
.allSatisfy(fl -> assertThat(fl.name()).startsWith("p").endsWith("a"));
.as("requested post-padding")
.hasSize(15)
.allSatisfy(fl -> assertThat(fl.name()).startsWith("q").isNotEqualTo("queue"));

代码示例来源:origin: reactor/reactor-core

@Test
public void nextCompleteAndErrorHaveContext() {
  Context context = Context.of("foo", "bar");
  List<Signal> signals = new ArrayList<>();
  StepVerifier.create(Flux.just("hello")
              .doOnEach(signals::add),
      StepVerifierOptions.create().withInitialContext(context))
        .expectNext("hello")
        .verifyComplete();
  assertThat(signals)
       .allSatisfy(signal -> assertThat(signal.getContext().hasKey("foo"))
           .as("has Context value")
           .isTrue());
}

代码示例来源:origin: io.zipkin.brave/brave-http-tests

@Test
public void usesExistingTraceId_b3() throws Exception {
 String path = "/foo";
 final String traceId = "463ac35c9f6413ad";
 final String parentId = traceId;
 final String spanId = "48485a3953bb6124";
 Request request = new Request.Builder().url(url(path))
   .header("b3", traceId + "-" + spanId + "-1-" + parentId)
   .build();
 try (Response response = client.newCall(request).execute()) {
  assertThat(response.isSuccessful()).isTrue();
 }
 assertThat(collectedSpans()).allSatisfy(s -> {
  assertThat(s.traceId()).isEqualTo(traceId);
  assertThat(s.parentId()).isEqualTo(parentId);
  assertThat(s.id()).isEqualTo(spanId);
 });
}

代码示例来源:origin: opencypher/cypher-for-gremlin

@Test
public void percentileContInvalidArgument() throws Exception {
  submitAndGet("CREATE ({prop: 10.0})");
  List<Throwable> throwables = Stream.of(1000, -1, 1.1)
    .map(param -> catchThrowable(() -> submitAndGet(
      "MATCH (n) RETURN percentileCont(n.prop, $param)",
      Collections.singletonMap("param", param)
    )))
    .collect(toList());
  assertThat(throwables)
    .allSatisfy(throwable ->
      assertThat(throwable)
        .hasMessageContaining("Number out of range"));
}

代码示例来源:origin: opencypher/cypher-for-gremlin

@Test
@Category(SkipExtensions.CustomFunctions.class)
public void listInvalidIndex() throws Exception {
  List<Throwable> throwables = Stream.of(
    new HashMap<>(ImmutableMap.of("expr", emptyMap(), "idx", 1)),
    new HashMap<>(ImmutableMap.of("expr", emptyList(), "idx", "foo")),
    new HashMap<>(ImmutableMap.of("expr", 100, "idx", 0))
  )
    .map(params -> catchThrowable(() -> submitAndGet(
      "WITH $expr AS expr, $idx AS idx " +
        "RETURN expr[idx]",
      params
    )))
    .collect(toList());
  assertThat(throwables)
    .allSatisfy(throwable ->
      assertThat(throwable)
        .hasMessageContaining("element access"));
}

代码示例来源:origin: opencypher/cypher-for-gremlin

@Test
  public void percentileDiscInvalidArgument() throws Exception {
    submitAndGet("CREATE ({prop: 10.0})");
    List<Throwable> throwables = Stream.of(1000, -1, 1.1)
      .map(param -> catchThrowable(() -> submitAndGet(
        "MATCH (n) RETURN percentileDisc(n.prop, $param)",
        Collections.singletonMap("param", param)
      )))
      .collect(toList());

    assertThat(throwables)
      .allSatisfy(throwable ->
        assertThat(throwable)
          .hasMessageContaining("Number out of range"));
  }
}

代码示例来源:origin: lukas-krecan/JsonUnit

@Test
void objectShouldMatch() {
  assertThatJson("{\"test\":[{\"value\":1},{\"value\":2},{\"value\":3}]}").node("test").isArray().allSatisfy(v -> assertThatJson(v).node("value").isNumber().isLessThan(valueOf(4)));
}

代码示例来源:origin: opencypher/cypher-for-gremlin

@Test
@Category(SkipExtensions.CustomFunctions.class)
public void castInvalidToString() throws Exception {
  List<Throwable> throwables = Stream.of(
    "[]",
    "{a: 1}"
  )
    .map(literal -> catchThrowable(() -> submitAndGet(
      "WITH [1, " + literal + "] AS list\n" +
        "RETURN toString(list[1]) AS n"
    )))
    .collect(toList());
  assertThat(throwables)
    .allSatisfy(throwable ->
      assertThat(throwable)
        .hasMessageContaining("Cannot convert"));
}

代码示例来源:origin: opencypher/cypher-for-gremlin

@Test
@Category(SkipExtensions.CustomFunctions.class)
public void castInvalidToFloat() throws Exception {
  List<Throwable> throwables = Stream.of(
    "true",
    "false",
    "[]",
    "{a: 1}"
  )
    .map(literal -> catchThrowable(() -> submitAndGet(
      "WITH [1.0, " + literal + "] AS list\n" +
        "RETURN toFloat(list[1]) AS n"
    )))
    .collect(toList());
  assertThat(throwables)
    .allSatisfy(throwable ->
      assertThat(throwable)
        .hasMessageContaining("Cannot convert"));
}

代码示例来源:origin: opencypher/cypher-for-gremlin

@Test
@Category(SkipExtensions.CustomFunctions.class)
public void castInvalidToInteger() throws Exception {
  List<Throwable> throwables = Stream.of(
    "true",
    "false",
    "[]",
    "{a: 1}"
  )
    .map(literal -> catchThrowable(() -> submitAndGet(
      "WITH [1, " + literal + "] AS list\n" +
        "RETURN toInteger(list[1]) AS n"
    )))
    .collect(toList());
  assertThat(throwables)
    .allSatisfy(throwable ->
      assertThat(throwable)
        .hasMessageContaining("Cannot convert"));
}

代码示例来源:origin: com.powsybl/powsybl-security-analysis-api

@Test
//test current limit violation
public void checkCurrentLimits() {
  Line line = network.getLine("NHV1_NHV2_1");
  List<LimitViolation> violations = new ArrayList<>();
  LimitViolationDetector detector = new DefaultLimitViolationDetector(Collections.singleton(Security.CurrentLimitType.PATL));
  detector.checkCurrent(line, Branch.Side.TWO, 1101, violations::add);
  Assertions.assertThat(violations)
      .hasSize(1)
      .allSatisfy(l -> assertEquals(1100, l.getLimit(), 0d));
  violations = new ArrayList<>();
  detector = new DefaultLimitViolationDetector(Collections.singleton(Security.CurrentLimitType.TATL));
  detector.checkCurrent(line, Branch.Side.TWO, 1201, violations::add);
  Assertions.assertThat(violations)
      .hasSize(1)
      .allSatisfy(l -> assertEquals(1200, l.getLimit(), 0d));
}

代码示例来源:origin: jlink/jqwik

@Property(tries = 20)
@Domain(DomainContext.Global.class)
@Domain(SmallNumbersContext.class)
void globalContextCanBeMixedIn(
  @ForAll @StringLength(5) @LowerChars String aString,
  @ForAll int smallNumber
) {
  assertThat(aString).hasSize(5);
  assertThat(aString.chars()).allSatisfy(Character::isLowerCase);
  assertThat(smallNumber).isBetween(1, 99);
}

相关文章

微信公众号

最新文章

更多

ListAssert类方法