### Question:
ParamFlowRequestDataWriter implements EntityWriter<ParamFlowRequestData, ByteBuf> { int calculateParamAmount( Collection<Object> params) { int size = 0; int length = 0; for (Object param : params) { int s = calculateParamTransportSize(param); if (s <= 0) { RecordLog.warn("[ParamFlowRequestDataWriter] WARN: Non-primitive type detected in params of " + "cluster parameter flow control, which is not supported: " + param); continue; } if (size + s > maxParamByteSize) { break; } size += s; length++; } return length; } ParamFlowRequestDataWriter();  ParamFlowRequestDataWriter(int maxParamByteSize); @Override void writeTo(ParamFlowRequestData entity, ByteBuf target);  }### Answer:
@Test public void testCalculateParamAmountExceedsMaxSize() { final int maxSize = 10; ParamFlowRequestDataWriter writer = new ParamFlowRequestDataWriter(maxSize); assertEquals(1, writer.calculateParamAmount(new ArrayList<Object>() {{ add(1); }})); assertEquals(2, writer.calculateParamAmount(new ArrayList<Object>() {{ add(1); add(64); }})); assertEquals(2, writer.calculateParamAmount(new ArrayList<Object>() {{ add(1); add(64); add(3); }})); }
@Test public void testCalculateParamAmount() { ParamFlowRequestDataWriter writer = new ParamFlowRequestDataWriter(); assertEquals(6, writer.calculateParamAmount(new ArrayList<Object>() {{ add(1); add(1d); add(1f); add((byte) 1); add("123"); add(true); }})); assertEquals(0, writer.calculateParamAmount(new ArrayList<Object>() {{ add(new SomePojo()); }})); assertEquals(1, writer.calculateParamAmount(new ArrayList<Object>() {{ add(new Object()); add(1); }})); }