Skip to content

Commit ca6ba71

Browse files
committed
Fix test failures from dependency upgrades
- Replace removed ISO8601Utils (gone in Gson 2.13.x) with java.time.Instant - Add junit-platform-launcher dep to align with JUnit 5.14.x - Add post-generation sed steps in Makefile to apply ISO8601Utils fix on regeneration
1 parent 65b10b9 commit ca6ba71

3 files changed

Lines changed: 20 additions & 7 deletions

File tree

Makefile

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,12 @@ build-docker:
2424
@echo "Removing problematic validateJsonElement calls..."
2525
find ./src/main/java ./src/test/java -type f -name '*.java' -exec sed -i '' '/Object\.validateJsonElement/d' {} + 2>/dev/null || true
2626
find ./src/main/java ./src/test/java -type f -name '*.java' -exec sed -i '' '/UUID\.validateJsonElement/d' {} + 2>/dev/null || true
27+
@echo "Replacing removed ISO8601Utils with java.time equivalents..."
28+
sed -i '' 's/import com.google.gson.internal.bind.util.ISO8601Utils;/import java.time.Instant;\nimport java.time.ZoneOffset;/' src/main/java/com/rootly/client/JSON.java 2>/dev/null || true
29+
sed -i '' 's/ISO8601Utils.format(date, true)/DateTimeFormatter.ISO_INSTANT.format(date.toInstant())/' src/main/java/com/rootly/client/JSON.java 2>/dev/null || true
30+
sed -i '' 's/ISO8601Utils.parse(date, new ParsePosition(0))/Date.from(Instant.parse(date))/' src/main/java/com/rootly/client/JSON.java 2>/dev/null || true
31+
sed -i '' 's/catch (ParseException e)/catch (ParseException | java.time.format.DateTimeParseException e)/' src/main/java/com/rootly/client/JSON.java 2>/dev/null || true
32+
sed -i '' '/import java.text.ParsePosition;/d' src/main/java/com/rootly/client/JSON.java 2>/dev/null || true
2733
@echo "✓ Client generation complete!"
2834

2935
# Generate client using local openapi-generator (requires Java and openapi-generator installed)
@@ -41,6 +47,12 @@ build-local:
4147
@echo "Removing problematic validateJsonElement calls..."
4248
find ./src/main/java ./src/test/java -type f -name '*.java' -exec sed -i '' '/Object\.validateJsonElement/d' {} + 2>/dev/null || true
4349
find ./src/main/java ./src/test/java -type f -name '*.java' -exec sed -i '' '/UUID\.validateJsonElement/d' {} + 2>/dev/null || true
50+
@echo "Replacing removed ISO8601Utils with java.time equivalents..."
51+
sed -i '' 's/import com.google.gson.internal.bind.util.ISO8601Utils;/import java.time.Instant;\nimport java.time.ZoneOffset;/' src/main/java/com/rootly/client/JSON.java 2>/dev/null || true
52+
sed -i '' 's/ISO8601Utils.format(date, true)/DateTimeFormatter.ISO_INSTANT.format(date.toInstant())/' src/main/java/com/rootly/client/JSON.java 2>/dev/null || true
53+
sed -i '' 's/ISO8601Utils.parse(date, new ParsePosition(0))/Date.from(Instant.parse(date))/' src/main/java/com/rootly/client/JSON.java 2>/dev/null || true
54+
sed -i '' 's/catch (ParseException e)/catch (ParseException | java.time.format.DateTimeParseException e)/' src/main/java/com/rootly/client/JSON.java 2>/dev/null || true
55+
sed -i '' '/import java.text.ParsePosition;/d' src/main/java/com/rootly/client/JSON.java 2>/dev/null || true
4456
@echo "✓ Client generation complete!"
4557

4658
# Upgrade all dependencies to latest versions

build.gradle

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,7 @@ dependencies {
119119
testImplementation 'org.junit.jupiter:junit-jupiter-api:5.14.3'
120120
testImplementation 'org.mockito:mockito-core:5.22.0'
121121
testRuntimeOnly 'org.junit.jupiter:junit-jupiter-engine:5.14.3'
122+
testRuntimeOnly 'org.junit.platform:junit-platform-launcher:1.14.3'
122123
}
123124

124125
javadoc {

src/main/java/com/rootly/client/JSON.java

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717
import com.google.gson.GsonBuilder;
1818
import com.google.gson.JsonParseException;
1919
import com.google.gson.TypeAdapter;
20-
import com.google.gson.internal.bind.util.ISO8601Utils;
2120
import com.google.gson.stream.JsonReader;
2221
import com.google.gson.stream.JsonWriter;
2322
import com.google.gson.JsonElement;
@@ -34,9 +33,10 @@
3433
import java.nio.charset.StandardCharsets;
3534
import java.text.DateFormat;
3635
import java.text.ParseException;
37-
import java.text.ParsePosition;
36+
import java.time.Instant;
3837
import java.time.LocalDate;
3938
import java.time.OffsetDateTime;
39+
import java.time.ZoneOffset;
4040
import java.time.format.DateTimeFormatter;
4141
import java.util.Date;
4242
import java.util.Locale;
@@ -1619,8 +1619,8 @@ public java.sql.Date read(JsonReader in) throws IOException {
16191619
if (dateFormat != null) {
16201620
return new java.sql.Date(dateFormat.parse(date).getTime());
16211621
}
1622-
return new java.sql.Date(ISO8601Utils.parse(date, new ParsePosition(0)).getTime());
1623-
} catch (ParseException e) {
1622+
return new java.sql.Date(Date.from(Instant.parse(date)).getTime());
1623+
} catch (ParseException | java.time.format.DateTimeParseException e) {
16241624
throw new JsonParseException(e);
16251625
}
16261626
}
@@ -1654,7 +1654,7 @@ public void write(JsonWriter out, Date date) throws IOException {
16541654
if (dateFormat != null) {
16551655
value = dateFormat.format(date);
16561656
} else {
1657-
value = ISO8601Utils.format(date, true);
1657+
value = DateTimeFormatter.ISO_INSTANT.format(date.toInstant());
16581658
}
16591659
out.value(value);
16601660
}
@@ -1673,8 +1673,8 @@ public Date read(JsonReader in) throws IOException {
16731673
if (dateFormat != null) {
16741674
return dateFormat.parse(date);
16751675
}
1676-
return ISO8601Utils.parse(date, new ParsePosition(0));
1677-
} catch (ParseException e) {
1676+
return Date.from(Instant.parse(date));
1677+
} catch (ParseException | java.time.format.DateTimeParseException e) {
16781678
throw new JsonParseException(e);
16791679
}
16801680
}

0 commit comments

Comments
 (0)