org.assertj.core.api.SoftAssertions Java Examples

The following examples show how to use org.assertj.core.api.SoftAssertions. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: JvmOptionConverterTest.java    From quickperf with Apache License 2.0 7 votes vote down vote up
@Test public void
should_return_jvm_option_objects_from_jvm_options_as_a_string() {

    // GIVEN
    JvmOptions jvmOptionsAsAnnotation = mock(JvmOptions.class);
    when(jvmOptionsAsAnnotation.value()).thenReturn(" -XX:+UseCompressedOops   -XX:+UseCompressedClassPointers  ");

    // WHEN
    List<JvmOption> jvmOptions = jvmOptionConverter.jvmOptionFrom(jvmOptionsAsAnnotation);

    // THEN
    SoftAssertions softAssertions = new SoftAssertions();
    softAssertions.assertThat(jvmOptions).hasSize(2);

    JvmOption firstJvmOption = jvmOptions.get(0);
    softAssertions.assertThat(firstJvmOption.asString())
                  .isEqualTo("-XX:+UseCompressedOops");

    JvmOption secondJvmOption = jvmOptions.get(1);
    softAssertions.assertThat(secondJvmOption.asString())
                  .isEqualTo("-XX:+UseCompressedClassPointers");

    softAssertions.assertAll();

}
 
Example #2
Source File: RatingTest.java    From robozonky with Apache License 2.0 6 votes vote down vote up
@Test
void allRatingsNowAvailable() {
    SoftAssertions.assertSoftly(softly -> {
        for (final Rating r : Rating.values()) {
            softly.assertThat(r.getMaximalRevenueRate())
                .as("Max revenue rate for " + r)
                .isGreaterThan(Ratio.ZERO);
            softly.assertThat(r.getMinimalRevenueRate())
                .as("Min revenue rate for " + r)
                .isGreaterThan(Ratio.ZERO);
            softly.assertThat(r.getFee())
                .as("Fee for " + r)
                .isGreaterThan(Ratio.ZERO);
            softly.assertThat(r.getInterestRate())
                .as("Interest rate for " + r)
                .isGreaterThan(Ratio.ZERO);
        }
    });
}
 
Example #3
Source File: AssertJ_02_FluentAssertionsAndMoreFeatures.java    From JUnit-5-Quick-Start-Guide-and-Framework-Support with MIT License 6 votes vote down vote up
/**
 * SoftAssertions are used to group assertions with different assertion bases and force all of them to run even if a previous assertion failed.
 */
@Test
void softAssertion() {
    SoftAssertions.assertSoftly(soft -> {
        // Base dummyFruits
        soft.assertThat(dummyFruits)
                .hasSize(3)
                .containsExactly(babyBanana, grannySmithApple, grapefruit);
        // Base otherDummyFruitList
        soft.assertThat(otherDummyFruitList)
                .hasSize(4)
                .containsAll(dummyFruits)
                .containsExactly(babyBanana, grannySmithApple, grapefruit, redBanana);
        // Base
        soft.assertThat(grapefruit).extracting(DummyFruit::getType).allMatch(DummyFruit.TYPE.ORANGE::equals);
    });
}
 
Example #4
Source File: BasicHeaderBlockTest.java    From banking-swift-messages-java with MIT License 6 votes vote down vote up
@Test
public void of_WHEN_valid_block_is_passed_RETURN_new_block() throws Exception {

    // Given
    GeneralBlock generalBlock = new GeneralBlock(BasicHeaderBlock.BLOCK_ID_1, "F01YOURCODEZABC2222777777");

    // When
    BasicHeaderBlock block = BasicHeaderBlock.of(generalBlock);

    // Then
    assertThat(block).isNotNull();
    SoftAssertions softly = new SoftAssertions();
    softly.assertThat(block.getApplicationId()).isEqualTo("F");
    softly.assertThat(block.getServiceId()).isEqualTo("01");
    softly.assertThat(block.getLogicalTerminalAddress()).isEqualTo("YOURCODEZABC");
    softly.assertThat(block.getSessionNumber()).isEqualTo("2222");
    softly.assertThat(block.getSequenceNumber()).isEqualTo("777777");
    softly.assertAll();
}
 
