org.junit.jupiter.api.Order Java Examples

The following examples show how to use org.junit.jupiter.api.Order. 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: TestMediator.java    From btdex with GNU General Public License v3.0 6 votes vote down vote up
@Test
@Order(1)
public void initSC() {
    sc = new InitSC();

    state = BuyContract.STATE_WAITING_PAYMT;
    long state_chain = sc.getContractFieldValue("state");

    if(state_chain == -1){
        System.out.println("Contract not found");
        return;
    } else if(state_chain == -2){
        System.out.println("Field not found");
        return;
    }
    assertEquals(state, state_chain);
}
 
Example #2
Source File: TestKata4DateTimePartials.java    From java-katas with MIT License 6 votes vote down vote up
@Test
@Tag("TODO")
@Order(2)
public void verifyMonthDay() {

    // Real world: Birthday or anniversary

    // TODO: Replace the MonthDay.now() below get a MonthDay anniversary for the Judegement Day.
    //  Check: java.time.MonthDay.now(java.time.Clock)
    MonthDay anniversaryofJudgementDay = MonthDay.now();

    assertEquals(Month.AUGUST,
            anniversaryofJudgementDay.getMonth(),
            "The month enumeration should match August.");

    assertEquals(8,
            anniversaryofJudgementDay.getMonthValue(),
            "The month value should match 8.");

    assertEquals(29,
            anniversaryofJudgementDay.getDayOfMonth(),
            "The date value should match 29.");
}
 
Example #3
Source File: TestSolution1InstantAndDateInterop.java    From java-katas with MIT License 6 votes vote down vote up
@Test
@Tag("PASSING")
@Order(2)
public void verifyInstantAndDateHaveAlmostSameEpochSeconds() {

    Instant instant = classicDate.toInstant();

    // NOTE: There is no simpler API method to get epoch seconds.
    long classicDateInSeconds = classicDate.getTime() / 1000;

    // DONE: Replace the "null" below to get seconds from epoch from the Instant
    //  Assert that the seconds from epoch from both Date and Instant are equal.
    //  Check: java.time.Instant.getEpochSecond()
    // NOTE: We use a custom assertion here since the millis to second arithmetic may cause
    //       rounding issues. We add a tolerance of 1 second.
    assertAlmostEquals(classicDateInSeconds,
            instant.getEpochSecond(),
            1L,
            "Date and Instant seconds should almost match");
}
 
Example #4
Source File: TestKata2LocalAndZonedDateTimes.java    From java-katas with MIT License 6 votes vote down vote up
@Test
@Tag("TODO")
@Order(4)
public void verifyLocalTimeUsingIntegers() {

    // *****************************************************
    // Demonstrate setting just the time to 7:52
    // *****************************************************

    // TODO: Replace the LocalTime.now() below to display a LocalTime of 7:52 AM.
    //  Fix LocalTime to 07:52 AM, using LocalTime with integers for hours and minutes.
    //  Check: java.time.LocalTime.of(int, int)
    //-----------------------------------------
    LocalTime sevenFiftyTwoAm = LocalTime.now();

    assertEquals("07:52",
            sevenFiftyTwoAm.toString(),
            "The time should show 07:52");
}
 
Example #5
Source File: TestSolution1InstantAndDateInterop.java    From java-katas with MIT License 6 votes vote down vote up
@Test
@Tag("PASSING")
@Order(1)
public void verifyInstantAndDateHaveSameEpochMilliseconds() {

    // DONE: Replace the Instant.now() with an instant from classicDate.
    //  Use a Date API that converts Date instances into Instant instances.
    //  Check: java.util.Date.toInstant()
    Instant instant = classicDate.toInstant();

    // DONE: Replace the "null" below to get milliseconds from epoch from the Instant
    //  Use an Instant API which converts it into milliseconds
    //  Check: java.time.Instant.toEpochMilli()
    assertEquals(Long.valueOf(classicDate.getTime()),
            instant.toEpochMilli(),
            "Date and Instant milliseconds should be equal");
}
 
