Instead of trying to test private methods, how about pulling out a new class where that private method behavior becomes part of the public API of that class? I often feel like Java developers are afraid to create new classes, when they should be creating them much more freely.
Extracting a new Class is straightforward if you use @intellijidea's refactorings to:

* Extract Method (isolate the behavior)
* Introduce Parameter (not always needed)
* Move Instance Method (so powerful!)

The resulting class is sooo much easier to test.
Move Instance Method is so powerful, which means it can also be confusing, so I cover this one in a bit of detail in my "Make Your Code More Testable" online course.

The next MYCMT class is coming in a few weeks, use "twontime" to save 20%!

https://ti.to/jitterted/make-your-code-more-testable-21mar08/discount/twontime
You can follow @jitterted.
Tip: mention @twtextapp on a Twitter thread with the keyword “unroll” to get a link to it.

Latest Threads Unrolled:

By continuing to use the site, you are consenting to the use of cookies as explained in our Cookie Policy to improve your experience.