-
Notifications
You must be signed in to change notification settings - Fork 114
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add catch user defined exceptions. #208
- Loading branch information
1 parent
db1ea9a
commit 7c8f746
Showing
5 changed files
with
169 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
/* | ||
* 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 testfuncs | ||
|
||
import ( | ||
hessian "github.com/apache/dubbo-go-hessian2" | ||
"github.com/apache/dubbo-go-hessian2/java8_time" | ||
) | ||
|
||
// test java8 java.time.Year | ||
func Java8TimeYear() []byte { | ||
e := hessian.NewEncoder() | ||
year := java8_time.Year{Year: 2020} | ||
e.Encode(year) | ||
return e.Buffer() | ||
} | ||
|
||
// test java8 java.time.LocalDate | ||
func Java8LocalDate() []byte { | ||
e := hessian.NewEncoder() | ||
date := java8_time.LocalDate{Year: 2020, Month: 9, Day: 12} | ||
e.Encode(date) | ||
return e.Buffer() | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
/* | ||
* 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 testfuncs | ||
|
||
import ( | ||
hessian "github.com/apache/dubbo-go-hessian2" | ||
"github.com/apache/dubbo-go-hessian2/java_exception" | ||
) | ||
|
||
// test java Exception | ||
func JavaException() []byte { | ||
e := hessian.NewEncoder() | ||
exception := java_exception.NewException("java_exception") | ||
e.Encode(exception) | ||
return e.Buffer() | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
/* | ||
* 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 unit; | ||
|
||
import junit.framework.Assert; | ||
import org.junit.Test; | ||
|
||
import java.time.LocalDate; | ||
import java.time.Year; | ||
|
||
/** | ||
* date 2020/9/12 11:09 <br/> | ||
* description class <br/> | ||
* test java8 | ||
* | ||
* @author [email protected] | ||
* @version 1.0 | ||
* @since 1.0 | ||
*/ | ||
public class GoJava8TimeTest { | ||
|
||
/** | ||
* test java8 java.time.* object and go java8_time/* struct | ||
*/ | ||
@Test | ||
public void testJava8Year() { | ||
Year year = Year.of(2020); | ||
Assert.assertEquals(year | ||
, GoTestUtil.readGoObject("Java8TimeYear")); | ||
LocalDate localDate = LocalDate.of(2020, 9, 12); | ||
Assert.assertEquals(localDate, GoTestUtil.readGoObject("Java8LocalDate")); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
/* | ||
* 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 unit; | ||
|
||
import junit.framework.Assert; | ||
import org.junit.Test; | ||
|
||
/** | ||
* date 2020/9/12 11:09 <br/> | ||
* description class <br/> | ||
* test java8 | ||
* | ||
* @author [email protected] | ||
* @version 1.0 | ||
* @since 1.0 | ||
*/ | ||
public class GoJavaExceptionTest { | ||
|
||
/** | ||
* test java java.lang.Exception object and go java_exception Exception struct | ||
*/ | ||
@Test | ||
public void testException() { | ||
Exception exception = new Exception("java_exception"); | ||
Object javaException = GoTestUtil.readGoObject("JavaException"); | ||
if (javaException instanceof Exception) { | ||
Assert.assertEquals(exception.getMessage(), ((Exception) javaException).getMessage()); | ||
} | ||
// assertEquals don't compare Exception object | ||
// Exception exception2 = new Exception("java_exception"); | ||
// Assert.assertEquals(exception, exception2); | ||
// Assert.assertEquals(exception, GoTestUtil.readGoObject("JavaException")); | ||
} | ||
|
||
} |