org.junit.jupiter.api.Tag Java Examples

The following examples show how to use org.junit.jupiter.api.Tag. 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: TestKata1InstantAndDateInterop.java    From java-katas with MIT License 7 votes vote down vote up
@Test
@Tag("TODO")
@Order(1)
public void verifyInstantAndDateHaveSameEpochMilliseconds() {

    // TODO: 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 = Instant.now();

    // TODO: 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()),
            null,
            "Date and Instant milliseconds should be equal");
}
 
Example #2
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 #3
Source File: TestSolution1InstantAndDateInterop.java    From java-katas with MIT License 6 votes vote down vote up
@Test
@Tag("PASSING")
@Order(5)
public void verifyInstantDateInteroperability() {

    // *****************************************************
    // Converting Date to an Instant.
    // *****************************************************
    Instant instant = classicDate.toInstant();
    assertEquals(classicDate.getTime(), instant.toEpochMilli());


    // *****************************************************
    // Converting an Instant to a Date.
    // *****************************************************
    // DONE: Replace the "null" below to convert an Instant into a Date
    //  Check: java.util.Date.from()
    Date anotherDate = Date.from(instant);
    assertEquals(classicDate, anotherDate);

    // *****************************************************
    // Think about why all conversions and inter-ops are
    // built into Date and not the newer java.time API.
    // *****************************************************
}
 
Example #4
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 #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(1)
public void verifyLocalDateUsingIntegers() {

    // *****************************************************
    // Is March = month 2 ( remember old date API? ) or
    // did Java 8 Date Time FINALLY address that and make
    // month numbering consistent with ISO8601 standard?
    // *****************************************************

    // TODO: Replace the LocalDate.now() below to create a LocalDate of 2015-03-17.
    //  Fix LocalDate to a date of 2015-03-17. Try using integers for years, months and dates.
    //  Check : java.time.LocalDate.of(int, int, int)
    LocalDate stPatricksDay2015 = LocalDate.now();

    assertEquals("2015-03-17",
            stPatricksDay2015.toString(),
            "The stPatricksDay2015 toString() should match the expected [2015-03-17]");
}
 
Example #7
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 #8
Source File: TestKata1InstantAndDateInterop.java    From java-katas with MIT License 6 votes vote down vote up
@Test
@Tag("TODO")
@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;

    // TODO: 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,
            null,
            1L,
            "Date and Instant seconds should almost match");
}
 
Example #9
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 #10
Source File: TestKata2OptionalConditionalFetching.java    From java-katas with MIT License 6 votes vote down vote up
@Test
@DisplayName("return a value either from non-empty Optional or from a Supplier")
@Tag("TODO")
@Order(3)
public void orElseGetSupplierValue() {

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

    /*
     * TODO:
     *  Replace the below to use an orElseGet(?) - instead of - the or(?)
     *  and the need to use get()
     *  Check API: java.util.Optional.ofNullable(?)
     */
    String nonNullString = null;

    assertTrue(nonNullString instanceof String,
            "The nonNullString should be an instance of String");

    assertEquals(nonNullString,
            "supplied",
            "The nonNullString should have a value of \"supplied\"");
}
 
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: TestSolution2LocalAndZonedDateTimes.java    From java-katas with MIT License 6 votes vote down vote up
@Test
@Tag("PASSING")
@Order(7)
public void verifyLocalDateTimeUsingClock() {

    // DONE: Replace the LocalDateTime.now() to produce the desired date and time.
    //  Fix LocalDateTime to the exact date-time of the Terminator (Original) Judgement Day.
    //  Check: java.time.LocalDateTime.now(java.time.Clock)
    LocalDateTime theOriginalJudgementDayDateTime =
            LocalDateTime.now(terminatorOriginalJudgementDay);

    assertEquals(8,
            theOriginalJudgementDayDateTime.getMonthValue(),
            "The Original Terminator Judgement Day was in the 8th month (August)");

    assertEquals(2,
            theOriginalJudgementDayDateTime.getHour(),
            "The hour should be at 2 AM");

    assertEquals(14,
            theOriginalJudgementDayDateTime.getMinute(),
            "The minute should be at 14");
}
 
