Tuesday, October 11, 2016

How to stop "Docker maven builds" downloading the whole maven repository everytime

When you google for this problem you can find different answers with different types of mounting of m2 folder. But if you are planing to mount your local m2 folder into Docker that is not really a very clean solution. The problem with that is the Docker build you are planing can be biased based on your local builds you have.

So I asked the question in stackoverflow and here is docker-compose.yml of my final working solution

version: '2'
services:
  client:
    build: .
    container_name: client
    volumes:
      - m2repo:/root/.m2/repository
volumes:
  m2repo:

Now when you run the system for the 2nd time, it will not load the maven content form the internet spending hours downloading them.

Sunday, November 15, 2015

Stubbing a method with Class field

Consider the scenario where you have to stub a method using when. In a case where parameter is a class not an object then the Matchers.any will not help in that case. Following is the code to be tested and one wrong way of stubbing.
// code to be tested
Long primaryKey = 12345L;
final App app = getEntityManager().find(App.class, primaryKey);

// stubbing the find method
when(em.find(Matchers.any(Class.class), Matchers.same(primaryKey)))
.thenReturn(app);
Instead of using Matchers.any we should use Matchers.isA as the way of stubbing. Following is correct way of stubbing in this setup.
when(em.find((Class) Matchers.isA(Class.class), Matchers.same(primaryKey)))
.thenReturn(app);
The original answer was found on stackoverflow.