### Question:
Solution extends SolutionPattern { public boolean composableWith(final Solution<T> other, final Query.QueryVariables vars) { return disjointWith(other) && bindings.compatibleWith(other.bindings, vars); } Solution(final Solution<T> other);  Solution(final int totalPatterns,
                    final int index,
                    final Bindings<T> bindings,
                    final long expirationTime);  Solution(final Solution<T> other,
                    final int index);  Solution(final Solution<T> other,
                    final int index,
                    final Bindings<T> newBindings);  Solution(final int totalPatterns,
                    final Solution<T> first,
                    final Solution<T> second); Bindings<T> getBindings(); void setBindings(final Bindings<T> bindings); boolean composableWith(final Solution<T> other,
                                  final Query.QueryVariables vars);  }### Answer:
@Test public void testCompatibility() throws Exception { Solution<String> ps1, ps2; Query.QueryVariables vars = new Query.QueryVariables(Arrays.asList("x", "y", "z")); HashMap<String, String> map1, map2; Bindings<String> b1, b2; map1 = new HashMap<>(); map1.put("x", "red"); map1.put("y", "green"); b1 = new Bindings<>(map1, vars); ps1 = new Solution<>(3, 0, b1, exp); map2 = new HashMap<>(); map2.put("x", "red"); map2.put("y", "green"); b2 = new Bindings<>(map2, vars); ps2 = new Solution<>(3, 1, b2, exp); assertTrue(ps1.composableWith(ps2, vars)); assertTrue(ps2.composableWith(ps1, vars)); map2 = new HashMap<>(); map2.put("x", "red"); map2.put("y", "blue"); b2 = new Bindings<>(map2, vars); ps2 = new Solution<>(3, 1, b2, exp); assertFalse(ps1.composableWith(ps2, vars)); assertFalse(ps2.composableWith(ps1, vars)); map2 = new HashMap<>(); map2.put("x", "red"); map2.put("z", "blue"); b2 = new Bindings<>(map2, vars); ps2 = new Solution<>(3, 1, b2, exp); assertTrue(ps1.composableWith(ps2, vars)); assertTrue(ps2.composableWith(ps1, vars)); map2 = new HashMap<>(); map2.put("z", "blue"); b2 = new Bindings<>(map2, vars); ps2 = new Solution<>(3, 1, b2, exp); assertTrue(ps1.composableWith(ps2, vars)); assertTrue(ps2.composableWith(ps1, vars)); map2 = new HashMap<>(); map2.put("z", "blue"); b2 = new Bindings<>(map2, vars); ps2 = new Solution<>(3, 0, b2, exp); assertFalse(ps1.composableWith(ps2, vars)); assertFalse(ps2.composableWith(ps1, vars)); }
@Test(expected = NoSuchElementException.class) public void testInvalidVariables() { Solution<String> ps1, ps2; Query.QueryVariables vars = new Query.QueryVariables(Arrays.asList("x", "y", "z")); HashMap<String, String> map1, map2; Bindings<String> b1, b2; map1 = new HashMap<>(); map1.put("x", "red"); map1.put("y", "green"); b1 = new Bindings<>(map1, vars); ps1 = new Solution<>(3, 0, b1, exp); map2 = new HashMap<>(); map2.put("a", "red"); map2.put("b", "green"); b2 = new Bindings<>(map2, vars); ps2 = new Solution<>(3, 0, b2, exp); ps1.composableWith(ps2, vars); }