    @Test
    public void saveHoldingsTest() throws IOException {


        // define mocks
        Client client = mock(Client.class);
        User user = mock(User.class);
        UserProfile userProfile = mock(UserProfile.class);
        Principal principal = mock(Principal.class);

        // define behaviour
        String username = "joe.coder@example.com";
        when(principal.getName()).thenReturn(username);
        when(client.getUser(username)).thenReturn(user);
        when(user.getProfile()).thenReturn(userProfile);

        // test the controller
        Holding[] inputHoldings = new Holding[] {
                new Holding()
                    .setCrypto("crypto1")
                    .setCurrency("currency1")
                    .setAmount("amount1"),
                new Holding()
                    .setCrypto("crypto2")
                    .setCurrency("currency2")
                    .setAmount("amount2")
        };

        HoldingsController holdingsController = new HoldingsController(client);
        Holding[] outputHoldings = holdingsController.saveHoldings(inputHoldings, principal);

        //////////////////////
        // Validate Results //
        //////////////////////

        // make sure the input array is the same as the output array
        assertThat(outputHoldings, is(inputHoldings));

        // verify mock interactions
        ArgumentCaptor<String> holdingsJsonCaptor = ArgumentCaptor.forClass(String.class);
        verify(userProfile).put(eq("holdings"), holdingsJsonCaptor.capture());
        verify(user).update();

        // validate the json
        JsonNode holdingsParsed = new ObjectMapper().readTree(holdingsJsonCaptor.getValue());
        assertThat(holdingsParsed, jsonArray(contains(
                jsonObject()
                    .where("crypto", jsonText("crypto1"))
                    .where("currency", jsonText("currency1"))
                    .where("amount", jsonText("amount1")),
                jsonObject()
                    .where("crypto", jsonText("crypto2"))
                    .where("currency", jsonText("currency2"))
                    .where("amount", jsonText("amount2"))
        )));
    }