Example #6
Source File: TestKata2LocalAndZonedDateTimes.java    From java-katas with MIT License 6 votes vote down vote up
@Test
@Tag("TODO")
@Order(6)
public void verifyLocalDateTimeUsingIntegers() {

    // TODO: Replace the LocalDateTime.now() to produce the desired date and time.
    //  Fix LocalDateTime to a date of 2005-05-05 and a time on 05:05:05 AM.
    //  Check: java.time.LocalDateTime.of(int, int, int, int, int, int)
    LocalDateTime allDateTimeOhFives =
            LocalDateTime.now();

    assertTrue(allDateTimeOhFives.getMonthValue() == 5,
            "The month should be May (5th Month)");

    assertEquals(5,
            allDateTimeOhFives.getMinute(),
            "The minute should be 5");

    assertTrue(allDateTimeOhFives.getSecond() == 5,
            "The second should be 5");
}
 
Example #7
Source File: TestKata1LambdaBasics.java    From java-katas with MIT License 6 votes vote down vote up
@Test
@Tag("TODO")
@Order(5)
public void convertAnonymousClassToLambda() {

    final AtomicInteger counter = new AtomicInteger();

    // TODO:
    //  Replace the anonymous class with a lambda. Hint: () ->
    //  The addAndGet() needs to be updated to add 1 instead of 0.
    Runnable runnable = new Runnable() {
        @Override
        public void run() {
            counter.addAndGet(0);
        }
    };

    runnable.run();

    assertEquals(1, counter.get() );
}
 
Example #8
Source File: TestKataDefaultConstructorInvocation.java    From java-katas with MIT License 6 votes vote down vote up
@Test
@Tag("PASSING")
@Order(1)
public void reflectionNoParamConstructor() {

    String expectedOutput = "[No param DemoClass constructor]" +
            " - Default constructor via Reflection";

    try {

        Class<DemoClass> demoClassClass =
                (Class<DemoClass>) Class.forName("none.cvg.handles.DemoClass");

        DemoClass demoClass =
                demoClassClass.getDeclaredConstructor().newInstance();

        assertEquals(expectedOutput,
                demoClass.printStuff("Default constructor via Reflection"),
                "Reflection invocation failed");

    } catch (InstantiationException | IllegalAccessException | InvocationTargetException |
            NoSuchMethodException | ClassNotFoundException e) {

        fail(REFLECTION_FAILURE.getValue() + e.getMessage());
    }
}
 
Example #9
Source File: TestTakeRetake.java    From btdex with GNU General Public License v3.0 6 votes vote down vote up
@Test
@Order(6)
public void testOfferTake() {
    // Take the offer
    BT.callMethod(takerPass, contract.getId(), compiled.getMethod("take"),
            BurstValue.fromPlanck(security + SellContract.ACTIVATION_FEE), BurstValue.fromBurst(0.1), 100,
            security, amount_chain).blockingGet();
    BT.forgeBlock();
    BT.forgeBlock();
    System.out.println("balance " + BT.getContractBalance(contract).longValue());

    // order should be taken, waiting for payment
    state_chain = BT.getContractFieldValue(contract, compiled.getField("state").getAddress());
    taker_chain = BT.getContractFieldValue(contract, compiled.getField("taker").getAddress());

    state = SellContract.STATE_WAITING_PAYMT;
    assertEquals(state, state_chain);
    assertEquals(taker.getSignedLongId(), taker_chain);
}
 
Example #10
Source File: TestKataPublicStaticMethodInvocation.java    From java-katas with MIT License 6 votes vote down vote up
@Test
@Tag("PASSING")
@Order(1)
public void reflectionPublicStaticMethod() {

    String expectedOutput = "DemoClass.class - Public static method via reflection";

    try {

        // Find the method on the class via a getMethod.
        Method publicStaticMethod =
                DemoClass.class.getMethod("publicStaticMethod",
                        String.class);

        assertEquals(expectedOutput,
                publicStaticMethod.invoke(DemoClass.class, "via reflection"),
                "Reflection invocation failed");

    } catch (NoSuchMethodException | IllegalAccessException | InvocationTargetException e) {

        fail(REFLECTION_FAILURE.getValue() + e.getMessage());
    }
}
 
