title: How do you unit test main method in Java?
body: <p>This is my class with main function. Here I initialize a spring bean which has camel route in it. I do not want to test any other classes being referred in this code but I just want to increate code coverage of this main class. How do I mock and test this class?</p>
  
  <pre><code>import org.apache.camel.main.Main;
  public class ABC{
  public static void main(String[] args) {
  
          Main main = new Main();
          MyCamelRoute myCamelRoute = SpringUtil.getBean(MyCamelRoute.class);
          main.addRouteBuilder(myCamelRoute);
  
          Thread t = new Thread(() -&gt; {
              try {
                  main.run();
              } catch (Exception e) {
                  _logger.error("Unable to add route", e);
              }
          }, "started route");
  
          t.start();  
      }
  }
  </code></pre>