ModelWriter { public void beginObject(final PWindow window) { encoder.beginObject(); if (currentWindow == null || !window.equals(currentWindow.get())) { currentWindow = new WeakReference<>(window); encoder.encode(ServerToClientModel.WINDOW_ID, window.getID()); } } ModelWriter(final WebsocketEncoder encoder); void beginObject(final PWindow window); void write(final ServerToClientModel model); void write(final ServerToClientModel model, final Object value); void endObject(); PWindow getCurrentWindow();  }
@Test public void testBeginObject() { final PWindow window1 = Element.newPWindow(null, null); modelWriter.beginObject(window1); modelWriter.beginObject(window1); final PWindow window2 = Element.newPWindow(null, null); modelWriter.beginObject(window2); Mockito.verify(websocketEncoder, Mockito.times(3)).beginObject(); Mockito.verify(websocketEncoder, Mockito.times(2)).encode(ArgumentMatchers.eq(ServerToClientModel.WINDOW_ID), ArgumentMatchers.any()); assertEquals(window2, modelWriter.getCurrentWindow()); }