title: How do i write unit test for function with void return type
body: <p>I am new to writing Unit tests. I saw few examples of jUnit , but they all were for functions returning a value. </p>
  
  <p>I have to write unit test for following method. Also we are using objects and methods in this method not belonging to this class like ConfigParser and ParseConfig. How do i go about writing Unit tests for such menthods? </p>
  
  <pre><code>    @RequestMapping(value = "/generate-json" , consumes = MediaType.APPLICATION_JSON_VALUE, method = RequestMethod.POST)
  @PageType(pageType = "PlaceHolderPageType")
  public void execute(@RequestBody String payload) throws JSONException {
      JSONObject json = new JSONObject(payload);
      JSONObject configJSON = generateJSONSchema(json.toString());
      String capabilityName = (String) configJSON.get(JSONConfigurationConstants.CAPABILITY_NAME);
      String fileLocation = FormInputFieldConstants.JSON_PATH + capabilityName + JSONConfigurationConstants.FILE_EXTENSION;
      //Write JSON file
      try (OutputStreamWriter file  = new OutputStreamWriter(new FileOutputStream(fileLocation), StandardCharsets.UTF_8)) {
          file.write(configJSON.toString());
          file.flush();
          file.close();
      } catch (IOException e) {
          e.printStackTrace();
      }
  
      URI uriSchemaLocation = new File(fileLocation).toURI();
      ConfigParser configParser = new ConfigParser(uriSchemaLocation);
      configParser.parseConfig(TestHelper.getMockedJSONObject(fileLocation));
  }
  </code></pre>