remove decode byte file and support unknowexception decode
diff --git a/decode_test.go b/decode_test.go
index 322d9e0..9bfc070 100644
--- a/decode_test.go
+++ b/decode_test.go
@@ -24,7 +24,7 @@
package hessian
import (
- "io/ioutil"
+ "github.com/apache/dubbo-go-hessian2/java_exception"
"log"
"os"
"os/exec"
@@ -32,14 +32,6 @@
"testing"
)
-import (
- "github.com/stretchr/testify/assert"
-)
-
-import (
- "github.com/apache/dubbo-go-hessian2/java_exception"
-)
-
const (
hessianJar = "test_hessian/target/test_hessian-1.0.0.jar"
testString = "hello, world! 你好,世界!"
@@ -118,7 +110,15 @@
if ok {
r = tmp.value.Interface()
}
- if !reflect.DeepEqual(r, expected) {
+ trow, o1 := r.(java_exception.Throwabler)
+ expe, o2 := expected.(java_exception.Throwabler)
+ if o1 && o2 {
+ log.Println(reflect.TypeOf(trow), reflect.TypeOf(trow).Elem().Name())
+ if trow.Error() == expe.Error() && reflect.TypeOf(trow).Elem().Name() == reflect.TypeOf(expe).Elem().Name() {
+ return
+ }
+ t.Errorf("%s: got %v, wanted %v", method, r, expected)
+ } else if !reflect.DeepEqual(r, expected) {
t.Errorf("%s: got %v, wanted %v", method, r, expected)
}
}
@@ -137,27 +137,9 @@
expected(r)
}
-func TestRuntimeException(t *testing.T) {
- // this byte slice in the file is generated by java
- c := getByteFromFile("RuntimeException.txt")
- decoder := NewDecoder(c)
- r, err := decoder.Decode()
- assert.Nil(t, err)
- _, j := r.(*java_exception.RuntimeException)
- assert.True(t, j)
-}
-
-func TestBizException(t *testing.T) {
- // this byte slice in the file is generated by java
- c := getByteFromFile("BizDddException.txt")
- decoder := NewDecoder(c)
- r, err := decoder.Decode()
- assert.Nil(t, err)
- _, j := r.(*UnknownException)
- assert.True(t, j)
-}
-
-func getByteFromFile(fname string) []byte {
- c, _ := ioutil.ReadFile("test_resource/" + fname)
- return c
+func TestUserDefindeException(t *testing.T) {
+ expect := &UnknownException{
+ DetailMessage: "throw UserDefindException",
+ }
+ testDecodeFramework(t, "throw_UserDefindException", expect)
}
diff --git a/test_hessian/src/main/java/test/TestThrowable.java b/test_hessian/src/main/java/test/TestThrowable.java
index 20652ff..3647e67 100644
--- a/test_hessian/src/main/java/test/TestThrowable.java
+++ b/test_hessian/src/main/java/test/TestThrowable.java
@@ -409,4 +409,8 @@
return new AnnotationTypeMismatchException(Override.class.getEnclosingMethod(), "AnnotationTypeMismatchException");
}
+ public static Object throw_UserDefindException() {
+ return new UserDefindException("throw UserDefindException");
+ }
+
}
diff --git a/test_hessian/src/main/java/test/UserDefindException.java b/test_hessian/src/main/java/test/UserDefindException.java
new file mode 100644
index 0000000..26d1db1
--- /dev/null
+++ b/test_hessian/src/main/java/test/UserDefindException.java
@@ -0,0 +1,24 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package test;
+
+public class UserDefindException extends RuntimeException{
+ public UserDefindException(String dd){
+ super(dd);
+ }
+}
\ No newline at end of file
diff --git a/test_resource/BizDddException.txt b/test_resource/BizDddException.txt
deleted file mode 100644
index f06b585..0000000
--- a/test_resource/BizDddException.txt
+++ /dev/null
Binary files differ
diff --git a/test_resource/RuntimeException.txt b/test_resource/RuntimeException.txt
deleted file mode 100644
index 430d269..0000000
--- a/test_resource/RuntimeException.txt
+++ /dev/null
Binary files differ