Finding the right Mockito import

I really enjoy working with Mockito, it’s a fantastic mocking framework for Java. However it can be a pain sometimes to know which packages to import for the tests you are writing.

A quick tip is to import everything while writing your tests & mocks like this:

import static org.junit.Assert.*;
import static org.mockito.Mockito.*;
import static org.mockito.Matchers.*;

Then once you have completed writing your tests use the CTRL+SHIFT+O (it’s CMD+SHIFT+O on Mac) shortcut in Eclipse to breakdown your imported packages to what you actually used.

You’ll end up with something like this:

import static org.mockito.Mockito.doThrow;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
import static org.mockito.Matchers.anyString;

Much easier yeah?🙂

Source: Finding import static statements for Mockito constructs

Change passwords on other accounts using Terminal

In work I have multiple accounts with security requirements making me change the passwords every 90 days. Normally with Windows I used to use CTRL+ALT+DEL and select the change password option. However on Mac OS X it’s not as straight forward… or is it? Using Terminal you can switch into any account by typing:

su yourAccountName

You will be prompted to enter the password for yourAccountName.

Then you can change the password for this account by typing:


You will have to enter the old password, then your new password and then repeat your new password.



How to switch between users on one terminal?
Change password on root user and user account

OS X Default Apps Not Changing

I ran into another weird issue during my first week with my MacBook Pro, for some reason I couldn’t change any of the default apps. Since this is my work laptop I wanted Outlook to be my default email client not Apple’s Mail.

However, it turned out I needed to reset my default app preferences as the preferences file had become corrupt! Use the following command in terminal to do it:

/System/Library/Frameworks/CoreServices.framework/Versions/A/Frameworks/LaunchServices.framework/Versions/A/Support/lsregister -kill -r -all local,system,user

Worked great for me🙂

Source: Unable to change default email application

What is Idempotence?

Got asked this question the other day and my mind pulled a blank on me. However an idempotent method is really straight forward. It’s just a method that no matter how many times its called the result state will always be the same, you can call the method many times without concern.

A good example of an idempotent method is the close() method on a data connection, you call it once, it closes, you call it a second time? Still closed, a third time? You get the idea.

This answer on the question of “What is idempotence?” on Stackoverflow explains it really well:


Update Node.js on a Windows Machine

Since most people are doing front end development on a Mac or are running Ubuntu updating Node.js on Windows seems to be forgotten about on most tutorials or accepted answers on Stackoverflow.

So here it is, download the latest MSI from the Node.js website (and install!) and then run the following commands on CMD Prompt.

npm cache clean
npm update -g

Source: Upgrading Node.js to latest version