fix review issue and add more test
diff --git a/decode_test.go b/decode_test.go
index 3728fec..b620ce8 100644
--- a/decode_test.go
+++ b/decode_test.go
@@ -24,6 +24,9 @@
package hessian
import (
+ "github.com/apache/dubbo-go-hessian2/java_exception"
+ "github.com/stretchr/testify/assert"
+ "io/ioutil"
"log"
"os"
"os/exec"
@@ -127,3 +130,28 @@
}
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
+}
diff --git a/java_unknown_exception.go b/java_unknown_exception.go
index 45f5a00..6787e3c 100644
--- a/java_unknown_exception.go
+++ b/java_unknown_exception.go
@@ -45,11 +45,11 @@
}
// if have these 4 fields, it is throwable struct
if count == 4 {
+ mutex.Lock()
+ defer mutex.Unlock()
if throwable, ok = getStructInfo(cls.javaName); ok {
return throwable, true
}
- mutex.Lock()
- defer mutex.Unlock()
RegisterPOJO(newBizException(cls.javaName))
if throwable, ok = getStructInfo(cls.javaName); ok {
return throwable, true
diff --git a/test_resource/BizDddException.txt b/test_resource/BizDddException.txt
new file mode 100644
index 0000000..f06b585
--- /dev/null
+++ b/test_resource/BizDddException.txt
Binary files differ
diff --git a/test_resource/RuntimeException.txt b/test_resource/RuntimeException.txt
new file mode 100644
index 0000000..430d269
--- /dev/null
+++ b/test_resource/RuntimeException.txt
Binary files differ