-
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.
Merge pull request #237 from zhangymPerson/java8_time_support
add catch user defined exceptions. #208
- Loading branch information
Showing
5 changed files
with
167 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" | ||
) | ||
|
||
// Java8TimeYear is test java8 java.time.Year | ||
func Java8TimeYear() []byte { | ||
e := hessian.NewEncoder() | ||
year := java8_time.Year{Year: 2020} | ||
e.Encode(year) | ||
return e.Buffer() | ||
} | ||
|
||
// Java8LocalDate is 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,31 @@ | ||
/* | ||
* 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" | ||
) | ||
|
||
// JavaException is 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,46 @@ | ||
/* | ||
* 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"); | ||
// assertEquals don't compare Exception object | ||
if (javaException instanceof Exception) { | ||
Assert.assertEquals(exception.getMessage(), ((Exception) javaException).getMessage()); | ||
} | ||
} | ||
|
||
} |