See if this is helpful:
MoneyHelper is being created, but a previous test or a setup method is not
properly "de-registered" or closed.
The most reliable and recommended way to de-register a static mock is by
using a *try-with-resources* block. This Java feature ensures that the mock
is automatically closed and deregistered at the end of the block,
preventing resource leaks and conflicts.
@Test void myTestThatMocksAStaticMethod() { try
(MockedStatic<MyStaticClass> mockedStatic =
Mockito.mockStatic(MyStaticClass.class))
{ // Here, you define the behavior of the static method
mockedStatic.when(MyStaticClass::someStaticMethod).thenReturn("mocked value"
);
// Your test logic that calls the static method String result =
MyStaticClass.someStaticMethod();
// Assertions assertEquals("mocked value", result); }
// The mock is automatically closed and deregistered here }
On Thu, Aug 21, 2025 at 5:33 PM Adam Monsen <[email protected]> wrote:
> Hi all, I'd love some help making my tests run locally. I've got a
> confusing and consistent failure.
>
> I'm trying to recreate more or less what appears in
> .github/workflows/build-postgresql.yml , but without the matrix/sharding.
> I'm standing up a postgres db and mock oauth2 server, then running the
> following:
>
> gradle createPGDB -PdbName=fineract_tenants
>
> gradle createPGDB -PdbName=fineract_default
>
> gradle --no-continue test -PdbType=postgresql -x checkstyleJmh -x
> checkstyleMain -x checkstyleTest -x spotlessCheck -x spotlessApply -x
> spotbugsMain -x spotbugsTest -x javadoc -x javadocJar -x modernizer -x
> :twofactor-tests:test -x :oauth2-test:test -x
> :fineract-e2e-tests-runner:test
>
> I've been using something close to this for months now without issues, but
> since about a week ago I've started getting a MockitoException. I ran it
> just now and got: 420 tests, 1 failures, 0 ignored, 47.916s duration.
> Failed tests: RepaymentPeriodTest. initializationError
>
> full results: https://adammonsen.com/tmp/2025-08-21-001-gradle-test/
>
> Any ideas?
>
--
--
Paul