Example #5
Source File: QuotaMonitorTest.java    From robozonky with Apache License 2.0 6 votes vote down vote up
@Test
void reaches90() {
    add(2700);
    SoftAssertions.assertSoftly(softly -> {
        softly.assertThat(monitor.threshold50PercentReached())
            .isTrue();
        softly.assertThat(monitor.threshold75PercentReached())
            .isTrue();
        softly.assertThat(monitor.threshold90PercentReached())
            .isTrue();
        softly.assertThat(monitor.threshold99PercentReached())
            .isFalse();
    });
    add(-1);
    SoftAssertions.assertSoftly(softly -> {
        softly.assertThat(monitor.threshold50PercentReached())
            .isTrue();
        softly.assertThat(monitor.threshold75PercentReached())
            .isTrue();
        softly.assertThat(monitor.threshold90PercentReached())
            .isFalse();
        softly.assertThat(monitor.threshold99PercentReached())
            .isFalse();
    });
}
 
Example #6
Source File: QuotaMonitorTest.java    From robozonky with Apache License 2.0 6 votes vote down vote up
@Test
void reaches99() {
    add(2970);
    SoftAssertions.assertSoftly(softly -> {
        softly.assertThat(monitor.threshold50PercentReached())
            .isTrue();
        softly.assertThat(monitor.threshold75PercentReached())
            .isTrue();
        softly.assertThat(monitor.threshold90PercentReached())
            .isTrue();
        softly.assertThat(monitor.threshold99PercentReached())
            .isTrue();
    });
    add(-1);
    SoftAssertions.assertSoftly(softly -> {
        softly.assertThat(monitor.threshold50PercentReached())
            .isTrue();
        softly.assertThat(monitor.threshold75PercentReached())
            .isTrue();
        softly.assertThat(monitor.threshold90PercentReached())
            .isTrue();
        softly.assertThat(monitor.threshold99PercentReached())
            .isFalse();
    });
}
 
Example #7
Source File: LappsGridRecommenderConformityTest.java    From inception with Apache License 2.0 6 votes vote down vote up
@Test
@Parameters(method = "getPosServices")
public void testPosConformity(LappsGridService aService) throws Exception
{
    CAS cas = loadData();
    
    predict(aService.getUrl(), cas);

    SoftAssertions softly = new SoftAssertions();
    softly.assertThat(JCasUtil.select(cas.getJCas(), Token.class))
            .as("Prediction should contain Tokens")
            .isNotEmpty();
    softly.assertThat(JCasUtil.select(cas.getJCas(), POS.class))
            .as("Prediction should contain POS tags")
            .isNotEmpty();

    softly.assertAll();
}
 
Example #8
Source File: UserHeaderBlockTest.java    From banking-swift-messages-java with MIT License 6 votes vote down vote up
@Test
public void of_WHEN_valid_block_is_passed_RETURN_new_block() throws Exception {

    // Given
    GeneralBlock generalBlock = new GeneralBlock(UserHeaderBlock.BLOCK_ID_3, "{113:SEPA}{108:ILOVESEPA}");

    // When
    UserHeaderBlock block = UserHeaderBlock.of(generalBlock);

    // Then
    assertThat(block).isNotNull();
    SoftAssertions softly = new SoftAssertions();
    softly.assertThat(block.getBankingPriorityCode()).contains("SEPA");
    softly.assertThat(block.getMessageUserReference()).contains("ILOVESEPA");
    softly.assertAll();
}
 
Example #9
Source File: DefaultInvestmentShareTest.java    From robozonky with Apache License 2.0 6 votes vote down vote up
@Test
void shareBoundaries() {
    assertThatThrownBy(() -> new DefaultInvestmentShare(-1))
        .isInstanceOf(IllegalArgumentException.class);
    assertThatThrownBy(() -> new DefaultInvestmentShare(101))
        .isInstanceOf(IllegalArgumentException.class);
    final DefaultInvestmentShare s = new DefaultInvestmentShare(0);
    SoftAssertions.assertSoftly(softly -> {
        softly.assertThat(s.getMinimumShareInPercent())
            .isEqualTo(0);
        softly.assertThat(s.getMaximumShareInPercent())
            .isEqualTo(0);
    });
    final DefaultInvestmentShare s2 = new DefaultInvestmentShare(100);
    SoftAssertions.assertSoftly(softly -> {
        softly.assertThat(s2.getMinimumShareInPercent())
            .isEqualTo(0);
        softly.assertThat(s2.getMaximumShareInPercent())
            .isEqualTo(100);
    });
}
 
