@Test public void shouldHaveNoSpecifiedButUnrealizedDependencies() { List<String> unrealized = new ArrayList<>(); packageDependencies .keySet() .stream() .map(Package::getPackage) .forEach( sourcePackage -> dependenciesOf(sourcePackage) .stream() .filter( dependency -> !packageDependencies.get(sourcePackage.getName()).contains(dependency)) .forEach(target -> unrealized.add(sourcePackage + " -> " + target))); if (!unrealized.isEmpty()) fail("unrealized dependencies:\n" + String.join("\n", unrealized)); }
@Test public void shouldHaveOnlyDefinedDependencies() { List<String> unexpected = new ArrayList<>(); packageDependencies .keySet() .stream() .map(Package::getPackage) .forEach( sourcePackage -> { List<String> allowed = dependenciesOf(sourcePackage); String source = sourcePackage.getName(); packageDependencies .get(source) .stream() .filter(target -> !source.equals(target)) .filter(target -> !allowed.contains(target)) .filter(target -> !isAlwaysAllowed(target)) .forEach(target -> unexpected.add(source + " -> " + target)); }); if (!unexpected.isEmpty()) fail("unexpected dependencies:\n" + String.join("\n", unexpected)); }
private List<String> dependenciesOf(Package source) { List<String> result = new ArrayList<>(); if (source.isAnnotationPresent(DependsUpon.class)) for (Class<?> target : source.getAnnotation(DependsUpon.class).packagesOf()) result.add(target.getPackage().getName()); return result; }
@Mock public int computeX(Invocation inv, int a, int b) { inputValues.add(a); inputValues.add(b); int x = inv.proceed(); outputValues.add(x); return x; }
@Test public void receiveAnOrder() throws Exception { when(request.getMethod()).thenReturn("POST"); when(request.getRequestURI()).thenReturn("/orders"); when(request.getParameter("order_code")).thenReturn("1234"); when(request.getParameter("article_code")).thenReturn("ABCD"); when(request.getParameter("address")).thenReturn("Some Place"); ordersController.service(); assertEquals(1, orders.size()); assertEquals(new Order("1234", "ABCD", "Some Place"), orders.get(0)); }
@Test @Ignore public void showAllNonShippedOrders() throws Exception { orders.add(new Order("a", "b", "c")); orders.add(new Order("d", "e", "f")); when(request.getMethod()).thenReturn("GET"); when(request.getRequestURI()).thenReturn("/orders"); ordersController.service(); verify(ordersView).show(orders); }
@Mock public int computeX(Invocation inv, int a, int b) { Integer x; try { x = inv.proceed(); return x; } finally { // Statements to be executed on exit would be here. //noinspection UnusedAssignment x = a + b; values.add(x); } }
@Test @Ignore public void shippedOrdersAreNotShown() throws Exception { Order shipped = new Order("X"); Order notShipped = new Order("Y"); orders.addAll(asList(shipped, notShipped)); shipped.ship(); when(request.getMethod()).thenReturn("GET"); when(request.getRequestURI()).thenReturn("/orders"); ordersController.service(); verify(ordersView).show(asList(notShipped)); }
@Test @Ignore public void theControllerWillShipAnOrder() throws Exception { Order order = new Order("5555", "_", "_"); orders.add(order); when(request.getMethod()).thenReturn("POST"); when(request.getRequestURI()).thenReturn("/orders/shipped"); when(request.getParameter("order_code")).thenReturn("5555"); ordersController.service(); assertEquals("controller should set shipped", true, order.isShipped()); verify(ordersView).refresh(); }
private List<List<Location>> buildGridOfLocations() { List<Location> northMostFirst = liveCellLocations.stream().sorted().collect(toList()); Location northMost = northMostFirst.get(0); Location southMost = northMostFirst.get(northMostFirst.size() - 1); List<Location> westMostFirst = liveCellLocations.stream().sorted(byWestMostFirst).collect(toList()); Location westMost = westMostFirst.get(0); Location eastMost = westMostFirst.get(westMostFirst.size() - 1); Location topLeft = getTopLeft(northMost, westMost); Location topRight = getTopRight(northMost, eastMost); Location bottomLeft = getBottomLeft(northMost, southMost); List<Location> topRow = topRowWith(topLeft, topRight); return gridWith(topRow, topLeft, bottomLeft); }
@Mock public int computeX(Invocation inv, int a, int b) { values.add(a + b); return inv.proceed(); }