Copilot commented on code in PR #3378:
URL: https://github.com/apache/dubbo-go/pull/3378#discussion_r3384842329


##########
protocol/dubbo/hessian2/hessian_response_test.go:
##########
@@ -205,6 +208,180 @@ func TestIsSupportResponseAttachmentConcurrent(t 
*testing.T) {
        wg.Wait()
 }
 
+func TestToGenericExceptionUsesHessianExceptionType(t *testing.T) {
+       exception, ok := 
ToGenericException(java_exception.DubboGenericException{
+               ExceptionClass:   "com.example.UserNotFoundException",
+               ExceptionMessage: "user not found",
+       })
+
+       require.True(t, ok)
+       require.IsType(t, &java_exception.DubboGenericException{}, exception)
+       assert.Equal(t, "com.example.UserNotFoundException", 
exception.ExceptionClass)
+       assert.Equal(t, "user not found", exception.ExceptionMessage)
+}
+
+func TestToGenericExceptionConversions(t *testing.T) {
+       pointerException := 
java_exception.NewDubboGenericException("com.example.PointerException", 
"pointer message")
+
+       tests := []struct {
+               name             string
+               input            any
+               wantOK           bool
+               wantClass        string
+               wantMessage      string
+               wantDetailString string
+       }{
+               {
+                       name:        "generic exception pointer",
+                       input:       pointerException,
+                       wantOK:      true,
+                       wantClass:   "com.example.PointerException",
+                       wantMessage: "pointer message",
+               },
+               {
+                       name:             "throwable",
+                       input:            
java_exception.NewThrowable("throwable message"),
+                       wantOK:           true,
+                       wantClass:        "java.lang.Throwable",
+                       wantMessage:      "throwable message",
+                       wantDetailString: "java exception: java.lang.Throwable 
- throwable message",
+               },
+               {
+                       name:             "legacy exception string",
+                       input:            "java exception: user not found",
+                       wantOK:           true,
+                       wantClass:        "java.lang.Exception",
+                       wantMessage:      "user not found",
+                       wantDetailString: "java exception: java.lang.Exception 
- user not found",
+               },
+               {
+                       name:             "plain string",
+                       input:            "plain failure",
+                       wantOK:           true,
+                       wantClass:        "java.lang.Exception",
+                       wantMessage:      "plain failure",
+                       wantDetailString: "java exception: java.lang.Exception 
- plain failure",
+               },
+               {
+                       name:   "unsupported type",
+                       input:  42,
+                       wantOK: false,
+               },
+       }
+
+       for _, test := range tests {
+               t.Run(test.name, func(t *testing.T) {
+                       exception, ok := ToGenericException(test.input)
+                       assert.Equal(t, test.wantOK, ok)
+                       if !test.wantOK {
+                               assert.Nil(t, exception)
+                               return
+                       }
+
+                       require.NotNil(t, exception)
+                       assert.Equal(t, test.wantClass, 
exception.ExceptionClass)
+                       assert.Equal(t, test.wantMessage, 
exception.ExceptionMessage)
+                       assert.Equal(t, test.wantDetailString, 
exception.Error())
+               })

Review Comment:
   In TestToGenericExceptionConversions, the "generic exception pointer" case 
leaves wantDetailString unset, but the loop unconditionally asserts 
exception.Error() equals wantDetailString. This makes the test assert Error() 
== "" for that case, which is very likely unintended and can cause a failing 
test or a meaningless assertion.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to