Skip to content

Commit

Permalink
[#1824] Add Entity View type test values for more Java types
Browse files Browse the repository at this point in the history
  • Loading branch information
beikov committed Nov 12, 2023
1 parent 66b3e56 commit e3b8681
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 0 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ Changes that happened in releases
* Ignore `@Any` mapped attributes in enum type scanning
* Fix NPE caused by wrong order by expression during criteria builder copying
* Workaround Hibernate 6 returning null java type for enum parameters
* Add Entity View type test values for more Java types

### Backwards-incompatible changes

Expand Down
Empty file modified ci/build-github-latest.sh
100644 → 100755
Empty file.
Original file line number Diff line number Diff line change
Expand Up @@ -34,17 +34,23 @@
import java.io.Serializable;
import java.math.BigDecimal;
import java.math.BigInteger;
import java.net.MalformedURLException;
import java.net.URL;
import java.sql.Time;
import java.sql.Timestamp;
import java.util.Calendar;
import java.util.Collection;
import java.util.Collections;
import java.util.Currency;
import java.util.Date;
import java.util.GregorianCalendar;
import java.util.HashMap;
import java.util.Locale;
import java.util.Map;
import java.util.Properties;
import java.util.Set;
import java.util.TimeZone;
import java.util.UUID;

/**
*
Expand Down Expand Up @@ -100,13 +106,58 @@ private void loadDefaultProperties() {
typeTestValues.put(Timestamp.class, new Timestamp(1));
typeTestValues.put(Calendar.class, Calendar.getInstance());
typeTestValues.put(GregorianCalendar.class, new GregorianCalendar());
typeTestValues.put(TimeZone.class, TimeZone.getTimeZone("Universal"));
typeTestValues.put(byte[].class, new byte[] { Byte.MAX_VALUE });
typeTestValues.put(Byte[].class, new Byte[] { Byte.MAX_VALUE });
typeTestValues.put(char[].class, new char[] { Character.MAX_VALUE });
typeTestValues.put(Character[].class, new Character[] { Character.MAX_VALUE });
typeTestValues.put(BigInteger.class, BigInteger.TEN);
typeTestValues.put(BigDecimal.class, BigDecimal.TEN);
typeTestValues.put(Serializable.class, "-");

typeTestValues.put(Class.class, EntityViewConfigurationImpl.class);
typeTestValues.put(Currency.class, Currency.getInstance("XXX"));
typeTestValues.put(Locale.class, new Locale("", "", ""));
typeTestValues.put(UUID.class, UUID.randomUUID());
try {
typeTestValues.put(URL.class, new URL("https://blazebit.com"));
} catch (MalformedURLException e) {
// Ignore
}

// Java 8 time types
try {
Class<?> localDate = Class.forName("java.time.LocalDate");
typeTestValues.put(localDate, localDate.getMethod("now").invoke(null));
Class<?> localTime = Class.forName("java.time.LocalTime");
typeTestValues.put(localTime, localTime.getMethod("now").invoke(null));
Class<?> localDateTime = Class.forName("java.time.LocalDateTime");
typeTestValues.put(localDateTime, localDateTime.getMethod("now").invoke(null));
Class<?> offsetTime = Class.forName("java.time.OffsetTime");
typeTestValues.put(offsetTime, offsetTime.getMethod("now").invoke(null));
Class<?> offsetDateTime = Class.forName("java.time.OffsetDateTime");
typeTestValues.put(offsetDateTime, offsetDateTime.getMethod("now").invoke(null));
Class<?> zonedDateTime = Class.forName("java.time.ZonedDateTime");
typeTestValues.put(zonedDateTime, zonedDateTime.getMethod("now").invoke(null));
Class<?> duration = Class.forName("java.time.Duration");
typeTestValues.put(duration, duration.getMethod("ofNanos", long.class).invoke(null, 1L));
Class<?> instant = Class.forName("java.time.Instant");
typeTestValues.put(instant, instant.getMethod("now").invoke(null));
Class<?> monthDay = Class.forName("java.time.MonthDay");
typeTestValues.put(monthDay, monthDay.getMethod("now").invoke(null));
Class<?> year = Class.forName("java.time.Year");
typeTestValues.put(year, year.getMethod("now").invoke(null));
Class<?> yearMonth = Class.forName("java.time.YearMonth");
typeTestValues.put(yearMonth, yearMonth.getMethod("now").invoke(null));
Class<?> period = Class.forName("java.time.Period");
typeTestValues.put(period, period.getMethod("ofDays", int.class).invoke(null, 1));
Class<?> zoneId = Class.forName("java.time.ZoneId");
typeTestValues.put(zoneId, zoneId.getMethod("of", String.class).invoke(null, "Universal"));
Class<?> zoneOffset = Class.forName("java.time.ZoneOffset");
typeTestValues.put(zoneOffset, zoneOffset.getMethod("of", String.class).invoke(null, "+17:59:59"));
} catch (Exception ex) {
// If they aren't found, we ignore them
}
}

@Override
Expand Down

0 comments on commit e3b8681

Please sign in to comment.