@Test public void aNotificationShouldBeEqualToTheOtherEvenTheirDetailsAreBithNull() { notification = new Notification(notification.getMessage(), null); Notification other = new Notification(notification.getMessage(), null); assertEquals(notification, other); }
@Test public void twoNotificationsShouldBeEqualIfTheyWrapEqualMessagesAndEqualDetails() { Notification other = new Notification(notification.getMessage(), notification.getDetail()); assertEquals(notification, other); assertThat(notification.hashCode(), is(equalTo(other.hashCode()))); }
@Test public void twoNotificationsShouldNotBeEqualIfTheyWrapUnequalMessages() { Notification other = new Notification(notification.getMessage() + "Y", notification.getDetail()); assertNotEquals(notification, other); }
public void handleNotification(Notification notification, Object handback) { log.warn("================================================================================"); String message = notification.getMessage(); log.warn("Message: " + message); String type = notification.getType(); log.warn("Type: " + type); if (type.equals(MemoryNotificationInfo.MEMORY_THRESHOLD_EXCEEDED) || type.equals(MemoryNotificationInfo.MEMORY_COLLECTION_THRESHOLD_EXCEEDED)) { CompositeData cd = (CompositeData) notification.getUserData(); MemoryNotificationInfo info = MemoryNotificationInfo.from(cd); String poolName = info.getPoolName(); log.warn("Pool Name: " + poolName); long count = info.getCount(); log.warn("Count: " + count); MemoryUsage usage = info.getUsage(); long maxMemory = usage.getMax(); long maxMB = maxMemory / (1024 * 1024); long usedMemory = usage.getUsed(); long usedMB = usedMemory / (1024 * 1024); double percentUsed = (double) usedMemory / maxMemory; log.debug( "Used Memory : " + usedMB + "/" + maxMB + " MB (" + percentFormat.format(percentUsed) + ")"); } }
private static void playTurn(Player p1, Player p2) { int x = -1, y = -1; System.out.println("\n\n\n\n\n"); System.out.println("Player " + p1.getName() + ": your Turn!"); Notification n = p1.getNotification(); while (n != null) { System.out.println(n.getMessage()); n = p1.getNotification(); } // print Battlefield System.out.println("My Battlefield:"); p1.getBattlefield().printGrid(); // print Monitor System.out.println("\nHUD:"); p1.getMonitor().printGrid(); int sunk = 5 - p2.shipsCount(); System.out.println("\nDestroyed " + sunk + "\t# of ships: " + p2.shipsCount()); boolean correct = false; scanIn = new Scanner(System.in); // read coordinates from stdin while (!correct) { try { System.out.print("Shot x: "); x = scanIn.nextInt(); System.out.print("Shot y: "); y = scanIn.nextInt(); if (x >= 0 && x < 10 && y >= 0 && y < 10) correct = true; } catch (InputMismatchException ime) { System.out.println("Error: insert only integers."); scanIn.next(); } } // shot Notification ans = p2.shot(x, y); String message = ans.getMessage(); System.out.println(message); // generate notification if (message.compareTo(Notification.HIT) == 0) { p2.setNotification(new Notification("Ship was hit in " + x + "-" + y)); // update monitor p1.getMonitor().setShot(x, y, true); } else if (message.compareTo(Notification.HITSUNK) == 0) { p2.setNotification(new Notification("Ship was sunk in " + x + "-" + y)); // update monitor p1.getMonitor().setShot(x, y, true); } else if (message.compareTo(Notification.MISS) == 0) { // update monitor p1.getMonitor().setShot(x, y, false); } // check if dead if (p2.shipsCount() == 0) { p2.setDead(); } pressAnyKeyToContinue(); return; }