DataContainer { public void setMaxLength(int maxLength) { this.maxLength = maxLength; }  void push(String id, String key, Object t); synchronized void push(String id, String key, Object t, boolean force); synchronized Map<String, Map<String, Object>> pop(); void setMaxLength(int maxLength);  }
@Test public void testSetMaxLength () { final DataContainer dataContainer = new DataContainer(); Runnable t = new Runnable() { @Override public void run() { while(true) { Map<String, Map<String, Object>> data = dataContainer.pop(); assertEquals(data.size(), 1); assertEquals(data.get("1").size(), 7); if (data.get("1").size() == 7) { break; } } }}; Thread tr = new Thread(t); tr.start(); dataContainer.push("1", "ff", "07"); dataContainer.setMaxLength(7); dataContainer.push("1", "gg", "01"); dataContainer.push("1", "hh", "02"); dataContainer.push("1", "ii", "03"); dataContainer.push("1", "jj", "04"); dataContainer.push("1", "kk", "05"); dataContainer.push("1", "ll", "06"); try { tr.join(); } catch (InterruptedException e) { e.printStackTrace(); } }