### Question:
Subscriptions { public void update(Map<Subscription, Long> subs, long currentTime, long expirationTime) { for (Subscription sub : expressions) { if (subs.put(sub, expirationTime) == null) { LOGGER.debug("new subscription: {}", sub); } } Iterator<Map.Entry<Subscription, Long>> it = subs.entrySet().iterator(); while (it.hasNext()) { Map.Entry<Subscription, Long> entry = it.next(); if (entry.getValue() < currentTime) { LOGGER.debug("expired: {}", entry.getKey()); it.remove(); } } } Subscriptions(); void update(Map<Subscription, Long> subs, long currentTime, long expirationTime); List<Subscription> getExpressions(); void setExpressions(List<Subscription> expressions); Subscriptions withExpressions(List<Subscription> expressions); @Override boolean equals(Object o); @Override int hashCode(); @Override String toString();  }### Answer:
@Test public void updateInit() { Map<Subscription, Long> subs = new HashMap<>(); Subscription a = newSub("a", ":true,:sum", 10L); Subscription b = newSub("b", ":true,:sum", 60L); newSubs(a, b).update(subs, 0L, 15L); Assertions.assertEquals(map(15L, a, b), subs); }
@Test public void updateComplete() { Subscription a = newSub("a", ":true,:sum", 10L); Subscription b = newSub("b", ":true,:sum", 60L); Map<Subscription, Long> subs = map(15L, a, b); newSubs(a, b).update(subs, 10L, 30L); Assertions.assertEquals(map(30L, a, b), subs); }
@Test public void updatePartial() { Subscription a = newSub("a", ":true,:sum", 10L); Subscription b = newSub("b", ":true,:sum", 60L); Map<Subscription, Long> subs = map(15L, a, b); newSubs(b).update(subs, 10L, 30L); Map<Subscription, Long> expected = map(15L, a, b); expected.put(b, 30L); Assertions.assertEquals(expected, subs); }
@Test public void updatePartialExpire() { Subscription a = newSub("a", ":true,:sum", 10L); Subscription b = newSub("b", ":true,:sum", 60L); Map<Subscription, Long> subs = map(15L, a, b); newSubs(b).update(subs, 16L, 30L); Map<Subscription, Long> expected = map(30L, b); Assertions.assertEquals(expected, subs); }