Repository: apache/dubbo-go-hessian2
Pull request #234 (2020-09-08 04:09:26)

fix fields name mismatch in Duration class



**What this PR does**:

1. fix fields name mismatch in Duration class: it should be "seconds/nanos", not "second/nano"
2. improve the test data for better verification: don't use "0" for int field, because event it dismatch the actual field, it still will be "0" because of the default value is "0" for int.
3. improve other test data

**Which issue(s) this PR fixes**:
<!--
*Automatically closes linked issue when PR is merged.
Usage: `Fixes #<issue number>`, or `Fixes (paste link of issue)`.
_If PR is about `failing-tests or flakes`, please post the related issues/tests in a comment and do not use `Fixes`_*
-->
Fixes #

**Special notes for your reviewer**:

**Does this PR introduce a user-facing change?**:
<!--
If no, just write "NONE" in the release-note block below.
If yes, a release note is required:
Enter your extended release note in the block below. If the PR requires additional action from users switching to the new release, include the string "action required".
-->
```release-note

```


Patch:
diff --git a/java8_time.go b/java8_time.go
index 6d5283f..2b80121 100644
--- a/java8_time.go
+++ b/java8_time.go
@@ -24,16 +24,16 @@ import (
 func init() {
 	RegisterPOJO(&java8_time.Year{Year: 2020})
 	RegisterPOJO(&java8_time.YearMonth{Month: 2020, Year: 6})
-	RegisterPOJO(&java8_time.Period{Years: 2020, Months: 6, Days: 6})
-	RegisterPOJO(&java8_time.LocalDate{Year: 2020, Month: 6, Day: 6})
-	RegisterPOJO(&java8_time.LocalTime{Hour: 6, Minute: 6, Second: 0, Nano: 0})
-	RegisterPOJO(&java8_time.LocalDateTime{Date: java8_time.LocalDate{Year: 2020, Month: 6, Day: 6}, Time: java8_time.LocalTime{Hour: 6, Minute: 6, Second: 6, Nano: 6}})
-	RegisterPOJO(&java8_time.MonthDay{Month: 6, Day: 6})
-	RegisterPOJO(&java8_time.Duration{Second: 0, Nano: 0})
-	RegisterPOJO(&java8_time.Instant{Seconds: 100, Nanos: 0})
-	RegisterPOJO(&java8_time.ZoneOffSet{Seconds: 0})
-	RegisterPOJO(&java8_time.OffsetDateTime{DateTime: java8_time.LocalDateTime{Date: java8_time.LocalDate{Year: 2020, Month: 6, Day: 6}, Time: java8_time.LocalTime{Hour: 6, Minute: 6, Second: 6, Nano: 6}}, Offset: java8_time.ZoneOffSet{Seconds: -64800}})
-	RegisterPOJO(&java8_time.OffsetTime{LocalTime: java8_time.LocalTime{Hour: 6, Minute: 6, Second: 6, Nano: 6}, ZoneOffset: java8_time.ZoneOffSet{Seconds: -64800}})
-	RegisterPOJO(&java8_time.ZonedDateTime{DateTime: java8_time.LocalDateTime{Date: java8_time.LocalDate{Year: 2020, Month: 6, Day: 6}, Time: java8_time.LocalTime{Hour: 6, Minute: 6, Second: 6, Nano: 6}}, Offset: java8_time.ZoneOffSet{Seconds: 0}, ZoneId: "Z"})
+	RegisterPOJO(&java8_time.Period{Years: 2020, Months: 6, Days: 16})
+	RegisterPOJO(&java8_time.LocalDate{Year: 2020, Month: 6, Day: 16})
+	RegisterPOJO(&java8_time.LocalTime{Hour: 6, Minute: 5, Second: 4, Nano: 3})
+	RegisterPOJO(&java8_time.LocalDateTime{Date: java8_time.LocalDate{Year: 2020, Month: 6, Day: 16}, Time: java8_time.LocalTime{Hour: 6, Minute: 5, Second: 4, Nano: 3}})
+	RegisterPOJO(&java8_time.MonthDay{Month: 6, Day: 16})
+	RegisterPOJO(&java8_time.Duration{Seconds: 30, Nanos: 10})
+	RegisterPOJO(&java8_time.Instant{Seconds: 100, Nanos: 10})
+	RegisterPOJO(&java8_time.ZoneOffSet{Seconds: 7200})
+	RegisterPOJO(&java8_time.OffsetDateTime{DateTime: java8_time.LocalDateTime{Date: java8_time.LocalDate{Year: 2020, Month: 6, Day: 16}, Time: java8_time.LocalTime{Hour: 6, Minute: 5, Second: 4, Nano: 3}}, Offset: java8_time.ZoneOffSet{Seconds: 7200}})
+	RegisterPOJO(&java8_time.OffsetTime{LocalTime: java8_time.LocalTime{Hour: 6, Minute: 5, Second: 4, Nano: 3}, ZoneOffset: java8_time.ZoneOffSet{Seconds: 7200}})
+	RegisterPOJO(&java8_time.ZonedDateTime{DateTime: java8_time.LocalDateTime{Date: java8_time.LocalDate{Year: 2020, Month: 6, Day: 16}, Time: java8_time.LocalTime{Hour: 6, Minute: 5, Second: 4, Nano: 3}}, Offset: java8_time.ZoneOffSet{Seconds: 7200}, ZoneId: "Z"})
 
 }
diff --git a/java8_time/duration.go b/java8_time/duration.go
index ee01d54..971a0ea 100644
--- a/java8_time/duration.go
+++ b/java8_time/duration.go
@@ -18,8 +18,8 @@
 package java8_time
 
 type Duration struct {
-	Second int64 `hessian:"second"`
-	Nano   int32 `hessian:"nano"`
+	Seconds int64 `hessian:"seconds"`
+	Nanos   int32 `hessian:"nanos"`
 }
 
 func (Duration) JavaClassName() string {


Test patch:
diff --git a/java8_time_test.go b/java8_time_test.go
index d9d5985..9529c95 100644
--- a/java8_time_test.go
+++ b/java8_time_test.go
@@ -24,18 +24,18 @@ import (
 
 func TestJava8Time(t *testing.T) {
 	doTestTime(t, "java8_Year", &java8_time.Year{Year: 2020})
-	doTestTime(t, "java8_LocalDate", &java8_time.LocalDate{Year: 2020, Month: 6, Day: 6})
-	doTestTime(t, "java8_LocalTime", &java8_time.LocalTime{Hour: 6, Minute: 6})
-	doTestTime(t, "java8_LocalDateTime", &java8_time.LocalDateTime{Date: java8_time.LocalDate{Year: 2020, Month: 6, Day: 6}, Time: java8_time.LocalTime{Hour: 6, Minute: 6, Second: 6, Nano: 6}})
-	doTestTime(t, "java8_MonthDay", &java8_time.MonthDay{Month: 6, Day: 6})
-	doTestTime(t, "java8_Duration", &java8_time.Duration{Second: 0, Nano: 0})
-	doTestTime(t, "java8_Instant", &java8_time.Instant{Seconds: 100, Nanos: 0})
+	doTestTime(t, "java8_LocalDate", &java8_time.LocalDate{Year: 2020, Month: 6, Day: 16})
+	doTestTime(t, "java8_LocalTime", &java8_time.LocalTime{Hour: 6, Minute: 16})
+	doTestTime(t, "java8_LocalDateTime", &java8_time.LocalDateTime{Date: java8_time.LocalDate{Year: 2020, Month: 6, Day: 16}, Time: java8_time.LocalTime{Hour: 6, Minute: 5, Second: 4, Nano: 3}})
+	doTestTime(t, "java8_MonthDay", &java8_time.MonthDay{Month: 6, Day: 16})
+	doTestTime(t, "java8_Duration", &java8_time.Duration{Seconds: 30, Nanos: 10})
+	doTestTime(t, "java8_Instant", &java8_time.Instant{Seconds: 100, Nanos: 10})
 	doTestTime(t, "java8_YearMonth", &java8_time.YearMonth{Year: 2020, Month: 6})
-	doTestTime(t, "java8_Period", &java8_time.Period{Years: 2020, Months: 6, Days: 6})
-	doTestTime(t, "java8_ZoneOffset", &java8_time.ZoneOffSet{Seconds: 0})
-	doTestTime(t, "java8_OffsetDateTime", &java8_time.OffsetDateTime{DateTime: java8_time.LocalDateTime{Date: java8_time.LocalDate{Year: 2020, Month: 6, Day: 6}, Time: java8_time.LocalTime{Hour: 6, Minute: 6, Second: 6, Nano: 6}}, Offset: java8_time.ZoneOffSet{Seconds: -64800}})
-	doTestTime(t, "java8_OffsetTime", &java8_time.OffsetTime{LocalTime: java8_time.LocalTime{Hour: 6, Minute: 6, Second: 6, Nano: 6}, ZoneOffset: java8_time.ZoneOffSet{Seconds: -64800}})
-	doTestTime(t, "java8_ZonedDateTime", &java8_time.ZonedDateTime{DateTime: java8_time.LocalDateTime{Date: java8_time.LocalDate{Year: 2020, Month: 6, Day: 6}, Time: java8_time.LocalTime{Hour: 6, Minute: 6, Second: 6, Nano: 6}}, Offset: java8_time.ZoneOffSet{Seconds: 0}, ZoneId: "Z"})
+	doTestTime(t, "java8_Period", &java8_time.Period{Years: 2020, Months: 6, Days: 16})
+	doTestTime(t, "java8_ZoneOffset", &java8_time.ZoneOffSet{Seconds: 7200})
+	doTestTime(t, "java8_OffsetDateTime", &java8_time.OffsetDateTime{DateTime: java8_time.LocalDateTime{Date: java8_time.LocalDate{Year: 2020, Month: 6, Day: 16}, Time: java8_time.LocalTime{Hour: 6, Minute: 5, Second: 4, Nano: 3}}, Offset: java8_time.ZoneOffSet{Seconds: 7200}})
+	doTestTime(t, "java8_OffsetTime", &java8_time.OffsetTime{LocalTime: java8_time.LocalTime{Hour: 6, Minute: 5, Second: 4, Nano: 3}, ZoneOffset: java8_time.ZoneOffSet{Seconds: 7200}})
+	doTestTime(t, "java8_ZonedDateTime", &java8_time.ZonedDateTime{DateTime: java8_time.LocalDateTime{Date: java8_time.LocalDate{Year: 2020, Month: 6, Day: 16}, Time: java8_time.LocalTime{Hour: 6, Minute: 5, Second: 4, Nano: 3}}, Offset: java8_time.ZoneOffSet{Seconds: 0}, ZoneId: "Z"})
 }
 
 func doTestTime(t *testing.T, method string, expected interface{}) {
diff --git a/test_hessian/src/main/java/test/TestJava8Time.java b/test_hessian/src/main/java/test/TestJava8Time.java
index 779fe5e..35dc521 100644
--- a/test_hessian/src/main/java/test/TestJava8Time.java
+++ b/test_hessian/src/main/java/test/TestJava8Time.java
@@ -22,39 +22,39 @@ import java.time.*;
 public class TestJava8Time {
 
     public static Duration java8_Duration() {
-        return Duration.ZERO;
+        return Duration.ofSeconds(30, 10);
     }
 
     public static Instant java8_Instant() {
-        return Instant.ofEpochMilli(100000L);
+        return Instant.ofEpochSecond(100, 10);
     }
 
     public static LocalDate java8_LocalDate() {
-        return LocalDate.of(2020, 6, 6);
+        return LocalDate.of(2020, 6, 16);
     }
 
     public static LocalDateTime java8_LocalDateTime() {
-        return LocalDateTime.of(2020, 6, 6, 6, 6, 6, 6);
+        return LocalDateTime.of(2020, 6, 16, 6, 5, 4, 3);
     }
 
     public static LocalTime java8_LocalTime() {
-        return LocalTime.of(6, 6);
+        return LocalTime.of(6, 16);
     }
 
     public static MonthDay java8_MonthDay() {
-        return MonthDay.of(6, 6);
+        return MonthDay.of(6, 16);
     }
 
     public static OffsetDateTime java8_OffsetDateTime() {
-        return OffsetDateTime.of(2020, 6, 6, 6, 6, 6, 6, ZoneOffset.MIN);
+        return OffsetDateTime.of(2020, 6, 16, 6, 5, 4, 3, java8_ZoneOffset());
     }
 
     public static OffsetTime java8_OffsetTime() {
-        return OffsetTime.of(6, 6, 6, 6, ZoneOffset.MIN);
+        return OffsetTime.of(6, 5, 4, 3, java8_ZoneOffset());
     }
 
     public static Period java8_Period() {
-        return Period.of(2020, 6, 6);
+        return Period.of(2020, 6, 16);
     }
 
     public static Year java8_Year() {
@@ -75,7 +75,7 @@ public class TestJava8Time {
     }
 
     public static ZoneOffset java8_ZoneOffset() {
-        return ZoneOffset.of("Z");
+        return ZoneOffset.ofHours(2);
     }
 
 }