Example #10
Source File: MockConnectionTest.java    From rabbitmq-mock with Apache License 2.0 6 votes vote down vote up
@Test
void connectionParams_are_default_ones() {
    Connection connection = new MockConnectionFactory().newConnection();

    SoftAssertions softly = new SoftAssertions();
    softly.assertThat(connection.getAddress().getHostAddress()).isEqualTo("127.0.0.1");
    softly.assertThat(connection.getPort()).isEqualTo(ConnectionFactory.DEFAULT_AMQP_PORT);
    softly.assertThat(connection.getChannelMax()).isEqualTo(0);
    softly.assertThat(connection.getFrameMax()).isEqualTo(0);
    softly.assertThat(connection.getHeartbeat()).isEqualTo(0);
    softly.assertThat(connection.getClientProperties()).isEqualTo(AMQConnection.defaultClientProperties());
    softly.assertThat(connection.getClientProvidedName()).isNull();
    softly.assertThat(connection.getServerProperties().get("version"))
        .isEqualTo(LongStringHelper.asLongString(new Version(AMQP.PROTOCOL.MAJOR, AMQP.PROTOCOL.MINOR).toString()));
    softly.assertThat(connection.getExceptionHandler()).isExactlyInstanceOf(DefaultExceptionHandler.class);
    softly.assertAll();
}
 
Example #11
Source File: AbstractJUnit4SpringTestBase.java    From quickperf with Apache License 2.0 6 votes vote down vote up
@Test public void
two_tests_having_performance_and_functional_issues() {

    // GIVEN
    Class<?> testClass = aClassWithTwoMethodsHavingFunctionnalAndPerfIssues();

    // WHEN
    PrintableResult printableResult = testResult(testClass);

    // THEN
    SoftAssertions softAssertions = new SoftAssertions();
    softAssertions.assertThat(printableResult.failureCount()).isEqualTo(2);

    softAssertions.assertThat(printableResult.toString())
                  .contains("java.lang.AssertionError: Performance and functional properties not respected")
                  .contains("Failing assertion of first test!")
                  .contains("Failing assertion of second test!");

    softAssertions.assertAll();

}
 
Example #12
Source File: GradleProjectTest.java    From jig with Apache License 2.0 6 votes vote down vote up
@ParameterizedTest
@MethodSource("fixtures")
public void 依存関係にあるすべてのJavaPluginが適用されたプロジェクトのクラスパスとソースパスが取得できること(
        String name,
        String[] classPathSuffixes,
        String[] sourcePathSuffixes) throws Exception {

    Method projectMethod = GradleProjectTest.class.getDeclaredMethod("_" + name, Path.class);
    projectMethod.setAccessible(true);
    Project project = (Project) projectMethod.invoke(null, tempDir);

    SourcePaths sourcePaths = new GradleProject(project).rawSourceLocations();

    List<Path> binarySourcePaths = sourcePaths.binarySourcePaths();
    List<Path> textSourcePaths = sourcePaths.textSourcePaths();

    Fixture fixture = new Fixture(classPathSuffixes, sourcePathSuffixes);
    SoftAssertions softly = new SoftAssertions();
    softly.assertThat(fixture.classPathContains(new HashSet<>(binarySourcePaths))).isTrue();
    softly.assertThat(fixture.sourcePathContains(new HashSet<>(textSourcePaths))).isTrue();
    softly.assertAll();
}
 
Example #13
Source File: QuotaMonitorTest.java    From robozonky with Apache License 2.0 6 votes vote down vote up
@Test
void reaches75() {
    add(2250);
    SoftAssertions.assertSoftly(softly -> {
        softly.assertThat(monitor.threshold50PercentReached())
            .isTrue();
        softly.assertThat(monitor.threshold75PercentReached())
            .isTrue();
        softly.assertThat(monitor.threshold90PercentReached())
            .isFalse();
        softly.assertThat(monitor.threshold99PercentReached())
            .isFalse();
    });
    add(-1);
    SoftAssertions.assertSoftly(softly -> {
        softly.assertThat(monitor.threshold50PercentReached())
            .isTrue();
        softly.assertThat(monitor.threshold75PercentReached())
            .isFalse();
        softly.assertThat(monitor.threshold90PercentReached())
            .isFalse();
        softly.assertThat(monitor.threshold99PercentReached())
            .isFalse();
    });
}
 
