-
Notifications
You must be signed in to change notification settings - Fork 4.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
validating the date format, add test case, since NumberFormatException extends IllegalArgumentException, it is only necessary to write IllegalArgumentException. #2529
Closed
Closed
Changes from 6 commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
11281be
issue 2472 throw exception if it is an invalid date format and since …
04c04d2
add test
48e6e99
Merge branch 'main' into main
Carpe-Wang 3bd2e14
add test
75278c8
Merge remote-tracking branch 'origin/main'
26e04d0
add a blank line before each of test methods
8ac0ffb
add if pattern != null
1a671b2
Merge branch 'main' into main
Carpe-Wang File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -16,6 +16,7 @@ | |
package com.google.gson.functional; | ||
|
||
import static com.google.common.truth.Truth.assertThat; | ||
import static org.junit.Assert.assertThrows; | ||
import static org.junit.Assert.fail; | ||
|
||
import com.google.gson.Gson; | ||
|
@@ -710,6 +711,21 @@ public void testStringBufferDeserialization() { | |
StringBuffer sb = gson.fromJson("'abc'", StringBuffer.class); | ||
assertThat(sb.toString()).isEqualTo("abc"); | ||
} | ||
@Test | ||
public void testSetDateFormatWithInvalidPattern() { | ||
GsonBuilder builder = new GsonBuilder(); | ||
String invalidPattern = "This is a invalid Pattern"; | ||
assertThrows(IllegalArgumentException.class, () -> { | ||
builder.setDateFormat(invalidPattern); | ||
}); | ||
} | ||
|
||
@Test | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Just one tiny thing: could you add a blank line before each of these new test methods? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. OK, I am sorry about that. |
||
public void testSetDateFormatWithValidPattern() { | ||
GsonBuilder builder = new GsonBuilder(); | ||
String validPattern = "yyyy-MM-dd"; | ||
builder.setDateFormat(validPattern); | ||
} | ||
|
||
private static class MyClassTypeAdapter extends TypeAdapter<Class<?>> { | ||
@Override | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It appears
null
might actually be a validpattern
value to clear any custom pattern previously set for the builder. The changes here would not support that anymore.@eamonnmcmanus, should
null
be supported?Apparently no unit test is covering that yet, might be good to add one (or I can add one in a separate PR if desired).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if pattern is null, here will throw null point exception.