/** Verify nothing serialized if no registered components */ public void testSerializeAsPartNoComponents() throws Exception { InstanceStack iStack = new InstanceStack(); iStack.setConfigAdapter(mci); JsonEncoder jsonMock = Mockito.mock(JsonEncoder.class); iStack.serializeAsPart(jsonMock); assertEquals( "Components should empty when no registered components", 0, iStack.getComponents().size()); verifyZeroInteractions(jsonMock); }
/** Verify registered components are serialized in alphabetical order */ public void testSerializeAsPart() throws Exception { InstanceStack iStack = new InstanceStack(); iStack.setConfigAdapter(mci); JsonEncoder jsonMock = Mockito.mock(JsonEncoder.class); BaseComponent<?, ?> a = getComponentWithPath("a"); BaseComponent<?, ?> b = getComponentWithPath("b"); BaseComponent<?, ?> c = getComponentWithPath("c"); iStack.registerComponent(b); iStack.registerComponent(c); iStack.registerComponent(a); iStack.serializeAsPart(jsonMock); List<BaseComponent<?, ?>> sorted = Lists.newArrayList(); sorted.add(a); sorted.add(b); sorted.add(c); verify(jsonMock).writeMapKey("components"); verify(jsonMock).writeArray(sorted); }
@Override public void serializeAsPart(Json json) throws IOException { if (fakeInstanceStack != null) { fakeInstanceStack.serializeAsPart(json); } }