Example #11
Source File: TestSolution1LambdaBasics.java    From java-katas with MIT License 6 votes vote down vote up
@Test
@Tag("PASSING")
@Order(5)
public void convertAnonymousClassToLambda() {

    final AtomicInteger counter = new AtomicInteger();

    // DONE:
    //  Replace the anonymous class with a lambda. Hint: () ->
    //  The addAndGet() needs to be updated to add 1 instead of 0.
    Runnable runnable = () -> counter.addAndGet(1);

    runnable.run();

    assertEquals(1, counter.get() );
}
 
Example #12
Source File: TestKataPublicMethodInvocation.java    From java-katas with MIT License 6 votes vote down vote up
@Test
@Tag("PASSING")
@Order(1)
public void reflectionPublicMethod() {

    String expectedOutput = "[DemoClass] - Public method - via reflection";

    try {

        // Find the method on the class via a getMethod.
        Method publicMethod =
                DemoClass.class.getMethod("publicMethod",
                        String.class);

        DemoClass demoClass = new DemoClass();

        assertEquals(expectedOutput,
                publicMethod.invoke(demoClass, "via reflection"),
                "Reflection invocation failed");

    } catch (NoSuchMethodException | IllegalAccessException | InvocationTargetException e) {

        fail(REFLECTION_FAILURE.getValue() + e.getMessage());
    }
}
 
Example #13
Source File: TestDispute.java    From btdex with GNU General Public License v3.0 6 votes vote down vote up
@Test
@Order(1)
public void initSC() throws IOException {
    sc = new CreateNoDepositSC(block * 10);
    makerPass = Long.toString(System.currentTimeMillis());
    sc.registerSC(makerPass);

    BurstAddress maker = BT.getBurstAddressFromPassphrase(makerPass);
    BT.forgeBlock();
    compiled = sc.getCompiled();
    contract = BT.findContract(maker, sc.getName());

    BurstValue send = BurstValue.fromBurst(100);
    BT.sendAmount(makerPass, contract.getId(), send, BurstValue.fromBurst(0.1)).blockingGet();
    BT.forgeBlock();
    BT.forgeBlock();

    state_chain = BT.getContractFieldValue(contract, compiled.getField("state").getAddress());
    state = SellNoDepositContract.STATE_OPEN;
    assertEquals(state, state_chain, "State not equal");
}
 
Example #14
Source File: TestSolution1OptionalCreationAndFetchingValues.java    From java-katas with MIT License 6 votes vote down vote up
@Test
@DisplayName("create an Optional from a variable")
@Tag("PASSING")
@Order(2)
public void createOptionalFromValue() {

    Integer anInteger = 10;

    /*
     * DONE:
     *  Replace the "null" to create an Optional for anInteger.
     *  Check API: java.util.Optional.of(?)
     */
    Optional<Integer> optionalForInteger = Optional.of(anInteger);

    assertTrue(optionalForInteger instanceof Optional,
            "The optionalEmptyString should be an instance of Optional");

    assertFalse(optionalForInteger.isEmpty(),
            "The optionalForInteger should not be empty");
}
 
Example #15
Source File: TestKata4DateTimePartials.java    From java-katas with MIT License 6 votes vote down vote up
@Test
@Tag("TODO")
@Order(4)
public void verifyYearMonth() {

    // Real world: CreditCard or Medicine expiration.

    // TODO: Replace the YearMonth.now() below get a YearMonth for the Judegement Day.
    //  Check: java.time.YearMonth.now(java.time.Clock)
    YearMonth yearMonthOfJudgementDay = YearMonth.now();

    assertEquals(Month.AUGUST,
            yearMonthOfJudgementDay.getMonth(),
            "The month enumeration should match August.");

    assertEquals(8,
            yearMonthOfJudgementDay.getMonthValue(),
            "The month value should match 8.");

    assertEquals(1997,
            yearMonthOfJudgementDay.getYear(),
            "The year value should match 1997.");
}
 