Example #14
Source File: UnifiedXmlDataShapeGeneratorRequestShapeTest.java    From syndesis with Apache License 2.0 6 votes vote down vote up
@Test
public void shouldGenerateAtlasmapSchemaSetForUpdatePetRequest() throws IOException {
    final Oas20Operation openApiOperation = OasModelHelper.getOperationMap(openApiDoc.paths.getPathItem(path), Oas20Operation.class).get(operation);

    final DataShape shape = generator.createShapeFromRequest(json, openApiDoc, openApiOperation);

    final SoftAssertions softly = new SoftAssertions();
    softly.assertThat(shape.getKind()).isEqualTo(DataShapeKinds.XML_SCHEMA);
    softly.assertThat(shape.getName()).isEqualTo("Request");
    softly.assertThat(shape.getDescription()).isEqualTo("API request payload");
    softly.assertThat(shape.getExemplar()).isNotPresent();
    softly.assertAll();

    final String expectedSpecification;
    try (InputStream in = UnifiedXmlDataShapeGenerator.class.getResourceAsStream("/openapi/v2/" + schemaset)) {
        expectedSpecification = IOUtils.toString(in, StandardCharsets.UTF_8);
    }

    final String specification = shape.getSpecification();

    assertThat(specification).isXmlEqualTo(expectedSpecification);
}
 
Example #15
Source File: MetricsTest.java    From prebid-server-java with Apache License 2.0 6 votes vote down vote up
private void verifyCreatesConfiguredCounterType(Consumer<Metrics> metricsConsumer) {
    final EnumMap<CounterType, Class<? extends Metric>> counterTypeClasses = new EnumMap<>(CounterType.class);
    counterTypeClasses.put(CounterType.counter, Counter.class);
    counterTypeClasses.put(CounterType.flushingCounter, ResettingCounter.class);
    counterTypeClasses.put(CounterType.meter, Meter.class);

    final SoftAssertions softly = new SoftAssertions();

    for (CounterType counterType : CounterType.values()) {
        // given
        metricRegistry = new MetricRegistry();

        // when
        metricsConsumer.accept(new Metrics(metricRegistry, CounterType.valueOf(counterType.name()),
                accountMetricsVerbosity, bidderCatalog));

        // then
        softly.assertThat(metricRegistry.getMetrics()).hasValueSatisfying(new Condition<>(
                metric -> metric.getClass() == counterTypeClasses.get(counterType),
                null));
    }

    softly.assertAll();
}
 
Example #16
Source File: ApplicationHeaderBlockTest.java    From banking-swift-messages-java with MIT License 6 votes vote down vote up
@Test
public void of_WHEN_valid_input_block_is_passed_RETURN_new_block() throws Exception {

    // Given
    GeneralBlock generalBlock = new GeneralBlock(ApplicationHeaderBlock.BLOCK_ID_2, "I101YOURBANKXJKLU3003");

    // When
    ApplicationHeaderBlock block = ApplicationHeaderBlock.of(generalBlock);

    // Then
    assertThat(block).isNotNull();
    assertThat(block.getInput()).isPresent();
    if (block.getInput().isPresent()) {
        SoftAssertions softly = new SoftAssertions();
        ApplicationHeaderInputBlock inputBlock = block.getInput().get();
        softly.assertThat(inputBlock.getMessageType()).isEqualTo("101");
        softly.assertThat(inputBlock.getReceiverAddress()).isEqualTo("YOURBANKXJKL");
        softly.assertThat(inputBlock.getMessagePriority()).isEqualTo(MessagePriority.URGENT);
        softly.assertThat(inputBlock.getDeliveryMonitoring()).contains("3");
        softly.assertThat(inputBlock.getObsolescencePeriod()).contains("003");
        softly.assertAll();
    }

    assertThat(block.getOutput()).isNotPresent();
}
 
Example #17
Source File: RatingTest.java    From robozonky with Apache License 2.0 6 votes vote down vote up
@Test
void someRatingsUnavailableBefore2019() {
    final Instant ratingsChange = Rating.MIDNIGHT_2019_03_18.minusSeconds(1);
    SoftAssertions.assertSoftly(softly -> {
        for (final Rating r : new Rating[] { Rating.AAE, Rating.AE }) {
            softly.assertThat(r.getMaximalRevenueRate(ratingsChange))
                .as("Max revenue rate for " + r)
                .isEqualTo(Ratio.ZERO);
            softly.assertThat(r.getMinimalRevenueRate(ratingsChange))
                .as("Min revenue rate for " + r)
                .isEqualTo(Ratio.ZERO);
            softly.assertThat(r.getFee(ratingsChange))
                .as("Fee for " + r)
                .isEqualTo(Ratio.ZERO);
        }
    });
}
 
