@@ -35,15 +35,35 @@ public final class SerializableErrorTest {
3535    private  static  final  ObjectMapper  mapper  = ObjectMappers .newServerObjectMapper ();
3636
3737    @ Test 
38-     public  void  testExceptionToError () {
38+     public  void  forException_should_keep_both_safe_and_unsafe_args () {
3939        ErrorType  error  = ErrorType .FAILED_PRECONDITION ;
40-         ServiceException  exception  =
41-                 new  ServiceException (error , SafeArg .of ("safeKey" , 42 ), UnsafeArg .of ("foo" , "bar" ));
40+         ServiceException  exception  = new  ServiceException (error ,
41+                 SafeArg .of ("safeKey" , 42 ),
42+                 UnsafeArg .of ("sensitiveInfo" , "some user-entered content" ));
43+ 
4244        SerializableError  expected  = new  SerializableError .Builder ()
4345                .errorCode (error .code ().name ())
4446                .errorName (error .name ())
4547                .errorInstanceId (exception .getErrorInstanceId ())
4648                .putParameters ("safeKey" , "42" )
49+                 .putParameters ("sensitiveInfo" , "some user-entered content" )
50+                 .build ();
51+         assertThat (SerializableError .forException (exception )).isEqualTo (expected );
52+     }
53+ 
54+     @ Test 
55+     public  void  forException_arg_key_collisions_just_use_the_last_one () {
56+         ErrorType  error  = ErrorType .INTERNAL ;
57+         ServiceException  exception  = new  ServiceException (
58+                 error ,
59+                 SafeArg .of ("collision" , "first" ),
60+                 UnsafeArg .of ("collision" , "second" ));
61+ 
62+         SerializableError  expected  = new  SerializableError .Builder ()
63+                 .errorCode (error .code ().name ())
64+                 .errorName (error .name ())
65+                 .errorInstanceId (exception .getErrorInstanceId ())
66+                 .putParameters ("collision" , "second" )
4767                .build ();
4868        assertThat (SerializableError .forException (exception )).isEqualTo (expected );
4969    }
0 commit comments