### Question:
MinimumDistanceCalculator extends Attribute { public static int calculateDistance(Object[] entities, int start, int end) { boolean[] visited = new boolean[entities.length]; int[] distance = new int[entities.length]; for (int i = 0; i < entities.length; i++) { distance[i] = Integer.MAX_VALUE; } distance[start] = 0; Map<Object, Integer> entityToIndex = new HashMap<Object, Integer>(); for (int i = 0; i < entities.length; i++) { entityToIndex.put(entities[i], Integer.valueOf(i)); } Entity current = (Entity) entities[start]; int currentIndex = start; boolean done = false; while (!done) { int currentDistance = distance[currentIndex]; List<IOPort> ports = current.portList(); for (IOPort port : ports) { if (port.isOutput()) { List<IOPort> remotePorts = port.connectedPortList(); for (IOPort remotePort : remotePorts) { Entity neighbor = (Entity) remotePort.getContainer(); int neighborIndex = entityToIndex.get(neighbor) .intValue(); if (visited[neighborIndex]) { continue; } if (distance[neighborIndex] > currentDistance + 1) { distance[neighborIndex] = currentDistance + 1; } } } } visited[currentIndex] = true; if (currentIndex == end) { break; } int minimumDistance = Integer.MAX_VALUE; done = true; for (int i = 0; i < entities.length; i++) { if (visited[i]) { continue; } done = false; if (distance[i] <= minimumDistance) { minimumDistance = distance[i]; currentIndex = i; } } current = (Entity) entities[currentIndex]; } return distance[end]; } MinimumDistanceCalculator(NamedObj container, String name); static int calculateDistance(Object[] entities, int start, int end);  }### Answer:
@Test public void testCalculateDistance() { List<Entity> entityList = testModel.entityList(); int result = MinimumDistanceCalculator .calculateDistance(entityList.toArray(), 0, 2); Assert.assertEquals(1, result); result = MinimumDistanceCalculator .calculateDistance(entityList.toArray(), 0, 0); Assert.assertEquals(0, result); result = MinimumDistanceCalculator .calculateDistance(entityList.toArray(), 1, 0); Assert.assertEquals(Integer.MAX_VALUE, result); }