'JSON path with big decimal Expected: is <1000> but: was <1000>

My test with Junit5 doesn't pass.

JSON path "$.balance" Expected: is <1000> but: was <1000>

I used the tree following modes. First one is the method that returns the initial error.

Other two Java complains with "cannot cast from BigDecimal to Integer".

Where is my wrong?

BigDecimal balance = new BigDecimal(1000);
        
when(bankAccountTransactionsService.balance()).thenReturn(balance);
        
mvc.perform(get("/api/v1/balance")).andExpect(status().isOk())
                .andExpect(jsonPath("$.balance", Matchers.comparesEqualTo(bankAccountTransactionsService.balance())));
mvc.perform(get("/api/v1/balance")).andExpect(status().isOk())
                .andExpect(jsonPath("$.balance", Matchers.comparesEqualTo(balance)));
mvc.perform(get("/api/v1/balance")).andExpect(status().isOk())
                .andExpect(jsonPath("$.balance", is(balance)));


Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source