How to check that an exception is not thrown using mockito?

If you are using Mockito 5.2 or later then you're able to use assertDoesNotThrow

Assertions.assertDoesNotThrow(() -> myClass.getBalanceForPerson(person1););

Fail the test if an exception is caught.

@Test
public void testGetBalanceForPerson() {

   // creating mock person
   Person person1 = mock(Person.class);
   when(person1.getId()).thenReturn("mockedId");

   // calling method under test
   try {
      myClass.getBalanceForPerson(person1);
   } catch(Exception e) {
      fail("Should not have thrown any exception");
   }
}

As long as you are not explicitly stating, that you are expecting an exception, JUnit will automatically fail any Tests that threw uncaught Exceptions.

For example the following test will fail:

@Test
public void exampleTest(){
    throw new RuntimeException();
}

If you further want to check, that the test will fail on Exception, you could simply add a throw new RuntimeException(); into the method you want to test, run your tests and check if they failed.

When you are not manually catching the exception and failing the test, JUnit will include the full stack trace in the failure message, which allows you to quickly find the source of the exception.