use of com.koushikdutta.ion.gson.GsonObjectParser in project ion by koush.
the class GsonTests method testParserCastingCallbackError.
public void testParserCastingCallbackError() throws Exception {
ByteBufferList b = new ByteBufferList(ByteBuffer.wrap("[]".getBytes()));
FilteredDataEmitter emitter = new FilteredDataEmitter() {
@Override
public boolean isPaused() {
return false;
}
};
GsonObjectParser g = new GsonObjectParser();
Future<JsonObject> ret = g.parse(emitter);
emitter.onDataAvailable(emitter, b);
emitter.getEndCallback().onCompleted(null);
final Semaphore s = new Semaphore(0);
ret.setCallback(new FutureCallback<JsonObject>() {
@Override
public void onCompleted(Exception e, JsonObject result) {
assertNull(result);
assertNotNull(e);
assertTrue(e instanceof ClassCastException);
s.release();
}
});
s.acquire();
}
use of com.koushikdutta.ion.gson.GsonObjectParser in project ion by koush.
the class GsonTests method testParserCastingError.
public void testParserCastingError() throws Exception {
ByteBufferList b = new ByteBufferList(ByteBuffer.wrap("[]".getBytes()));
FilteredDataEmitter emitter = new FilteredDataEmitter() {
@Override
public boolean isPaused() {
return false;
}
};
GsonObjectParser g = new GsonObjectParser();
Future<JsonObject> ret = g.parse(emitter);
emitter.onDataAvailable(emitter, b);
emitter.getEndCallback().onCompleted(null);
try {
JsonObject j = ret.get();
fail(j.toString());
} catch (Exception e) {
e.printStackTrace();
}
}
use of com.koushikdutta.ion.gson.GsonObjectParser in project ion by koush.
the class GsonTests method testParserCastingSuccess.
public void testParserCastingSuccess() throws Exception {
ByteBufferList b = new ByteBufferList(ByteBuffer.wrap("{}".getBytes()));
FilteredDataEmitter emitter = new FilteredDataEmitter() {
@Override
public boolean isPaused() {
return false;
}
};
GsonObjectParser g = new GsonObjectParser();
Future<JsonObject> ret = g.parse(emitter);
emitter.onDataAvailable(emitter, b);
emitter.getEndCallback().onCompleted(null);
JsonObject j = ret.get();
assertNotNull(j);
}
Aggregations