### Question:
MatrixRunner { public void run() { if (!paramMatrix.isEmpty()) { Map.Entry<String, List<T>> entry = paramMatrix.entrySet().iterator().next(); for (T value: entry.getValue()) { Map<String, T> paramsCopy = new LinkedHashMap<>(paramMap); paramsCopy.put(entry.getKey(), value); Map<String, List<T>> matrixCopy = new LinkedHashMap<>(paramMatrix); matrixCopy.remove(entry.getKey()); new MatrixRunner<T>(paramsCopy, matrixCopy) { @Override protected void run(Map<String, T> paramMap) { MatrixRunner.this.run(paramMap); } }.run(); } } else { run(paramMap); } } MatrixRunner(Map<String, List<T>> paramMatrix); private  MatrixRunner(Map<String, T> paramMap, Map<String, List<T>> paramMatrix); void run();  }### Answer:
@Test public void test() { Map<String, List<String>> matrix = new LinkedHashMap<>(); List<Map<String, String>> usedParams = new ArrayList<>(); new MatrixRunner<String>(matrix) { @Override public void run(Map<String, String> params) { usedParams.add(params); } }.run(); assertEquals(1, usedParams.size()); assertTrue(usedParams.iterator().next().isEmpty()); matrix.put("db", Lists.newArrayList("oracle", "mysql")); matrix.put("os", Lists.newArrayList("windows", "linux")); usedParams.clear(); new MatrixRunner<String>(matrix) { @Override public void run(Map<String, String> params) { usedParams.add(params); } }.run(); assertEquals(4, usedParams.size()); Map<String, String> params = new HashMap<>(); params.put("db", "oracle"); params.put("os", "windows"); assertEquals(params, usedParams.get(0)); params.put("db", "oracle"); params.put("os", "linux"); assertEquals(params, usedParams.get(1)); params.put("db", "mysql"); params.put("os", "windows"); assertEquals(params, usedParams.get(2)); params.put("db", "mysql"); params.put("os", "linux"); assertEquals(params, usedParams.get(3)); }