Example #16
Source File: TestSolution4DateTimePartials.java    From java-katas with MIT License 6 votes vote down vote up
@Test
@Tag("PASSING")
@Order(2)
public void verifyMonthDay() {

    // Real world: Birthday or anniversary

    // TODO: Replace the MonthDay.now() below get a MonthDay anniversary for the Judegement Day.
    //  Check: java.time.MonthDay.now(java.time.Clock)
    MonthDay anniversaryofJudgementDay = MonthDay.now(terminatorOriginalJudgementDay);

    assertEquals(Month.AUGUST,
            anniversaryofJudgementDay.getMonth(),
            "The month enumeration should match August.");

    assertEquals(8,
            anniversaryofJudgementDay.getMonthValue(),
            "The month value should match 8.");

    assertEquals(29,
            anniversaryofJudgementDay.getDayOfMonth(),
            "The date value should match 29.");
}
 
Example #17
Source File: TestMakerDisputeWithdraw.java    From btdex with GNU General Public License v3.0 6 votes vote down vote up
@Test
@Order(1)
public void initSC() {
    sc = new InitSC();

    long state = SellContract.STATE_WAITING_PAYMT;
    long state_chain = sc.getContractFieldValue("state");

    if(state_chain == -1){
        System.out.println("Contract not found");
        return;
    } else if(state_chain == -2){
        System.out.println("Field not found");
        return;
    }
    assertEquals(state, state_chain);

}
 
Example #18
Source File: TestKata2OptionalConditionalFetching.java    From java-katas with MIT License 6 votes vote down vote up
@Test
@DisplayName("return an Optional of either a non-null value or from a Supplier")
@Tag("TODO")
@Order(1)
public void orReturnOptional() {

    Optional<String> defaultOptional = Optional.of("supplied");
    Optional<String> anOptional = Optional.empty();

    /*
     * TODO:
     *  Replace the empty optional to either return the anOptional, if it has a value
     *  or return the defaultOptional (use a Supplier)
     *  Check API: java.util.Optional.or(?)
     */
    Optional<String> nonNullOptional = Optional.empty();

    assertTrue(nonNullOptional instanceof Optional,
            "The nonNullOptional should be an instance of Optional");

    assertFalse(nonNullOptional.isEmpty(),
            "The nonNullOptional should not be empty");
}
 
Example #19
Source File: TestSolution1LambdaBasics.java    From java-katas with MIT License 6 votes vote down vote up
@Test
@Tag("PASSING")
@Order(6)
public void customFunctionWithLambda() {

    int integer = 10;

    String s = Integer.toBinaryString(integer);

    // DONE:
    //  Create a Function that maps any integer into a String using a lambda syntax
    //  Do not create a new method. Replace the empty String below to invoke a toBinaryString
    //  Check API: java.util.function.Function
    //  Check API: java.util.function.Function.apply(?)
    Function<Integer, String> toBinaryStringFunction = i -> Integer.toBinaryString(i);

    assertEquals("1010",
            toBinaryStringFunction.apply(10),
            "");

    assertEquals("11110",
            toBinaryStringFunction.apply(30),
            "");

}
 
Example #20
Source File: TestSolution1OptionalCreationAndFetchingValues.java    From java-katas with MIT License 6 votes vote down vote up
@Test
@DisplayName("create an empty Optional")
@Tag("PASSING")
@Order(1)
public void emptyOptional() {

    /*
     * DONE:
     *  Replace the "null" to create an empty Optional.
     *  Check API: java.util.Optional.empty()
     */
    Optional<String> optionalEmptyString = Optional.empty();

    assertTrue(optionalEmptyString instanceof Optional,
            "The optionalEmptyString should be an instance of Optional");

    assertTrue(optionalEmptyString.isEmpty(),
            "The optionalEmptyString should be empty");
}
 
Example #21
Source File: TestKata2LocalAndZonedDateTimes.java    From java-katas with MIT License 6 votes vote down vote up
@Test
@Tag("TODO")
@Order(2)
public void verifyLocalDateUsingMonthEnums() {

    // *****************************************************
    // A tribute to 2001: A Space Odyssey.
    // HAL, the sentient computer,
    // was 'born' on January 12th 1999
    // *****************************************************

    // TODO: Replace the LocalDate.now() below to create a LocalDate of 1999-01-12.
    //  Fix LocalDate below to HAL's birthday. Use Month enums.
    //  No longer a confusion about whether January is 0 or 1.
    LocalDate halsBirthday = LocalDate.now();

    assertEquals(1999,
            halsBirthday.getYear(),
            "LocalDate year should match the expected");

    assertEquals(Month.JANUARY,
            halsBirthday.getMonth(),
            "LocalDate month should match the expected");
}
 
