Need help writing unit test for the method

Viewed 35

Generates random Id based on conditions. generateId() generates random 8 character length ID. Can anyone help we write unit tests for the code below. I wanted to test out the all the blocks of the recursive function. I wanted to use Mockito and Junit framework. Any idea would be helpful too.

featureManager.isOn(someFeature) returns a boolean if a given feature is live.

  public String getId(String pId) {
    String Id = generateId();
    if (featureManager.isOn(someFeature)) {
      NotificationUnion notificationUnion = GraphQlProxy
          .getId(fId);
      if (notificationUnion.getCid() == null
          || notificationUnion.getId() == null) {
        return callDataApi(id, pId);
      } else {
        return getId(pId);
      }
    } else {
      return callDataApi(id, pId);
    }
  }

  private String callDataApi(String id, String pId) {

    Model model = dataDi
        .getByAttributes(id, pId);
    if (model.getCiD() != null) {
      return getId(pId);
    }
   return id;
}
0 Answers
Related