Example #18
Source File: SystemTrailerBlockTest.java    From banking-swift-messages-java with MIT License 6 votes vote down vote up
@Test
public void of_WHEN_valid_block_is_passed_RETURN_new_block() throws Exception {

    // Given
    GeneralBlock generalBlock = new GeneralBlock(SystemTrailerBlock.BLOCK_ID_S, "{CHK:F7C4F89AF66D}{TNG:}{SAC:}{COP:P}");

    // When
    SystemTrailerBlock block = SystemTrailerBlock.of(generalBlock);

    // Then
    assertThat(block).isNotNull();
    SoftAssertions softly = new SoftAssertions();
    softly.assertThat(block.getChecksum()).contains("F7C4F89AF66D");
    softly.assertThat(block.getTraining()).contains("");
    softly.assertThat(block.getAdditionalSubblocks("COP").getContent()).isEqualTo("P");
    softly.assertAll();
}
 
Example #19
Source File: Tuple3Test.java    From robozonky with Apache License 2.0 6 votes vote down vote up
@Test
void equals() {
    Tuple3 tuple = Tuple.of(1, 1, 1);
    SoftAssertions.assertSoftly(softly -> {
        softly.assertThat(tuple)
            .isEqualTo(tuple);
        softly.assertThat(tuple)
            .isNotEqualTo(null);
        softly.assertThat(tuple)
            .isNotEqualTo("");
    });
    Tuple3 tuple2 = Tuple.of(1, 1, 1);
    SoftAssertions.assertSoftly(softly -> {
        softly.assertThat(tuple)
            .isNotSameAs(tuple2);
        softly.assertThat(tuple)
            .isEqualTo(tuple2);
    });
    Tuple3 tuple3 = Tuple.of(1, 2, 3);
    SoftAssertions.assertSoftly(softly -> {
        softly.assertThat(tuple3)
            .isNotEqualTo(tuple);
        softly.assertThat(tuple)
            .isNotEqualTo(tuple3);
    });
}
 
Example #20
Source File: Tuple2Test.java    From robozonky with Apache License 2.0 6 votes vote down vote up
@Test
void equals() {
    Tuple2 tuple = Tuple.of(1, 1);
    SoftAssertions.assertSoftly(softly -> {
        softly.assertThat(tuple)
            .isEqualTo(tuple);
        softly.assertThat(tuple)
            .isNotEqualTo(null);
        softly.assertThat(tuple)
            .isNotEqualTo("");
    });
    Tuple2 tuple2 = Tuple.of(1, 1);
    SoftAssertions.assertSoftly(softly -> {
        softly.assertThat(tuple)
            .isNotSameAs(tuple2);
        softly.assertThat(tuple)
            .isEqualTo(tuple2);
    });
    Tuple2 tuple3 = Tuple.of(1, 2);
    SoftAssertions.assertSoftly(softly -> {
        softly.assertThat(tuple3)
            .isNotEqualTo(tuple);
        softly.assertThat(tuple)
            .isNotEqualTo(tuple3);
    });
}
 
Example #21
Source File: UnifiedXmlDataShapeGeneratorRequestShapeTest.java    From syndesis with Apache License 2.0 6 votes vote down vote up
@Test
public void shouldGenerateAtlasmapSchemaSetForUpdatePetRequest() throws IOException {
    final Oas30Operation openApiOperation = OasModelHelper.getOperationMap(openApiDoc.paths.getPathItem(path), Oas30Operation.class).get(operation);

    final DataShape shape = generator.createShapeFromRequest(json, openApiDoc, openApiOperation);

    final SoftAssertions softly = new SoftAssertions();
    softly.assertThat(shape.getKind()).isEqualTo(DataShapeKinds.XML_SCHEMA);
    softly.assertThat(shape.getName()).isEqualTo("Request");
    softly.assertThat(shape.getDescription()).isEqualTo("API request payload");
    softly.assertThat(shape.getExemplar()).isNotPresent();
    softly.assertAll();

    final String expectedSpecification;
    try (InputStream in = UnifiedXmlDataShapeGenerator.class.getResourceAsStream("/openapi/v3/" + schemaset)) {
        expectedSpecification = IOUtils.toString(in, StandardCharsets.UTF_8);
    }

    final String specification = shape.getSpecification();

    assertThat(specification).isXmlEqualTo(expectedSpecification);
}
 