Example #22
Source File: Unit5MyExtraTest.java    From hol-streams with Apache License 2.0 6 votes vote down vote up
@Test
@Order(0)
void actorToFilmCount() {
    final Join<Tuple3<FilmActor, Film, Actor>> join = joinComponent
        .from(FilmActorManager.IDENTIFIER)
        .innerJoinOn(Film.FILM_ID).equal(FilmActor.FILM_ID)
        .innerJoinOn(Actor.ACTOR_ID).equal(FilmActor.ACTOR_ID)
        .build(Tuples::of);

    final Map<Actor, Long> expected = join.stream()
        .collect(
            groupingBy(Tuple3::get2, counting())
        );

    tester(expected, instance.actorToFilmCount(joinComponent));
}
 
Example #23
Source File: TestKata1LambdaBasics.java    From java-katas with MIT License 6 votes vote down vote up
@Test
@Tag("TODO")
@Order(6)
public void customFunctionWithLambda() {

    int integer = 10;

    String s = Integer.toBinaryString(integer);

    // TODO:
    //  Create a Function that maps any integer into a String using a lambda syntax
    //  Do not create a new method. Replace the empty String below to invoke a toBinaryString
    //  Check API: java.util.function.Function
    //  Check API: java.util.function.Function.apply(?)
    Function<Integer, String> toBinaryStringFunction = i -> "";

    assertEquals("1010",
            toBinaryStringFunction.apply(10),
            "");

    assertEquals("11110",
            toBinaryStringFunction.apply(30),
            "");

}
 
Example #24
Source File: AbstractDebeziumTest.java    From camel-quarkus with Apache License 2.0 6 votes vote down vote up
@Test
@Order(2)
public void testUpdate() throws SQLException {
    if (getConnection() == null) {
        LOG.warn("Test 'testUpdate' is skipped, because container is not running.");
        return;
    }

    executeUpdate(String.format("INSERT INTO %s (name, city) VALUES ('%s', '%s')", getCompanyTableName(),
            COMPANY_2, CITY_2));

    //validate that event is in queue
    receiveResponse(200, containsString(COMPANY_2));

    executeUpdate(String.format("UPDATE %s SET name = '%s_changed' WHERE city = '%s'", getCompanyTableName(),
            COMPANY_2, CITY_2));

    //validate that event for delete is in queue
    receiveResponse(204, is(emptyOrNullString()));
    //validate that event for create is in queue
    receiveResponse(200, containsString(COMPANY_2 + "_changed"));
}
 
Example #25
Source File: TestMakerTakerAgreeReopenTakeDispute.java    From btdex with GNU General Public License v3.0 5 votes vote down vote up
@Test
@Order(2)
public void testMakerDispute() {
    sc.dispute(sc.getMaker(), amountToMaker, amountToTaker);
    BT.forgeBlock();
    BT.forgeBlock();

    state = SellContract.STATE_CREATOR_DISPUTE;
    assertEquals(state, state&sc.getContractFieldValue("state"));
    assertEquals(amountToMaker, sc.getContractFieldValue("disputeCreatorAmountToCreator"));
    assertEquals(amountToTaker, sc.getContractFieldValue("disputeCreatorAmountToTaker"));
    assertEquals(0, sc.getContractFieldValue("disputeTakerAmountToTaker"));
    assertEquals(0, sc.getContractFieldValue("disputeTakerAmountToCreator"));
}
 
Example #26
Source File: Unit2MyIntermediateTest.java    From hol-streams with Apache License 2.0 5 votes vote down vote up
@Test
@Order(5)
void strings() {
    final List<Object> OBJECTS = Arrays.asList("First", 21, new Random(42), new ArrayList<>(), "Last");
    tester(
        instance,
        OBJECTS.stream().filter(String.class::isInstance).map(String.class::cast),
        i -> i.strings(OBJECTS.stream()),
        s -> s.collect(toList())
    );
}
 
