UpdateFlow { private String checkInstance(UserId userId, Flow flow){ if (tenantManage.getFlow(userId)!=null){ if (tenantManage.getFlow(userId).containsKey(flow.getFlowId())){ Flow flowExist = tenantManage.getFlow(userId).get(flow.getFlowId()); if (!flowExist.getFlowName().equals(flow.getFlowName())){ return "The flow name should not be changed."; } } } if (tenantManage.getFlowDataStore(userId)!=null){ if (tenantManage.getFlowDataStore(userId).containsKey(flow.getFlowId())){ Flow flowExist = tenantManage.getFlowDataStore(userId).get(flow.getFlowId()); if (!flowExist.getFlowName().equals(flow.getFlowName())){ return "The flow name should not be changed."; } } } return null; } UpdateFlow(DataBroker dataBroker, TenantManage tenantManage); String FlowHandling(UserId userId, Flow flow);  }
@Test public void testcheckInstance() throws Exception { Class<UpdateFlow> class1 = UpdateFlow.class; Method method = class1.getDeclaredMethod("checkInstance",new Class[]{UserId.class, Flow.class}); method.setAccessible(true); Map<FlowId,Flow> map1 = new HashMap<FlowId, Flow>(); map1.put(flowId,flow2); when(tenantManage.getFlow(userId)).thenReturn(map1); when(flow.getFlowId()).thenReturn(flowId); when(flow2.getFlowName()).thenReturn(flowName2); when(flow.getFlowName()).thenReturn(flowName); Assert.assertEquals(method.invoke(updateFlow, userId, flow), "The flow name should not be changed."); when(tenantManage.getFlow(userId)).thenReturn(null); when(tenantManage.getFlowDataStore(userId)).thenReturn(map1); when(flow.getFlowId()).thenReturn(flowId); when(flow2.getFlowName()).thenReturn(flowName2); when(flow.getFlowName()).thenReturn(flowName); Assert.assertEquals(method.invoke(updateFlow, userId, flow), "The flow name should not be changed."); when(tenantManage.getFlow(userId)).thenReturn(null); when(tenantManage.getFlowDataStore(userId)).thenReturn(null); Assert.assertEquals(method.invoke(updateFlow, userId, flow), null); }