mardi 8 septembre 2020

Passing Arraylist or collection of different Objects of a class to a generic Method

I am writing a test suite where I have to validate the responses of large number of APIs.All the APIs responses and thier parameters are grouped in one class (Response Class with public clases inside them for parmeters (response1_param,response2_param,response3_param...etc)

Now for different API calls there are different responses but with different parameters.

A--->response1
>>Parse generic_response(g(response1_param))
B---->response2
>>Parse generic_response(g(response2_param)
C---->response3
>>Parse generic_response(g(response3_param))

I want to make a generic method which could parse the list of Parameters corresponding to different response. => basically g method

one way I could think of is to create a variable argument method and pass all the parameters along with the expected response parameters. Other way is to create soem generic response parameter class.

Below is a code snippet for Response class.

public final class Response {
   
  
    public final class response1_param {

      
        public response1_Param1(int value) {
           
        }

          public response1_Param2(int value) {
                  
        }
    }


    public final class response2_param {

      
        public response2_Param1(int value) {
           
        }

          public response2_Param2(int value) {
                  
        }
    }
    
    
        public final class response3_param {
    
          
            public response3_Param1(int value) {
               
            }
    
              public response3_Param2(int value) {
                      
            }
    }

}

Can some one please suggest a good design.

Aucun commentaire:

Enregistrer un commentaire