-
-
Notifications
You must be signed in to change notification settings - Fork 148
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
3e481c6
commit 580159d
Showing
7 changed files
with
117 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
57 changes: 57 additions & 0 deletions
57
properties/src/test/java/com/fasterxml/jackson/dataformat/javaprop/StreamClosingTest.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,57 @@ | ||
package com.fasterxml.jackson.dataformat.javaprop; | ||
|
||
import com.fasterxml.jackson.core.JsonParser; | ||
import com.fasterxml.jackson.databind.ObjectMapper; | ||
import com.fasterxml.jackson.dataformat.javaprop.testutil.CloseStateInputStream; | ||
import com.fasterxml.jackson.dataformat.javaprop.testutil.CloseStateReader; | ||
|
||
@SuppressWarnings("resource") | ||
public class StreamClosingTest extends ModuleTestBase | ||
{ | ||
// for [dataformats-text#179] | ||
public static class Bean179 { | ||
public int value; | ||
|
||
@Override public String toString() { return "[value: "+value+"]"; } | ||
} | ||
|
||
private final ObjectMapper PROPS_MAPPER = mapperForProps(); | ||
|
||
public void testInputStreamClosing() throws Exception | ||
{ | ||
// by default, SHOULD close it: | ||
CloseStateInputStream in = CloseStateInputStream.forString("value = 42"); | ||
assertFalse(in.closed); | ||
Bean179 result = PROPS_MAPPER.readValue(in, Bean179.class); | ||
assertNotNull(result); | ||
assertTrue(in.closed); | ||
|
||
// but not if reconfigured | ||
in = CloseStateInputStream.forString("value = 42"); | ||
assertFalse(in.closed); | ||
result = PROPS_MAPPER.readerFor(Bean179.class) | ||
.without(JsonParser.Feature.AUTO_CLOSE_SOURCE) | ||
.readValue(in); | ||
assertNotNull(result); | ||
assertTrue(in.closed); | ||
} | ||
|
||
public void testReaderClosing() throws Exception | ||
{ | ||
// by default, SHOULD close it: | ||
CloseStateReader r = CloseStateReader.forString("value = 42"); | ||
assertFalse(r.closed); | ||
Bean179 result = PROPS_MAPPER.readValue(r, Bean179.class); | ||
assertNotNull(result); | ||
assertTrue(r.closed); | ||
|
||
// but not if reconfigured | ||
r = CloseStateReader.forString("value = 42"); | ||
assertFalse(r.closed); | ||
result = PROPS_MAPPER.readerFor(Bean179.class) | ||
.without(JsonParser.Feature.AUTO_CLOSE_SOURCE) | ||
.readValue(r); | ||
assertNotNull(result); | ||
assertTrue(r.closed); | ||
} | ||
} |
24 changes: 24 additions & 0 deletions
24
...c/test/java/com/fasterxml/jackson/dataformat/javaprop/testutil/CloseStateInputStream.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,24 @@ | ||
package com.fasterxml.jackson.dataformat.javaprop.testutil; | ||
|
||
import java.io.ByteArrayInputStream; | ||
import java.io.FilterInputStream; | ||
import java.io.IOException; | ||
import java.io.InputStream; | ||
|
||
public class CloseStateInputStream extends FilterInputStream | ||
{ | ||
public boolean closed = false; | ||
|
||
public CloseStateInputStream(InputStream in) { super(in); } | ||
|
||
@Override | ||
public void close() throws IOException { | ||
closed = true; | ||
super.close(); | ||
} | ||
|
||
public static CloseStateInputStream forString(String input) throws IOException { | ||
return new CloseStateInputStream(new ByteArrayInputStream( | ||
input.getBytes("UTF-8"))); | ||
} | ||
} |
20 changes: 20 additions & 0 deletions
20
...es/src/test/java/com/fasterxml/jackson/dataformat/javaprop/testutil/CloseStateReader.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,20 @@ | ||
package com.fasterxml.jackson.dataformat.javaprop.testutil; | ||
|
||
import java.io.*; | ||
|
||
public class CloseStateReader extends FilterReader | ||
{ | ||
public boolean closed = false; | ||
|
||
public CloseStateReader(Reader r) { super(r); } | ||
|
||
@Override | ||
public void close() throws IOException { | ||
closed = true; | ||
super.close(); | ||
} | ||
|
||
public static CloseStateReader forString(String input) throws IOException { | ||
return new CloseStateReader(new StringReader(input)); | ||
} | ||
} |
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