-1

I have 5 strings "a,b,c,d,e" in a drop down,i am writing a testcase where i am checking if the user has selected any of the five then insert into DB,currently i am not getting any of the values from client side,so it has to be written in a junit if the user has selected any of these values then return true .

current approach: 1st method having 'a' data JSONObject obj=new JSONObject(); obj.put("DT",a);

2nd method having 'b' data JSONObject obj=new JSONObject(); obj.put("DT",b);

and so on for furthur values.which is creating more number of methods.I need to insert all the values in a single method.

Thanks

sheetal
  • 227
  • 1
  • 2
  • 4

1 Answers1

2

I'm a bit confused as to what you're actually struggling with. Are you just looking for a helper method to do this?

public static JSONObject createAndPopulateObject(String data) {
  JSONObject obj = new JSONObject();
  obj.put("DT", data);
  return obj;
}

//...
aObj = createAndPopulateObject("a");
bObj = createAndPopulateObject("b");
Mark Peters
  • 80,126
  • 17
  • 159
  • 190