Tuesday, September 11, 2012

Mockito return the value from the response

An example:
private HttpServletRequest request = mock(HttpServletRequest.class);
    private HttpServletResponse response = mock(HttpServletResponse.class);

    @Test
    public void testAuthz() throws Exception {
        AuthorizationEndpoint endpoint = new AuthorizationEndpoint();
        when(request.getParameter("response_type")).thenReturn(ResponseType.CODE.toString());
        when(request.getParameter("client_id")).thenReturn("test_id");
        when(request.getParameter("redirect_uri")).thenReturn("http://localhost");

        final ArrayList values = new ArrayList();
        doAnswer(new Answer() {
            @Override
            public Object answer(InvocationOnMock invocation) throws Throwable {
                String temp = (String) invocation.getArguments()[0];
                values.add(temp);
                return null;
            }
        }).when(response).sendRedirect(anyString());

        httpRequest("GET", "/authorization");

        endpoint.service(request, response);

        String redirectURL = values.get(0);

        URL url = new URL(redirectURL);
        String fragment = url.toURI().getQuery();
        Map map = OAuthUtils.decodeForm(fragment);

        assertNotNull(map.get(OAuth.OAUTH_CODE));
    }

    private void httpRequest(String method, String pathInfo) {
        when(request.getMethod()).thenReturn(method);
        when(request.getPathInfo()).thenReturn(pathInfo);
    }

Monday, September 10, 2012

Fedora: Skype Issue: libXv.so.1: cannot open


If you try to run skype and get the following error
skype: error while loading shared libraries: libXv.so.1: cannot open

$>sudo yum install alsa-lib.i686 libXv.i686 libXScrnSaver.i686 qt.i686 qt-x11.i686

Wednesday, September 05, 2012

Eclipse Heap Settings on Mac

Locating the eclipse.ini is tricky on a mac.

To locate it, right-click on the Eclipse Application icon and select "Show Package Contents", then double-click on the "Contents" folder and then double-click on the "MacOS" folder, the home of eclipse.ini

You can use Applications->Text Edit to change the eclipse.ini file. :)

Usually you want to adjust the heap settings.