Example #22
Source File: Tuple1Test.java    From robozonky with Apache License 2.0 6 votes vote down vote up
@Test
void equals() {
    Tuple1 tuple = Tuple.of(1);
    SoftAssertions.assertSoftly(softly -> {
        softly.assertThat(tuple)
            .isEqualTo(tuple);
        softly.assertThat(tuple)
            .isNotEqualTo(null);
        softly.assertThat(tuple)
            .isNotEqualTo("");
    });
    Tuple1 tuple2 = Tuple.of(1);
    SoftAssertions.assertSoftly(softly -> {
        softly.assertThat(tuple)
            .isNotSameAs(tuple2);
        softly.assertThat(tuple)
            .isEqualTo(tuple2);
    });
    Tuple1 tuple3 = Tuple.of(2);
    SoftAssertions.assertSoftly(softly -> {
        softly.assertThat(tuple3)
            .isNotEqualTo(tuple);
        softly.assertThat(tuple)
            .isNotEqualTo(tuple3);
    });
}
 
Example #23
Source File: UserTrailerBlockTest.java    From banking-swift-messages-java with MIT License 6 votes vote down vote up
@Test
public void of_WHEN_valid_block_is_passed_RETURN_new_block() throws Exception {

    // Given
    GeneralBlock generalBlock = new GeneralBlock(UserTrailerBlock.BLOCK_ID_5, "{CHK:F7C4F89AF66D}{TNG:}");

    // When
    UserTrailerBlock block = UserTrailerBlock.of(generalBlock);

    // Then
    assertThat(block).isNotNull();
    SoftAssertions softly = new SoftAssertions();
    softly.assertThat(block.getChecksum()).contains("F7C4F89AF66D");
    softly.assertThat(block.getTraining()).contains("");
    softly.assertAll();
}
 
Example #24
Source File: QuotaMonitorTest.java    From robozonky with Apache License 2.0 6 votes vote down vote up
@Test
void reaches50() {
    add(1500);
    SoftAssertions.assertSoftly(softly -> {
        softly.assertThat(monitor.threshold50PercentReached())
            .isTrue();
        softly.assertThat(monitor.threshold75PercentReached())
            .isFalse();
        softly.assertThat(monitor.threshold90PercentReached())
            .isFalse();
        softly.assertThat(monitor.threshold99PercentReached())
            .isFalse();
    });
    add(-1);
    SoftAssertions.assertSoftly(softly -> {
        softly.assertThat(monitor.threshold50PercentReached())
            .isFalse();
        softly.assertThat(monitor.threshold75PercentReached())
            .isFalse();
        softly.assertThat(monitor.threshold90PercentReached())
            .isFalse();
        softly.assertThat(monitor.threshold99PercentReached())
            .isFalse();
    });
}
 
Example #25
Source File: PermissionCheckTest.java    From jump-the-queue with Apache License 2.0 5 votes vote down vote up
/**
 * Check if all relevant methods in use case implementations have permission checks i.e. {@link RolesAllowed},
 * {@link DenyAll} or {@link PermitAll} annotation is applied. This is only checked for methods that are declared in
 * the corresponding interface and thus have the {@link Override} annotations applied.
 */
@Test
@Ignore // Currently Access control has not been implemented in jumpthequeue so the test is ignored
public void permissionCheckAnnotationPresent() {

  String packageName = "com.devonfw.application.jtqj";
  Filter<String> filter = new Filter<String>() {

    @Override
    public boolean accept(String value) {

      return value.contains(".logic.impl.usecase.Uc") && value.endsWith("Impl");
    }

  };
  ReflectionUtil ru = ReflectionUtilImpl.getInstance();
  Set<String> classNames = ru.findClassNames(packageName, true, filter);
  Set<Class<?>> classes = ru.loadClasses(classNames);
  SoftAssertions assertions = new SoftAssertions();
  for (Class<?> clazz : classes) {
    Method[] methods = clazz.getDeclaredMethods();
    for (Method method : methods) {
      Method parentMethod = ru.getParentMethod(method);
      if (parentMethod != null) {
        Class<?> declaringClass = parentMethod.getDeclaringClass();
        if (declaringClass.isInterface() && declaringClass.getSimpleName().startsWith("Uc")) {
          boolean hasAnnotation = false;
          if (method.getAnnotation(RolesAllowed.class) != null || method.getAnnotation(DenyAll.class) != null
              || method.getAnnotation(PermitAll.class) != null) {
            hasAnnotation = true;
          }
          assertions.assertThat(hasAnnotation)
              .as("Method " + method.getName() + " in Class " + clazz.getSimpleName() + " is missing access control")
              .isTrue();
        }
      }
    }
  }
  assertions.assertAll();
}
 
