### Question:
MethodCanaryConverter { static MethodsRecordInfo convertToMethodsRecordInfo(long startMillis, long stopMillis, Map<ThreadInfo, List<MethodEvent>> methodEventMap) { MethodsRecordInfo methodsRecordInfo = new MethodsRecordInfo(startMillis, stopMillis, new ArrayList<>()); if (methodEventMap == null || methodEventMap.isEmpty()) { return methodsRecordInfo; } for (Map.Entry<ThreadInfo, List<MethodEvent>> entry : methodEventMap.entrySet()) { List<MethodEvent> methodEvents = entry.getValue(); List<MethodsRecordInfo.MethodInfoOfThreadInfo.MethodInfo> methodInfos = new ArrayList<>(methodEvents.size()); Stack<MethodsRecordInfo.MethodInfoOfThreadInfo.MethodInfo> methodEventsStackOfCurrentThread = new Stack<>(); for (MethodEvent methodEvent : methodEvents) { if (methodEvent.isEnter) { MethodsRecordInfo.MethodInfoOfThreadInfo.MethodInfo methodInfo = new MethodsRecordInfo.MethodInfoOfThreadInfo.MethodInfo(); methodInfo.className = methodEvent.className; methodInfo.methodAccessFlag = methodEvent.methodAccessFlag; methodInfo.methodName = methodEvent.methodName; methodInfo.methodDesc = methodEvent.methodDesc; methodInfo.startMillis = methodEvent.eventTimeMillis; methodInfo.stack = methodEventsStackOfCurrentThread.size(); methodInfos.add(methodInfo); methodEventsStackOfCurrentThread.push(methodInfo); } else { MethodsRecordInfo.MethodInfoOfThreadInfo.MethodInfo methodInfo = null; if (!methodEventsStackOfCurrentThread.empty()) { methodInfo = methodEventsStackOfCurrentThread.pop(); } if (methodInfo != null) { methodInfo.endMillis = methodEvent.eventTimeMillis; } } } methodsRecordInfo.methodInfoOfThreadInfos.add(new MethodsRecordInfo.MethodInfoOfThreadInfo(entry.getKey(), methodInfos)); } return methodsRecordInfo; }    }### Answer:
@Test public void convertToMethodsRecordInfo() { Map<ThreadInfo, List<MethodEvent>> methodEventMap = mockMethodEventMap(); MethodsRecordInfo methodsRecordInfo = mockMethodsRecordInfo(methodEventMap); Gson gson = new Gson(); String c = gson.toJson(methodsRecordInfo); System.out.println("methodsRecordInfo:\n" + c); assertEquals(methodsRecordInfo.methodInfoOfThreadInfos.size(), methodEventMap.size()); }