Code example for JSONObject

Methods: getString

0
    @Test 
    public void getJsonParameterRegressionTest() { 
        when(request.getParameter("test")).thenReturn("{\"foo\":\"bar\"}");
 
        JSONObject o = SUT.wrapGetJsonParameter(request, "test");
        Assert.assertNotNull(o);
        try { 
            Assert.assertEquals("bar", o.getString("foo"));
        } catch (JSONException e) {
            Assert.fail();
        } 
 
        verify(request, times(1)).getParameter("test");
    } 
 
    @Test 
    public void getJsonParameterWithMalformedJson() { 
        when(request.getParameter("test")).thenReturn("brokenJSON");
 
        try { 
            Assert.assertNull(SUT.wrapGetJsonParameter(request, "test"));