ProtocolUtil.skip() throws ProtocolException, not AssertionError
This commit is contained in:
Родитель
d34c1df98a
Коммит
d43d2cb774
|
@ -1,4 +1,8 @@
|
|||
0.2.0 (unreleased)
|
||||
Unreleased
|
||||
|
||||
- Demote AssertionError to ProtocolExeception in ProtocolUtil#skip() for unknown TType values.
|
||||
|
||||
0.1.1 (released 6 January 2016)
|
||||
------------------
|
||||
|
||||
- Add CompactProtocol implementation
|
||||
|
|
|
@ -23,6 +23,7 @@ import com.bendb.thrifty.protocol.Protocol;
|
|||
import com.bendb.thrifty.protocol.SetMetadata;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.net.ProtocolException;
|
||||
|
||||
public final class ProtocolUtil {
|
||||
private ProtocolUtil() {
|
||||
|
@ -78,7 +79,7 @@ public final class ProtocolUtil {
|
|||
break;
|
||||
|
||||
default:
|
||||
throw new AssertionError("Unrecognized TType value: " + typeCode);
|
||||
throw new ProtocolException("Unrecognized TType value: " + typeCode);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -8,6 +8,7 @@ import okio.ByteString;
|
|||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.net.ProtocolException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.LinkedHashMap;
|
||||
|
@ -16,6 +17,7 @@ import java.util.List;
|
|||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
import static org.hamcrest.CoreMatchers.equalTo;
|
||||
import static org.hamcrest.CoreMatchers.is;
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
|
@ -133,4 +135,26 @@ public class ProtocolUtilTest {
|
|||
|
||||
assertThat(buffer.size(), is(0L));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void throwsProtocolExceptionOnUnknownTTypeValue() throws Exception {
|
||||
Buffer buffer = new Buffer();
|
||||
BinaryProtocol protocol = new BinaryProtocol(buffer, buffer);
|
||||
protocol.writeStructBegin("Test");
|
||||
protocol.writeFieldBegin("num", 1, TType.I32);
|
||||
protocol.writeI32(2);
|
||||
protocol.writeFieldEnd();
|
||||
protocol.writeFieldBegin("invalid_ttype", 2, (byte) 84);
|
||||
protocol.writeString("shouldn't get here");
|
||||
protocol.writeFieldEnd();
|
||||
protocol.writeFieldStop();
|
||||
protocol.writeStructEnd();
|
||||
|
||||
try {
|
||||
ProtocolUtil.skip(protocol, TType.STRUCT);
|
||||
fail();
|
||||
} catch (ProtocolException ignored) {
|
||||
assertThat(ignored.getMessage(), equalTo("Unrecognized TType value: 84"));
|
||||
}
|
||||
}
|
||||
}
|
Загрузка…
Ссылка в новой задаче