@Test public void shouldRetriveTheSameInstance() { NodePreparer preparer1 = NodePreparers.getPreparerFor(node1); NodePreparer preparer2 = NodePreparers.getPreparerFor(node1); assertTrue(preparer1 == preparer2); }
public static NodePreparer getPreparerFor(CloudNode node) { String nodeId = node.getId(); if (testing) { return preparerForTest; } else { synchronized (NodePreparers.class) { if (!preparers.containsKey(nodeId)) { NodePreparer preparer = new NodePreparer(node); preparers.put(nodeId, preparer); } } return preparers.get(nodeId); } }
NodePreparers { public static NodePreparer getPreparerFor(CloudNode node) { String nodeId = node.getId(); if (testing) { return preparerForTest; } else { synchronized (NodePreparers.class) { if (!preparers.containsKey(nodeId)) { NodePreparer preparer = new NodePreparer(node); preparers.put(nodeId, preparer); } } return preparers.get(nodeId); } } }
NodePreparers { public static NodePreparer getPreparerFor(CloudNode node) { String nodeId = node.getId(); if (testing) { return preparerForTest; } else { synchronized (NodePreparers.class) { if (!preparers.containsKey(nodeId)) { NodePreparer preparer = new NodePreparer(node); preparers.put(nodeId, preparer); } } return preparers.get(nodeId); } }  }
NodePreparers { public static NodePreparer getPreparerFor(CloudNode node) { String nodeId = node.getId(); if (testing) { return preparerForTest; } else { synchronized (NodePreparers.class) { if (!preparers.containsKey(nodeId)) { NodePreparer preparer = new NodePreparer(node); preparers.put(nodeId, preparer); } } return preparers.get(nodeId); } }  static NodePreparer getPreparerFor(CloudNode node); }
NodePreparers { public static NodePreparer getPreparerFor(CloudNode node) { String nodeId = node.getId(); if (testing) { return preparerForTest; } else { synchronized (NodePreparers.class) { if (!preparers.containsKey(nodeId)) { NodePreparer preparer = new NodePreparer(node); preparers.put(nodeId, preparer); } } return preparers.get(nodeId); } }  static NodePreparer getPreparerFor(CloudNode node); static NodePreparer preparerForTest; static boolean testing; }