Example #27
Source File: Unit2MyIntermediateTest.java    From hol-streams with Apache License 2.0 5 votes vote down vote up
@Test
@Order(2)
void firstDistinctTwoWordsLongerThanThreeCharsInAlphabeticOrder() {
    tester(
        instance,
        WORDS.stream().filter(s -> s.length() > 3).distinct().limit(2).sorted(),
        i -> i.firstDistinctTwoWordsLongerThanThreeCharsInAlphabeticOrder(WORDS.stream()),
        s -> s.collect(toList())
    );
}
 
Example #28
Source File: TestKataCompareAndSet.java    From java-katas with MIT License 5 votes vote down vote up
@Test
@Tag("PASSING")
@Order(2)
public void compareAndSetUsingAtomicReferenceFieldUpdater() {

    final AtomicReferenceFieldUpdater<TestKataCompareAndSet, Integer> valueUpdater =
            AtomicReferenceFieldUpdater.newUpdater(TestKataCompareAndSet.class,
                    Integer.class,
                    "privateVolatile");

    boolean exchanged = valueUpdater.compareAndSet(this, currentValue, newValue);

    assertTrue(exchanged,
            "The value should have been changed to 7, " +
                    "hence exchanged should be true"
            );

    assertEquals(newValue,
            valueUpdater.get(this),
            "The value of the privateVolatile should now be 7");

    exchanged = valueUpdater.compareAndSet(this, 2, 33);

    assertFalse(exchanged,
            "The value should not have changed since the expected value " +
                    "did not match, hence exchanged should be false"
            );

    assertEquals(newValue,
            valueUpdater.get(this),
            "The value of the privateVolatile should still be 7");
}
 
Example #29
Source File: TestSolution3PeriodsAndDurations.java    From java-katas with MIT License 5 votes vote down vote up
@Test
@Tag("PASSING")
@Order(2)
public void verifyPeriodCreatedUsingFluentMethods() {

    // Create a Period instance
    // TODO: Replace the Period.ZERO to a time period of 20 years and 10 days.
    //  Check : java.time.Period.ofYears(int).withDays(int)
    Period twentyYearsAndTenDays = Period.ofYears(20).withDays(10);

    assertEquals(20,
            twentyYearsAndTenDays.get(ChronoUnit.YEARS),
            "The Period should include twenty years");

    assertEquals(10,
            twentyYearsAndTenDays.get(ChronoUnit.DAYS),
            "The Period should include ten days");


    // Add the Period to a LocalDateTime
    LocalDateTime tOJDateTime = LocalDateTime.now(terminatorOriginalJudgementDay);

    // TODO: Call a method on tOJDateTime to add the newly created Period
    //  Check : java.time.LocalDateTime.plus(java.time.temporal.TemporalAmount)
    LocalDateTime calculatedTwentyYearsAndTenDaysLater =
            tOJDateTime.plus(twentyYearsAndTenDays);

    //1997-08-29 after 20 years and 10 days => 2017-09=08
    assertEquals(2017,
            calculatedTwentyYearsAndTenDaysLater.getYear(),
            "The year after 20 years and 10 days should be 2017");

    assertEquals(9,
            calculatedTwentyYearsAndTenDaysLater.getMonthValue(),
            "The month value after 20 years and 10 days should be 9");

    assertEquals(8,
            calculatedTwentyYearsAndTenDaysLater.getDayOfMonth(),
            "The date after 20 years and 10 days should be 8");
}
 
Example #30
Source File: TestKata4DateTimePartials.java    From java-katas with MIT License 5 votes vote down vote up
@Test
@Tag("TODO")
@Order(1)
public void verifyMonth() {

    LocalDateTime tOJDateTime = LocalDateTime.now(terminatorOriginalJudgementDay);

    // TODO: Replace the "null" below get a Month instance.
    //  Check: java.time.LocalDateTime.getMonth()
    Month tOJMonth = null;

    assertEquals(Month.AUGUST,
            tOJMonth,
            "The Month enumeration should match August.");
}