-
-
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
83c5694
commit 96657ef
Showing
5 changed files
with
139 additions
and
39 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
64 changes: 64 additions & 0 deletions
64
src/test/java/com/fasterxml/jackson/core/json/OutputStreamInitTest.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,64 @@ | ||
package com.fasterxml.jackson.core.json; | ||
|
||
import java.io.*; | ||
|
||
import com.fasterxml.jackson.core.JsonEncoding; | ||
import com.fasterxml.jackson.core.JsonFactory; | ||
import com.fasterxml.jackson.core.JsonGenerator; | ||
|
||
//[core#764] (and [databind#3508] | ||
public class OutputStreamInitTest | ||
extends com.fasterxml.jackson.core.BaseTest | ||
{ | ||
static class FailingOutputStream extends OutputStream { | ||
public int written = 0; | ||
public boolean failWrites = false; | ||
public boolean closed = false; | ||
|
||
public void startFailingWrites() { | ||
failWrites = true; | ||
} | ||
|
||
@Override | ||
public void close() { | ||
closed = true; | ||
} | ||
|
||
@Override | ||
public void write(int b) throws IOException { | ||
++written; | ||
if (failWrites) { | ||
throw new IOException("No writes!"); | ||
} | ||
} | ||
} | ||
|
||
static class FailingJsonFactory extends JsonFactory { | ||
private static final long serialVersionUID = 1L; | ||
|
||
public FailingOutputStream lastStream; | ||
|
||
@Override | ||
protected OutputStream _fileOutputStream(File f) { | ||
return (lastStream = new FailingOutputStream()); | ||
} | ||
} | ||
|
||
public void testForFile() throws Exception | ||
{ | ||
final FailingJsonFactory jsonF = new FailingJsonFactory(); | ||
try { | ||
JsonGenerator g = jsonF.createGenerator(new File("/tmp/test.json"), | ||
JsonEncoding.UTF8); | ||
g.writeString("foo"); | ||
jsonF.lastStream.startFailingWrites(); | ||
g.close(); | ||
fail("Should not pass"); | ||
} catch (Exception e) { | ||
verifyException(e, "No writes"); | ||
} | ||
assertNotNull(jsonF.lastStream); | ||
assertTrue(jsonF.lastStream.closed); | ||
} | ||
|
||
} |