Example #26
Source File: StopStreamingTest.java    From ditto with Eclipse Public License 2.0 5 votes vote down vote up
@Test
public void gettersReturnExpected() {
    final StreamingType streamingType = StreamingType.EVENTS;
    final String connectionCorrelationId = "my-correlation-id";

    final StopStreaming underTest = new StopStreaming(streamingType, connectionCorrelationId);

    final SoftAssertions softly = new SoftAssertions();
    softly.assertThat(underTest.getStreamingType()).isEqualTo(streamingType);
    softly.assertThat(underTest.getConnectionCorrelationId()).isEqualTo(connectionCorrelationId);
    softly.assertAll();
}
 
Example #27
Source File: LogTypeTest.java    From ditto with Eclipse Public License 2.0 5 votes vote down vote up
private LogTypeAssert supportsCategory(final LogCategory category, final LogCategory... otherCategories) {
    isNotNull();
    final SoftAssertions softAssertions = new SoftAssertions();

    final List<LogCategory> shouldNotContain = new ArrayList<>(Arrays.asList(LogCategory.values()));
    shouldNotContain.remove(category);
    shouldNotContain.removeAll(Arrays.asList(otherCategories));

    final List<LogCategory> shouldContain = new ArrayList<>(Arrays.asList(otherCategories));
    shouldContain.add(category);

    final String shouldContainMessage =
            MessageFormat.format("Expected log type <{0}> to support category <{1}>, but it didn't.", actual,
                    category);
    shouldContain.forEach(c -> {
        softAssertions.assertThat(actual.supportsCategory(c))
                .overridingErrorMessage(shouldContainMessage)
                .isTrue();
    });

    final String shouldNotContainMessage =
            MessageFormat.format("Expected log type <{0}> to not support category <{1}>, but it did.", actual,
                    category);
    shouldNotContain.forEach(c -> {
        softAssertions.assertThat(actual.supportsCategory(c))
                .overridingErrorMessage(shouldContainMessage)
                .isFalse();
    });

    softAssertions.assertAll();
    return myself;
}
 
Example #28
Source File: FindPageObjectTest.java    From bobcat with Apache License 2.0 5 votes vote down vote up
@Test
public void shouldFindWebElementListInPageObject() {
  SoftAssertions softly = new SoftAssertions();
  softly.assertThat(masterPage.getDrinks().getLiWebElementList().size()).isEqualTo(3);
  softly.assertThat(masterPage.getDrinks().getLiWebElementList().get(2).getText())
      .isEqualTo(MILK_TEXT);
  softly.assertAll();
}
 
Example #29
Source File: BuildResultAssert.java    From curiostack with MIT License 5 votes vote down vote up
/** Asserts that the {@code tasks} succeeded during the build. */
public BuildResultAssert tasksDidNotRun(Iterable<String> tasks) {
  SoftAssertions.assertSoftly(
      softly -> {
        for (var task : tasks) {
          BuildTask result = actual.task(task);
          softly.assertThat(result).as("Task %s did not run", task).isNull();
        }
      });
  return this;
}
 
Example #30
Source File: RatingTest.java    From robozonky with Apache License 2.0 5 votes vote down vote up
@Test
void feesBefore2018() {
    final Instant ratingsChange = Rating.MIDNIGHT_2017_09_01.minusSeconds(1);
    SoftAssertions.assertSoftly(softly -> {
        for (final Rating r : new Rating[] { Rating.AAAAA, Rating.AAAA, Rating.AAA, Rating.AA, Rating.A, Rating.B,
                Rating.C, Rating.D }) {
            softly.assertThat(r.getFee(ratingsChange))
                .as("Fee for " + r)
                .isEqualTo(Ratio.fromPercentage(1));
        }
    });
}