-
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
Formalize null handling of type tokens #2030
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -17,6 +17,7 @@ | |
package com.google.gson; | ||
|
||
import com.google.gson.internal.Excluder; | ||
import com.google.gson.reflect.TypeToken; | ||
import com.google.gson.stream.JsonReader; | ||
import com.google.gson.stream.JsonWriter; | ||
import java.io.IOException; | ||
|
@@ -26,6 +27,9 @@ | |
import java.util.ArrayList; | ||
import java.util.HashMap; | ||
import junit.framework.TestCase; | ||
import org.junit.Rule; | ||
import org.junit.Test; | ||
import org.junit.rules.ExpectedException; | ||
|
||
/** | ||
* Unit tests for {@link Gson}. | ||
|
@@ -82,4 +86,16 @@ private static final class TestTypeAdapter extends TypeAdapter<Object> { | |
} | ||
@Override public Object read(JsonReader in) throws IOException { return null; } | ||
} | ||
|
||
public void testNullAdapterLookup() { | ||
// Formalize the handling of null type tokens (previously it was partially handled, but still throwing an error) | ||
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. Not sure if this comment line here is useful in the test code. To me this message only seems to be relevant regarding why this pull request or commit was created, but not why this test exists. Note that unlike eamonnmcmanus, I am not a member of this project. Feel free to consider my comments only as suggestion. |
||
// Note: ExpectedException cannot be used due to test suite extending TestCase | ||
try { | ||
new Gson().getAdapter((TypeToken<Object>) null); | ||
assertTrue("Unreachable", false); | ||
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 |
||
} | ||
catch (NullPointerException e) { | ||
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. Can you join this to the previous line?
|
||
assertEquals("No type specified", e.getMessage()); | ||
} | ||
} | ||
} |
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.
These imports seem to be unused.