Java 类org.junit.jupiter.api.Assumptions 实例源码

项目:iStudent    文件:GreetingServiceTest.java   
@Test
@DisplayName("Updating a greeting should work")
void updateGreeting() {
    // Given we have a greeting already saved
    GreetingDto savedGreeting = service.createGreeting(createGreetingDto("We come in peace!"));
    Assumptions.assumeTrue(savedGreeting != null);
    // When we update it
    savedGreeting.setMessage("Updated message");
    service.updateGreetingWithId(savedGreeting.getId(), savedGreeting);
    // Then it should be updated
    Optional<GreetingDto> updatedGreetingOptional = service.findGreetingById(savedGreeting.getId());
    Assertions.assertAll("Updating a greeting by id should work",
            () -> assertTrue(updatedGreetingOptional.isPresent(), "Could not find greeting by id"),
            () -> assertEquals(savedGreeting.getId(), updatedGreetingOptional.get().getId(), "Updated greeting has invalid id"),
            () -> assertEquals("Updated message", updatedGreetingOptional.get().getMessage(), "Updated greeting has different message from the expected updated one"));

}
项目:validity    文件:StackTraceTest.java   
@Test
void testDefaultValidityFailedValidationExecutorRemovesValidityStackFrames() {
    Exception exception = new NullPointerException();
    Assumptions.assumeTrue(null != exception.getStackTrace() && exception.getStackTrace().length > 0,
                           "This test can only work if the JVM is filling in stack traces.");
    IllegalArgumentException thrown = Assertions.assertThrows(IllegalArgumentException.class,
                                                              () -> FVE.fail("expected", "subject", () -> "message"));
    int firstLineNumber = exception.getStackTrace()[0].getLineNumber();
    Assertions.assertTrue(null != thrown.getStackTrace() && thrown.getStackTrace().length > 0,
                          "If the JVM is filling in stack traces the thrown exception should have a stack trace.");
    Assertions.assertEquals(firstLineNumber + 4,
                            thrown.getStackTrace()[0].getLineNumber(),
                            "Default stack trace should have the caller as the first line number.");
    Assertions.assertEquals(exception.getStackTrace()[0].getClassName(),
                            thrown.getStackTrace()[0].getClassName(),
                            "Default stack trace should have the caller as the first line");
    Assertions.assertTrue(thrown.getStackTrace().length > 1,
                          "Default stack trace should have more than the caller.");
}
项目:qpp-conversion-tool    文件:SubmissionIntegrationTest.java   
@Test
void testSubmissionApiPostSuccess() throws IOException {
    HttpResponse httpResponse = servicePost(qpp);
    Assumptions.assumeTrue(endpointIsUp(httpResponse), "Validation api is down");

    assertThat(getStatus(httpResponse)).isEqualTo(200);
}
项目:qpp-conversion-tool    文件:SubmissionIntegrationTest.java   
@Test
@SuppressWarnings("unchecked")
void testSubmissionApiPostFailure() throws IOException {
    Map<String, Object> obj = (Map<String, Object>) qpp.getObject();
    obj.remove("performanceYear");
    HttpResponse httpResponse = servicePost(qpp);
    Assumptions.assumeTrue(endpointIsUp(httpResponse), "Validation api is down");

    assertWithMessage("QPP submission should be unprocessable")
            .that(getStatus(httpResponse))
            .isEqualTo(422);
}
项目:fuse-nio-adapter    文件:FileAttributesUtilTest.java   
@Test
public void testCopyBasicFileAttributesFromNioToFuse() {
    Instant instant = Instant.ofEpochSecond(424242l, 42);
    FileTime ftime = FileTime.from(instant);
    BasicFileAttributes attr = Mockito.mock(BasicFileAttributes.class);
    Mockito.when(attr.isDirectory()).thenReturn(true);
    Mockito.when(attr.lastModifiedTime()).thenReturn(ftime);
    Mockito.when(attr.creationTime()).thenReturn(ftime);
    Mockito.when(attr.lastAccessTime()).thenReturn(ftime);
    Mockito.when(attr.size()).thenReturn(42l);

    FileAttributesUtil util = new FileAttributesUtil();
    FileStat stat = new FileStat(jnr.ffi.Runtime.getSystemRuntime());
    util.copyBasicFileAttributesFromNioToFuse(attr, stat);

    Assertions.assertTrue((FileStat.S_IFDIR & stat.st_mode.intValue()) == FileStat.S_IFDIR);
    Assertions.assertEquals(424242l, stat.st_mtim.tv_sec.get());
    Assertions.assertEquals(42, stat.st_mtim.tv_nsec.intValue());
    Assertions.assertEquals(424242l, stat.st_ctim.tv_sec.get());
    Assertions.assertEquals(42, stat.st_ctim.tv_nsec.intValue());
    Assumptions.assumingThat(Platform.IS_MAC || Platform.IS_WINDOWS, () -> {
        Assertions.assertEquals(424242l, stat.st_birthtime.tv_sec.get());
        Assertions.assertEquals(42, stat.st_birthtime.tv_nsec.intValue());
    });
    Assertions.assertEquals(424242l, stat.st_atim.tv_sec.get());
    Assertions.assertEquals(42, stat.st_atim.tv_nsec.intValue());
    Assertions.assertEquals(42l, stat.st_size.longValue());
}
项目:fuse-nio-adapter    文件:FileAttributesUtilTest.java   
@Test
public void testBasicFileAttributesToFileStat() {
    Instant instant = Instant.ofEpochSecond(424242l, 42);
    FileTime ftime = FileTime.from(instant);
    BasicFileAttributes attr = Mockito.mock(BasicFileAttributes.class);
    Mockito.when(attr.isDirectory()).thenReturn(true);
    Mockito.when(attr.lastModifiedTime()).thenReturn(ftime);
    Mockito.when(attr.creationTime()).thenReturn(ftime);
    Mockito.when(attr.lastAccessTime()).thenReturn(ftime);
    Mockito.when(attr.size()).thenReturn(42l);

    FileAttributesUtil util = new FileAttributesUtil();
    FileStat stat = util.basicFileAttributesToFileStat(attr);

    Assertions.assertTrue((FileStat.S_IFDIR & stat.st_mode.intValue()) == FileStat.S_IFDIR);
    Assertions.assertEquals(424242l, stat.st_mtim.tv_sec.get());
    Assertions.assertEquals(42, stat.st_mtim.tv_nsec.intValue());
    Assertions.assertEquals(424242l, stat.st_ctim.tv_sec.get());
    Assertions.assertEquals(42, stat.st_ctim.tv_nsec.intValue());
    Assumptions.assumingThat(Platform.IS_MAC || Platform.IS_WINDOWS, () -> {
        Assertions.assertEquals(424242l, stat.st_birthtime.tv_sec.get());
        Assertions.assertEquals(42, stat.st_birthtime.tv_nsec.intValue());
    });
    Assertions.assertEquals(424242l, stat.st_atim.tv_sec.get());
    Assertions.assertEquals(42, stat.st_atim.tv_nsec.intValue());
    Assertions.assertEquals(42l, stat.st_size.longValue());
}
项目:codingdojoleipzig    文件:UnitTest.java   
@Test
public void onlyRunThisOnCIEnvironment() {
    String result = new RomanConverter().convert(166);

    Assumptions.assumingThat(System.getenv("CI") != null, () ->
            assertEquals("CLXVI", result)
    );
}
项目:traute    文件:AbstractTrauteTest.java   
@BeforeEach
public void commonSetUp() {
    settingsBuilder = TrautePluginSettingsBuilder.settingsBuilder();
    expectCompilationResult = CompilationResultExpectationBuilder.expectCompilationResult();
    expectRunResult = RunResultExpectationBuilder.expectRunResult();

    Assumptions.assumeTrue(Boolean.getBoolean(ACTIVATION_PROPERTY));
}
项目:roboslack    文件:WebHookTokenTests.java   
@Test
void testFromEnvironment() {
    List<String> keysMissingFromEnvironment = WebHookToken.Env.missingTokenKeys();
    Assumptions.assumeTrue(keysMissingFromEnvironment.isEmpty(),
            () -> String.format("Skipping test, environment keys not found: [%s]",
                    Joiner.on(", ").join(keysMissingFromEnvironment)));
    WebHookToken token = WebHookToken.fromEnvironment();
    Assertions.assertFalse(Strings.isNullOrEmpty(token.partB()));
    Assertions.assertFalse(Strings.isNullOrEmpty(token.partT()));
    Assertions.assertFalse(Strings.isNullOrEmpty(token.partX()));
    Assertions.assertFalse(Strings.isNullOrEmpty(token.toString()));
}
项目:iStudent    文件:GreetingServiceTest.java   
@Test
@DisplayName("Retrieving a greeting by id should work")
void findGreetingById() {
    // Given we have a greeting already saved
    GreetingDto savedGreeting = service.createGreeting(createGreetingDto("We come in peace!"));
    Assumptions.assumeTrue(savedGreeting != null);
    // When we try to retrieve it
    Optional<GreetingDto> greetingByIdOptional = service.findGreetingById(savedGreeting.getId());
    // Then it should be there
    Assertions.assertAll("Retrieving a greeting by id should work",
            () -> assertTrue(greetingByIdOptional.isPresent(), "Could not find greeting by id"),
            () -> assertEquals(savedGreeting.getId(), greetingByIdOptional.get().getId(), "Retrieved greeting has invalid id"),
            () -> assertEquals(savedGreeting.getMessage(), greetingByIdOptional.get().getMessage(), "Retrieved greeting has different message from the saved one"));

}
项目:iStudent    文件:GreetingServiceTest.java   
@Test
@DisplayName("Removing a greeting by id should work")
void deleteGreetingById() {
    // Given we have a greeting already saved
    GreetingDto savedGreeting = service.createGreeting(createGreetingDto("We come in peace!"));
    Assumptions.assumeTrue(savedGreeting != null);
    // When we delete it
    service.deleteGreetingById(savedGreeting.getId());
    // Then it should be removed
    Optional<GreetingDto> deletedGreetingOptional = service.findGreetingById(savedGreeting.getId());
    Assertions.assertAll("Removing a greeting by id should work",
            () -> assertFalse(deletedGreetingOptional.isPresent(), "Found greeting by id when it should be deleted"));

}
项目:patience    文件:DelaySuppliersTest.java   
@ParameterizedTest
@DisplayName("it returns a delay supplier that returns the expected duration supplier")
@ArgumentsSource(ValidFixedArgumentsProvider.class)
void testReturnsExpectedDelaySupplier(Duration duration,
                                      List<Duration> expectedSuppliedDurations) {
    Assumptions.assumeTrue(null != expectedSuppliedDurations && !expectedSuppliedDurations.isEmpty(),
                           "Should have received a non-null and non-empty list of expected durations.");
    Supplier<Duration> supplier = DelaySuppliers.fixed(duration).create();
    Assertions.assertAll(expectedSuppliedDurations.stream().map(next -> () -> Assertions.assertEquals(next, supplier.get())));
}
项目:patience    文件:DelaySuppliersTest.java   
@ParameterizedTest
@DisplayName("it returns a delay supplier that returns the expected duration supplier")
@ArgumentsSource(ValidExponentialArgumentsProvider.class)
void testReturnsExpectedDelaySupplier(int base,
                                      Duration duration,
                                      List<Duration> expectedSuppliedDurations) {
    Assumptions.assumeTrue(null != expectedSuppliedDurations && !expectedSuppliedDurations.isEmpty(),
                           "Should have received a non-null and non-empty list of expected durations.");
    Supplier<Duration> supplier = DelaySuppliers.exponential(base, duration).create();
    Assertions.assertAll(expectedSuppliedDurations.stream().map(next -> () -> Assertions.assertEquals(next, supplier.get())));
}
项目:patience    文件:ExponentialDelaySupplierFactoryTest.java   
@ParameterizedTest
@DisplayName("it returns the expected type of Supplier")
@ArgumentsSource(ExpectedDurations.class)
void testReturnsExpectedSupplier(int base,
                                 Duration duration,
                                 List<Duration> expectedDurations) {
    Assumptions.assumeTrue(null != expectedDurations && !expectedDurations.isEmpty(),
                           "Should be given at least 1 expected result duration.");
    Supplier<Duration> supplier = getInstance(base, duration).create();
    Assertions.assertAll(expectedDurations.stream()
                                          .map(d -> (Executable) () -> Assertions.assertEquals(d,
                                                                                               supplier.get(),
                                                                                               "Duration supplier should return the expected durations."))
                                          .toArray(Executable[]::new));
}
项目:qpp-conversion-tool    文件:VariableDependantTestHelper.java   
static void assumeIsPresent(String variable) {
    Assumptions.assumeTrue(EnvironmentHelper.isPresent(variable));
}