If you cannot use external APIs or dont want to, you can still use pure standard JDK API to access private methods using reflection. Here is an example

    MyObject obj = new MyObject();
    Method privateMethod = MyObject.class.getDeclaredMethod("getFoo", null);
    privateMethod.setAccessible(true);
    String returnValue = (String) privateMethod.invoke(obj, null);
    System.out.println("returnValue = " + returnValue);

Check Java Tutorial [http://docs.oracle.com/javase/tutorial/reflect/][1] or Java API [http://docs.oracle.com/javase/7/docs/api/java/lang/reflect/package-summary.html][2] for more information.

As @kij cited on his answer there are times when a simple solution using reflection is really good to test a private method.


  [1]: http://docs.oracle.com/javase/tutorial/reflect/
  [2]: http://docs.oracle.com/javase/7/docs/api/java/lang/reflect/package-summary.html