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.

Wednesday, August 29, 2012

Fedora: yum-complete-transaction taking forever?

It is possible that it may be in an infinite loop or such. Cleanup your yum transaction as follows:

yum install yum-utils
yum clean all
/usr/sbin/yum-complete-transaction --cleanup-only

Wednesday, August 15, 2012

Fedora: Remove old kernels

Update your system
$ sudo  yum -y update --skip-broken

Now remove old kernels
$ sudo package-cleanup --oldkernels -y

Monday, March 26, 2012

Android Tip: android.view.WindowManager$BadTokenException

If you are using an ActivityGroup to display a series of activities, then you may encounter the infamous BadTokenException.

The location where you are getting the exception, will have a "this" usage for the context.

To get over this error, use "this.getParent()".

Eg:  final ProgressDialog pbarDialog = new ProgressDialog( this.getParent() );
 

Android Tip: Dealing with Droid Spinner Background

Droid seems to have an issue where in the spinner background is white and none of the elements are displayed even though they are available in the spinner.

This error has a workaround at http://stackoverflow.com/questions/4361604/how-to-change-the-spinner-font-color

Friday, March 02, 2012

TIP: Fedora: No packages marked for update

Causes:
1) Your fedora distribution may have been EOL.  No more packages are available. You need to upgrade your version.    OR
2) Your yum cache is out of date and needs a refresh.

$ sudo yum clean expire-cache
$ sudo yum update

Thursday, February 09, 2012

TIP:Lenovo Thinkpad W520 Fedora 16 Internal Mic Not Working

Solution as mentioned in
https://bugzilla.redhat.com/show_bug.cgi?id=752610 is


$ sudo vi /etc/modprobe.d/dist-alsa.conf

Add as the first line.
options snd-hda-intel index=0 model=thinkpad

Then reboot and you should be good to go.


If you are keen on seeing what my file looks like:

# ALSA Sound Support
#
# We want to ensure that snd-seq is always loaded for those who want to use
# the sequencer interface, but we can't do this automatically through udev # at the moment...so we have this rule (just for the moment).
#
# Remove the following line if you don't want the sequencer.

options snd-hda-intel index=0 model=thinkpad

install snd-pcm /sbin/modprobe --ignore-install snd-pcm && /sbin/modprobe snd-seq

Wednesday, January 25, 2012

TIP: Passphraseless SSH on Fedora

If you are trying to set up passphraseless SSH on Fedora, then remember that the permissions on the file authorized_keys should be 644 ====================================================== .ssh$ chmod 644 authorized_keys anil@sadbhav:~/.ssh$ ssh localhost Last login: Sun Jan 22 21:42:06 2012 from localhost anil@sadbhav:~$ exit logout Connection to localhost closed. anil@sadbhav:~/.ssh$ chmod 644 known_hosts ================