-
Notifications
You must be signed in to change notification settings - Fork 28
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1084 from microsoft/fix/error-handling
Add default UTC offset when deserializing to OffsetDateTime fails due to a missing time offset value.
- Loading branch information
Showing
12 changed files
with
172 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,13 @@ | ||
dependencies { | ||
// Use JUnit Jupiter API for testing. | ||
testImplementation 'org.junit.jupiter:junit-jupiter-api:5.10.2' | ||
testImplementation 'org.junit.jupiter:junit-jupiter-params:5.10.2' | ||
|
||
// Use JUnit Jupiter Engine for testing. | ||
testRuntimeOnly 'org.junit.jupiter:junit-jupiter-engine' | ||
|
||
// This dependency is used internally, and not exposed to consumers on their own compile classpath. | ||
implementation 'jakarta.annotation:jakarta.annotation-api:2.1.1' | ||
|
||
api project(':components:abstractions') | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
39 changes: 39 additions & 0 deletions
39
...serialization/text/src/test/java/com/microsoft/kiota/serialization/TextParseNodeTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
package com.microsoft.kiota.serialization; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
import static org.junit.jupiter.api.Assertions.assertInstanceOf; | ||
import static org.junit.jupiter.api.Assertions.assertTrue; | ||
|
||
import org.junit.jupiter.api.Test; | ||
import org.junit.jupiter.params.ParameterizedTest; | ||
import org.junit.jupiter.params.provider.ValueSource; | ||
|
||
import java.time.format.DateTimeParseException; | ||
|
||
public class TextParseNodeTest { | ||
|
||
@Test | ||
void testParsesDateTimeOffset() { | ||
final var dateTimeOffsetString = "2024-02-12T19:47:39+02:00"; | ||
final var result = new TextParseNode(dateTimeOffsetString).getOffsetDateTimeValue(); | ||
assertEquals(dateTimeOffsetString, result.toString()); | ||
} | ||
|
||
@Test | ||
void testParsesDateTimeStringWithoutOffsetToDateTimeOffset() { | ||
final var dateTimeString = "2024-02-12T19:47:39"; | ||
final var result = new TextParseNode(dateTimeString).getOffsetDateTimeValue(); | ||
assertEquals(dateTimeString + "Z", result.toString()); | ||
} | ||
|
||
@ParameterizedTest | ||
@ValueSource(strings = {"2024-02-12T19:47:39 Europe/Paris", "19:47:39"}) | ||
void testInvalidOffsetDateTimeStringThrowsException(final String dateTimeString) { | ||
try { | ||
new TextParseNode(dateTimeString).getOffsetDateTimeValue(); | ||
} catch (final Exception ex) { | ||
assertInstanceOf(DateTimeParseException.class, ex); | ||
assertTrue(ex.getMessage().contains(dateTimeString)); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters