Installing ADB on MacOS

If you've already installed Android Studio --

Add the following lines to the end of ~/.bashrc or ~/.zshrc (if using Oh My ZSH):

export ANDROID_HOME=/Users/$USER/Library/Android/sdk
export PATH=${PATH}:$ANDROID_HOME/tools:$ANDROID_HOME/platform-tools

Restart Terminal and you're good to go.

set the value of a variable synchronously for an asynchronous function

function getWords( callback ){

    var words = [];

    chrome.runtime.sendMessage({detail: "words"}, function(response) {
        console.log(response) // prints ["word1, "word2" ..]


function processWords(words){
    //do your logic in here

How to save Objects in local storage in Chrome + JavaScript

local storage limited to handle only string key/value pairs you can do like below using JSON.stringify and while getting value JSON.parse

var testObject = {name:"test", time:"Date 2017-02-03T08:38:04.449Z"};
Put the object into storage:

localStorage.setItem('testObject', JSON.stringify(testObject));
localStorage['testObject'] = JSON.stringify(testObject));

Retrieve the object from storage:
var retrievedObject = localStorage.getItem('testObject');
var retrievedObject = localStorage['testObject'];

console.log('retrievedObject: ', JSON.parse(retrievedObject));

Replace all spaces in javascript

var a = ' he l l o '
var result = a.replace(/ /g, '+');

Caused by: java.lang.IllegalStateException: The driver is not executable: chromedriver + Selenium

Given below permission to chromedriver and it works.

chmod 777 chromedriver

As previous answer there is no relevance to the .exe part in stack trace

Mockito - calling real method


class C {
 void m1() { ...}
 boolean m2() { ... return flag;}

unit test code:

C cMock = Mockito.mock(C.class);
The strange thing is that m2 is not being called.


This is also where Mockito.spy can be used. it allows you to do partial mocks on real objects.

C cMock = Mockito.spy(new C());

Mockito and constructor + field injection Or Mocking a constructor of @Autowired service(system under test)

As mentioned in a previous post, I’m using Mockito extensively. It’s a superb framework that helps writing unit test a lot.

Recently, I came across a problem when trying to write a test for a legacy Spring class, that used injection in both constructor and field. In Guice, the class would like like this:

package io.mhlg.assisteddemo.service;

import io.mhlg.assisteddemo.domain.Money;

import javax.inject.Inject;

class InternetPayment implements Payment {
    private InternetDataSender internetDataSender;
    private InternetDataPreparer internetDataPreparer;

    private final Money money;

    public InternetPayment(@Assisted Money money) { = money;

    public String sendThePayment() {
        String theMessage = internetDataPreparer.prepareMessage(money);

        return internetDataSender.sendTheDataViaInternet(theMessage);

This isn’t an often case, but I can imagine a situation when that would be used.

Trying to test such a class with Mockito can be tricky. It turns out that when using @InjectMocks annotation, Mockito injects mocks only to the constructor, leaving the fields undefined. In order to test it properly, one needs to initialize the class with the constructor parameter and Mockito by hand:

package io.mhlg.assisteddemo.service;

import static org.assertj.core.api.Assertions.assertThat;

import io.mhlg.assisteddemo.domain.Money;
import org.junit.Before;
import org.junit.Test;
import org.mockito.InjectMocks;
import org.mockito.Mock;
import org.mockito.MockitoAnnotations;
import static org.mockito.Mockito.when;

public class InternetPaymentTest {

    private InternetPayment testObj;

    private InternetDataPreparer internetDataPreparer;

    private InternetDataSender internetDataSender;
    private Money someMoney;

    public void setUp() throws Exception {
        someMoney = Money.createMoney(100, "USD"); // you can use mock(Money.class) here instead
        testObj = new InternetPayment(someMoney);

    public void testSendThePayment() throws Exception {
        // given
        final String somePreparedMessage = "some message";

        final String someReturningMessage = "return message";

        // when
        final String result = testObj.sendThePayment();

        // then