How to use buildDefaultComparables method of org.assertj.core.api.AbstractZonedDateTimeAssert class

Best Assertj code snippet using org.assertj.core.api.AbstractZonedDateTimeAssert.buildDefaultComparables

Source:AbstractZonedDateTimeAssert.java Github

copy

Full Screen

...837 @Override838 @CheckReturnValue839 public SELF usingDefaultComparator() {840 SELF self = super.usingDefaultComparator();841 self.comparables = buildDefaultComparables();842 return self;843 }844 private Comparables buildDefaultComparables() {845 ChronoZonedDateTimeByInstantComparator defaultComparator = ChronoZonedDateTimeByInstantComparator.getInstance();846 return new Comparables(new ComparatorBasedComparisonStrategy(defaultComparator, defaultComparator.description()));847 }848 private ZonedDateTime[] convertToDateTimeArray(String... dateTimesAsString) {849 ZonedDateTime[] dates = new ZonedDateTime[dateTimesAsString.length];850 for (int i = 0; i < dateTimesAsString.length; i++) {851 dates[i] = parse(dateTimesAsString[i]);852 }853 return dates;854 }855 private ZonedDateTime[] changeToActualTimeZone(ZonedDateTime... dateTimes) {856 ZonedDateTime[] dates = new ZonedDateTime[dateTimes.length];857 for (int i = 0; i < dateTimes.length; i++) {858 dates[i] = sameInstantInActualTimeZone(dateTimes[i]);859 }860 return dates;861 }862 private void checkIsNotNullAndNotEmpty(Object[] values) {863 checkArgument(values != null, "The given ZonedDateTime array should not be null");864 checkArgument(values.length > 0, "The given ZonedDateTime array should not be empty");865 }866 /**867 * Obtains an instance of {@link ZonedDateTime} from a string representation in ISO date format.868 *869 * @param dateTimeAsString the string to parse870 * @return the parsed {@link ZonedDateTime}871 */872 @Override873 protected ZonedDateTime parse(String dateTimeAsString) {874 return ZonedDateTime.parse(dateTimeAsString, DateTimeFormatter.ISO_DATE_TIME);875 }876 private ZonedDateTime sameInstantInActualTimeZone(ZonedDateTime zonedDateTime) {877 if (zonedDateTime == null) return null; // nothing to convert in actual's TZ878 if (actual == null) return zonedDateTime; // no actual => let's keep zonedDateTime as it is.879 return zonedDateTime.withZoneSameInstant(actual.getZone());880 }881 /**882 * Check that the {@link ZonedDateTime} string representation to compare actual {@link ZonedDateTime} to is not null,883 * otherwise throws a {@link IllegalArgumentException} with an explicit message884 *885 * @param dateTimeAsString String representing the ZonedDateTime to compare actual with886 * @throws IllegalArgumentException with an explicit message if the given {@link String} is null887 */888 private static void assertDateTimeAsStringParameterIsNotNull(String dateTimeAsString) {889 checkArgument(dateTimeAsString != null,890 "The String representing the ZonedDateTime to compare actual with should not be null");891 }892 /**893 * Returns true if both datetime are in the same year, month and day of month, hour, minute and second, false894 * otherwise.895 *896 * @param actual the actual datetime. expected not be null897 * @param other the other datetime. expected not be null898 * @return true if both datetime are in the same year, month and day of month, hour, minute and second, false899 * otherwise.900 */901 private static boolean areEqualIgnoringNanos(ZonedDateTime actual, ZonedDateTime other) {902 return areEqualIgnoringSeconds(actual, other) && actual.getSecond() == other.getSecond();903 }904 /**905 * Returns true if both datetime are in the same year, month, day of month, hour and minute, false otherwise.906 *907 * @param actual the actual datetime. expected not be null908 * @param other the other datetime. expected not be null909 * @return true if both datetime are in the same year, month, day of month, hour and minute, false otherwise.910 */911 private static boolean areEqualIgnoringSeconds(ZonedDateTime actual, ZonedDateTime other) {912 return areEqualIgnoringMinutes(actual, other) && actual.getMinute() == other.getMinute();913 }914 /**915 * Returns true if both datetime are in the same year, month, day of month and hour, false otherwise.916 *917 * @param actual the actual datetime. expected not be null918 * @param other the other datetime. expected not be null919 * @return true if both datetime are in the same year, month, day of month and hour, false otherwise.920 */921 private static boolean areEqualIgnoringMinutes(ZonedDateTime actual, ZonedDateTime other) {922 return haveSameYearMonthAndDayOfMonth(actual, other) && actual.getHour() == other.getHour();923 }924 /**925 * Returns true if both datetime are in the same year, month and day of month, false otherwise.926 *927 * @param actual the actual datetime. expected not be null928 * @param other the other datetime. expected not be null929 * @return true if both datetime are in the same year, month and day of month, false otherwise930 */931 private static boolean haveSameYearMonthAndDayOfMonth(ZonedDateTime actual, ZonedDateTime other) {932 return haveSameYearAndMonth(actual, other) && actual.getDayOfMonth() == other.getDayOfMonth();933 }934 /**935 * Returns true if both datetime are in the same year and month, false otherwise.936 *937 * @param actual the actual datetime. expected not be null938 * @param other the other datetime. expected not be null939 * @return true if both datetime are in the same year and month, false otherwise940 */941 private static boolean haveSameYearAndMonth(ZonedDateTime actual, ZonedDateTime other) {942 return haveSameYear(actual, other) && actual.getMonth() == other.getMonth();943 }944 /**945 * Returns true if both datetime are in the same year, false otherwise.946 *947 * @param actual the actual datetime. expected not be null948 * @param other the other datetime. expected not be null949 * @return true if both datetime are in the same year, false otherwise950 */951 private static boolean haveSameYear(ZonedDateTime actual, ZonedDateTime other) {952 return actual.getYear() == other.getYear();953 }954 protected AbstractZonedDateTimeAssert(ZonedDateTime actual, Class<?> selfType) {955 super(actual, selfType);956 comparables = buildDefaultComparables();957 }958}...

Full Screen

Full Screen

buildDefaultComparables

Using AI Code Generation

copy

Full Screen

1package com.example;2import static org.assertj.core.api.Assertions.assertThat;3import java.time.ZonedDateTime;4import org.junit.jupiter.api.Test;5class ZonedDateTimeAssert_buildDefaultComparables_Test {6 void should_be_able_to_use_buildDefaultComparables() {7 ZonedDateTime actual = ZonedDateTime.parse("2011-12-03T10:15:30+01:00[Europe/Paris]");8 ZonedDateTime other = ZonedDateTime.parse("2011-12-03T10:15:30+01:00[Europe/Paris]");9 ZonedDateTime reference = ZonedDateTime.parse("2011-12-03T10:15:30+01:00[Europe/Paris]");10 ZonedDateTime[] result = org.assertj.core.api.AbstractZonedDateTimeAssert.buildDefaultComparables(actual, other, reference);11 assertThat(result).containsExactly(ZonedDateTime.parse("2011-12-03T10:15:30+01:00[Europe/Paris]"),12 ZonedDateTime.parse("2011-12-03T10:15:30+01:00[Europe/Paris]"),13 ZonedDateTime.parse("2011-12-03T10:15:30+01:00[Europe/Paris]"));14 }15}16package com.example;17import static org.assertj.core.api.Assertions.assertThat;18import java.time.ZonedDateTime;19import org.junit.jupiter.api.Test;20class ZonedDateTimeAssert_buildDefaultComparables_Test {21 void should_be_able_to_use_buildDefaultComparables() {22 ZonedDateTime actual = ZonedDateTime.parse("2011-12-03T10:15:30+

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful