AbstractSerializer implements Serializer { protected SofaRpcException buildSerializeError(String message) { return new SofaRpcException(getErrorCode(true), LogCodes.getLog(LogCodes.ERROR_SERIALIZER, message)); }    }
@Test public void buildSerializeError() { RpcInternalContext old = RpcInternalContext.peekContext(); try { RpcInternalContext.removeContext(); SofaRpcException exception = serializer.buildSerializeError("xx"); Assert.assertEquals(RpcErrorType.UNKNOWN, exception.getErrorType()); RpcInternalContext.getContext().setProviderSide(true); exception = serializer.buildSerializeError("xx"); Assert.assertEquals(RpcErrorType.SERVER_SERIALIZE, exception.getErrorType()); RpcInternalContext.getContext().setProviderSide(false); exception = serializer.buildSerializeError("xx"); Assert.assertEquals(RpcErrorType.CLIENT_SERIALIZE, exception.getErrorType()); RpcInternalContext.removeContext(); exception = serializer.buildSerializeError("xx", new RuntimeException()); Assert.assertEquals(RpcErrorType.UNKNOWN, exception.getErrorType()); RpcInternalContext.getContext().setProviderSide(true); exception = serializer.buildSerializeError("xx", new RuntimeException()); Assert.assertEquals(RpcErrorType.SERVER_SERIALIZE, exception.getErrorType()); RpcInternalContext.getContext().setProviderSide(false); exception = serializer.buildSerializeError("xx", new RuntimeException()); Assert.assertEquals(RpcErrorType.CLIENT_SERIALIZE, exception.getErrorType()); } finally { RpcInternalContext.setContext(old); } }