Example #13
Source File: TestSolution1LambdaBasics.java    From java-katas with MIT License 6 votes vote down vote up
@Test
@Tag("PASSING")
@Order(7)
public void customFunctionWithMethodReference() {

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

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

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

}
 
Example #14
Source File: TestSolution2LocalAndZonedDateTimes.java    From java-katas with MIT License 6 votes vote down vote up
@Test
@Tag("PASSING")
@Order(6)
public void verifyLocalDateTimeUsingIntegers() {

    // DONE: 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.of(5, 5, 5, 5, 5, 5);

    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 #15
Source File: TestSolution1LambdaBasics.java    From java-katas with MIT License 6 votes vote down vote up
/**
 * @see IntegerPair
 * @see Function
 */
@Test
@Tag("PASSING")
@Order(4)
public void methodCallAsMethodReference() {
    IntegerPair integerPair = new IntegerPair();

    // DONE:
    //  Replace the below anonymous class with a method reference
    //  Most IDEs allow for an automatic conversion (no parenthesis for method)
    //  Hint: object -> Object::method
    Function<IntegerPair, Integer> getSecond = IntegerPair::getSecond;

    // DONE:
    //  Fix the assertion to return the correct expectation (6)
    //  Check API: java.util.function.Function.apply(?)
    assertEquals(6, getSecond.apply(integerPair),
            "The key should have a value of \'defaultKey\'");
}
 
Example #16
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 #17
Source File: TestKata1InstantAndDateInterop.java    From java-katas with MIT License 6 votes vote down vote up
@Test
@Tag("TODO")
@Order(5)
public void verifyInstantDateInteroperability() {

    // *****************************************************
    // Converting Date to an Instant.
    // *****************************************************
    Instant instant = classicDate.toInstant();
    assertEquals(classicDate.getTime(), instant.toEpochMilli());


    // *****************************************************
    // Converting an Instant to a Date.
    // *****************************************************
    // TODO: Replace the "null" below to convert an Instant into a Date
    //  Check: java.util.Date.from()
    Date anotherDate = null;
    assertEquals(classicDate, anotherDate);

    // *****************************************************
    // Think about why all conversions and inter-ops are
    // built into Date and not the newer java.time API.
    // *****************************************************
}
 
Example #18
Source File: TestSolution2OptionalConditionalFetching.java    From java-katas with MIT License 6 votes vote down vote up
@Test
@DisplayName("return either a value from non-empty Optional or a default value")
@Tag("PASSING")
@Order(2)
public void orElseReturnValue() {

    Integer anInteger = null;
    Optional<Integer> nullableInteger = Optional.ofNullable(anInteger);

    /*
     * DONE:
     *  Replace the below to use an orElse(?) - instead of - the or(?)
     *  and the need to use get()
     *  Check API: java.util.Optional.orElse(?)
     */
    Integer nonNullInteger = nullableInteger.orElse(10);

    assertTrue(nonNullInteger instanceof Integer,
            "The nonNullInteger should be an instance of Integer");

    assertEquals(nonNullInteger,
            10,
            "The nonNullInteger should not be empty");
}
 
Example #19
Source File: TestSolution2OptionalConditionalFetching.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("PASSING")
@Order(1)
public void orReturnOptional() {

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

    /*
     * DONE:
     *  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 = anOptional.or(() -> defaultOptional);

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

    assertFalse(nonNullOptional.isEmpty(),
            "The nonNullOptional should not be empty");
}
 
Example #20
Source File: TestKata2LambdasDeeperDive.java    From java-katas with MIT License 6 votes vote down vote up
@Test
@Tag("TODO")
@Order(4)
public void sortNames() {
    List<Person> persons =
            Arrays.asList(Person.ALICE, Person.BOB, Person.CATHY, Person.DHRUV, Person.EMILY);
    List<Person> expectedList =
            Arrays.asList(Person.EMILY, Person.BOB, Person.DHRUV, Person.ALICE, Person.CATHY);

    // TODO:
    //  Replace the anonymous class with a lambda.
    //  Replace the postions of o2 and o1 to pass the test as well
    Comparator<Person> nameSorter = new Comparator<>() {
        @Override
        public int compare(Person o1, Person o2) {
            return o2.getLastName().compareTo(o1.getLastName());
        }
    };
    List<Person> actualList = new ArrayList<>();
    actualList.addAll(persons);
    Collections.sort(actualList, nameSorter);

    assertEquals(expectedList, actualList, "The sorted lists should match");
}
 
Example #21
Source File: TestSolution1OptionalCreationAndFetchingValues.java    From java-katas with MIT License 6 votes vote down vote up
@Test
@DisplayName("create a nullable Optional from a variable")
@Tag("PASSING")
@Order(3)
public void createNullableOptionalFromValue() {

    Integer anInteger = null;

    /*
     * DONE:
     *  Replace the "null" to create a nullable Optional for anInteger.
     *  Check API: java.util.Optional.ofNullable(?)
     */
    Optional<Integer> optionalNullableInteger = Optional.ofNullable(anInteger);

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

    assertTrue(optionalNullableInteger.isEmpty(),
            "The optionalNullableInteger should be empty");
}
 
Example #22
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 #23
Source File: TestKata1OptionalCreationAndFetchingValues.java    From java-katas with MIT License 6 votes vote down vote up
@Test
@DisplayName("create an Optional from a variable")
@Tag("TODO")
@Order(2)
public void createOptionalFromValue() {

    Integer anInteger = 10;

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

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

    assertFalse(optionalForInteger.isEmpty(),
            "The optionalForInteger should not be empty");
}
 
Example #24
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 #25
Source File: TestKata2LocalAndZonedDateTimes.java    From java-katas with MIT License 5 votes vote down vote up
@Test
@Tag("TODO")
@Order(8)
public void verifyZonedDateTimeUsingIntegers() {

    ZonedDateTime allDateTimeOhFives =
            ZonedDateTime.of(5,
                    5,
                    5,
                    5,
                    5,
                    5,
                    555,
                    ZoneId.ofOffset("", ZoneOffset.of("-0500")));

    ZoneId gmtPlusOneZoneId = ZoneId.ofOffset("", ZoneOffset.of("+0100"));

    // TODO: Replace ZonedDateTime.now() to get date time in GMT +1 offset.
    //  Given a date of 2005-05-05 and a time on 05:05:05 AM in GMT -5,
    //  fix it to display in GMT +1. Show the same Instant in a different zone.
    //  Check: java.time.ZonedDateTime.withZoneSameInstant(java.time.ZoneId)
    //-----------------------------------------
    ZonedDateTime gmtPlusOneDateTimeAtAllFivesInGmtMinusFive =
            ZonedDateTime.now();

    assertEquals(3600,
            gmtPlusOneDateTimeAtAllFivesInGmtMinusFive.getOffset().getTotalSeconds(),
            "The offset should be 3600 seconds (1h)");

    assertEquals(11,
            gmtPlusOneDateTimeAtAllFivesInGmtMinusFive.getHour(),
            "5 AM in GMT -5 should imply 11AM in GMT +1");
}
 
Example #26
Source File: TestSolution3StreamsAndOptionals.java    From java-katas with MIT License 5 votes vote down vote up
@Test
    @DisplayName("Java 8 Streaming with Optional")
    @Tag("PASSING")
    @Order(1)
    public void java8Example() {

        /*
         * TODO:
         *  Replace the code below to use stream() API:
         *  1. stream() the namesSet
         *  2.   map() to get an Optional<NameValuePair> using this::findOptionalNameValuePair(?)
         *  3.   filter() to include non empty Optionals, use Optional::isPresent as predicate
         *  4.   map() to get the actual NameValuePair object, use Optional::get
         *  5.   collect() to a Set, use Collectors.toSet()
         */
        Set<NameValuePair> actualNameValuePairs = new TreeSet<>();
        for (String name : namesSet) {
            NameValuePair nameValuePair = nameNameValuePairMap.get(name);
            if (nameValuePair != null) {
                actualNameValuePairs.add(nameValuePair);
            }
        }

//        Set<NameValuePair> actualNameValuePairs =
//                namesSet.stream()
//                        .map(this::findOptionalNameValuePair)
//                        .filter(Optional::isPresent)
//                        .map(Optional::get)
//                        .collect(Collectors.toSet());

        assertEquals(
                expectedSetOfNameValuePairs,
                actualNameValuePairs,
                "The two collections should be the same");
    }
 
Example #27
Source File: TestSolution1OptionalCreationAndFetchingValues.java    From java-katas with MIT License 5 votes vote down vote up
@Test
@DisplayName("check a non-null Optional has a value")
@Tag("PASSING")
@Order(4)
public void checkOptionalForNonNullValueIsPresent() {

    Integer anInteger = 10;

    Optional<Integer> optionalInteger = Optional.ofNullable(anInteger);

    /*
     * DONE:
     *  Replace the "false" to check that the Optional has a non-null value.
     *  Check API: java.util.Optional.isPresent()
     */
    assertTrue(optionalInteger.isPresent(),
            "The optionalNullableInteger should be present");


    anInteger = null;

    optionalInteger = Optional.ofNullable(anInteger);

    /*
     * DONE:
     *  Replace the "false" to check that the Optional has a non-null value.
     *  Check API: java.util.Optional.isPresent()
     */
    assertFalse(optionalInteger.isPresent(),
            "The optionalNullableInteger should not be present");

}
 
Example #28
Source File: TestSolutionGetter.java    From java-katas with MIT License 5 votes vote down vote up
@Test
@Tag("PASSING")
@Order(4)
public void getPrivateVariableFromConstructedClassViaVarHandles() {

    try {

        /*
         * DONE:
         *  Replace the "null"s with valid values to get a VarHandle.
         *  Check API: java.lang.invoke.MethodHandles.privateLookupIn(?, ?)
         *             HINT: params are Target class and type of lookup
         *  Check API: java.lang.invoke.MethodHandles.Lookup.findVarHandle(?, ?, ?)
         *             HINT: params are Declaring class, Variable name, Variable type
         */
        VarHandle privateVariableVarHandle = MethodHandles
                .privateLookupIn(TestSolutionGetter.class, MethodHandles.lookup())
                .findVarHandle(TestSolutionGetter.class, "privateVariable", Integer.class);

        assertEquals(1,
                privateVariableVarHandle.coordinateTypes().size(),
                "There should only be one coordinateType");

        assertEquals(TestSolutionGetter.class,
                privateVariableVarHandle.coordinateTypes().get(0),
                "The only coordinate type is AttributeGetterTest");

        assertTrue(privateVariableVarHandle.isAccessModeSupported(VarHandle.AccessMode.GET),
                "Access mode for a GET should be true");

        assertEquals(2,
                privateVariableVarHandle.get(this),
                "The value of the field should be 2");

    } catch (NoSuchFieldException | IllegalAccessException | NullPointerException e) {

        fail(TEST_FAILURE.getValue() + e.getMessage());

    }
}
 
Example #29
Source File: TestSolution1InstantAndDateInterop.java    From java-katas with MIT License 5 votes vote down vote up
@Test
@Tag("PASSING")
@Order(4)
public void verifyInstantDefaultFormatting() {

    classicDateFormatter.setTimeZone(TimeZone.getTimeZone("UTC"));

    Instant instant = classicDate.toInstant();

    // DONE: Replace the "null" below to retrieve an instant as a string
    //  Assert that instant default toString matches the ISO8601 full date format.
    assertEquals(classicDateFormatter.format(classicDate),
            instant.toString(),
            "Instant toString() should match ISO8601 format");
}
 
Example #30
Source File: TestSolution1InstantAndDateInterop.java    From java-katas with MIT License 5 votes vote down vote up
@Test
@Tag("PASSING")
@Order(3)
public void verifyInstantHasNanoseconds() {

    Instant instant = Instant.now();

    // DONE: Replace the "null" below to get nanos from the Instant
    //  Assert that instant has nano seconds.
    //  Check: java.time.Instant.getNano()
    assertTrue(Integer.valueOf(instant.getNano()) > -1,
            "Instant should have nanoseconds");
}