LPS-51439 Prevent over compiling for test-class and test-method

Backport pull at https://github.com/brianchandotcom/liferay-portal-ee/pull/7750