-
-
Notifications
You must be signed in to change notification settings - Fork 787
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
2dee63a
commit 83c5694
Showing
3 changed files
with
84 additions
and
3 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
69 changes: 69 additions & 0 deletions
69
src/test/java/com/fasterxml/jackson/core/json/InputStreamInitTest.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,69 @@ | ||
package com.fasterxml.jackson.core.json; | ||
|
||
import java.io.File; | ||
import java.io.IOException; | ||
import java.io.InputStream; | ||
import java.net.URL; | ||
|
||
import com.fasterxml.jackson.core.*; | ||
|
||
// [core#763] (and [databind#3455] | ||
public class InputStreamInitTest | ||
extends com.fasterxml.jackson.core.BaseTest | ||
{ | ||
static class FailingInputStream extends InputStream { | ||
public boolean closed = false; | ||
|
||
@Override | ||
public void close() { | ||
closed = true; | ||
} | ||
|
||
@Override | ||
public int read() throws IOException { | ||
throw new IOException("Will not read, ever!"); | ||
} | ||
} | ||
|
||
static class FailingJsonFactory extends JsonFactory { | ||
private static final long serialVersionUID = 1L; | ||
|
||
public FailingInputStream lastStream; | ||
|
||
@Override | ||
protected InputStream _fileInputStream(File f) throws IOException { | ||
return (lastStream = new FailingInputStream()); | ||
} | ||
|
||
@Override | ||
protected InputStream _optimizedStreamFromURL(URL url) throws IOException { | ||
return (lastStream = new FailingInputStream()); | ||
} | ||
} | ||
|
||
public void testForFile() throws Exception | ||
{ | ||
final FailingJsonFactory jsonF = new FailingJsonFactory(); | ||
try { | ||
/*JsonParser p =*/ jsonF.createParser(new File("/tmp/test.json")); | ||
fail("Should not pass"); | ||
} catch (IOException e) { | ||
verifyException(e, "Will not read"); | ||
} | ||
assertNotNull(jsonF.lastStream); | ||
assertTrue(jsonF.lastStream.closed); | ||
} | ||
|
||
public void testForURL() throws Exception | ||
{ | ||
final FailingJsonFactory jsonF = new FailingJsonFactory(); | ||
try { | ||
/*JsonParser p =*/ jsonF.createParser(new URL("http://localhost:80/")); | ||
fail("Should not pass"); | ||
} catch (IOException e) { | ||
verifyException(e, "Will not read"); | ||
} | ||
assertNotNull(jsonF.lastStream); | ||
assertTrue(jsonF.lastStream.closed); | ||
} | ||
} |