FlowUtils { public static Action createSetFieldDestinationMacAddress(int order, String macAddress) { Action action; ActionBuilder ab = new ActionBuilder(); MacAddress address = MacAddress.getDefaultInstance(macAddress); EthernetDestination destination = new EthernetDestinationBuilder().setAddress(address).build(); EthernetMatchBuilder builder = new EthernetMatchBuilder(); builder.setEthernetDestination(destination); EthernetMatch ethernetMatch = builder.build(); SetFieldBuilder setFieldBuilder = new SetFieldBuilder(); setFieldBuilder.setEthernetMatch(ethernetMatch); SetField setField = setFieldBuilder.build(); org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.Action acction = new SetFieldCaseBuilder(). setSetField(setField).build(); ab.setOrder(order).setKey(new ActionKey(order)).setAction(acction); action = ab.build(); return action; } private  FlowUtils(); static EthernetMatch createEthernetMatch(); static Action createSendToControllerAction(int order); static Action createOutputNormal(int order); static Action createSetFieldDestinationMacAddress(int order, String macAddress);  }
@Test public void testCreateSetFieldDestinationMacAddressAction() throws Exception { ActionBuilder ab = mock(ActionBuilder.class); PowerMockito.whenNew(ActionBuilder.class).withNoArguments().thenReturn(ab); EthernetMatchBuilder ethernetMatchBuilder = mock(EthernetMatchBuilder.class); PowerMockito.whenNew(EthernetMatchBuilder.class).withNoArguments().thenReturn(ethernetMatchBuilder); when(ethernetMatchBuilder.setEthernetDestination(any(EthernetDestination.class))).thenReturn(ethernetMatchBuilder); when(ab.setOrder(any(Integer.class))).thenReturn(ab); PowerMockito.whenNew(ActionKey.class).withAnyArguments().thenReturn(mock(ActionKey.class)); when(ab.setKey(any(ActionKey.class))).thenReturn(ab); SetFieldCaseBuilder setFieldCaseBuilder = mock(SetFieldCaseBuilder.class); PowerMockito.whenNew(SetFieldCaseBuilder.class).withNoArguments().thenReturn(setFieldCaseBuilder); when(setFieldCaseBuilder.setSetField(any(SetField.class))).thenReturn(setFieldCaseBuilder); when(ab.setAction(any(SetFieldCase.class))).thenReturn(ab); SetFieldBuilder setFieldBuilder = mock(SetFieldBuilder.class); PowerMockito.whenNew(SetFieldBuilder.class).withNoArguments().thenReturn(setFieldBuilder); when(setFieldBuilder.setProtocolMatchFields(any(ProtocolMatchFields.class))).thenReturn(setFieldBuilder); when(ethernetMatchBuilder.build()).thenReturn(mock(EthernetMatch.class)); when(setFieldBuilder.build()).thenReturn(mock(SetField.class)); when(setFieldCaseBuilder.build()).thenReturn(mock(SetFieldCase.class)); Action action = mock(Action.class); when(ab.build()).thenReturn(action); assertEquals("Failed to return correct Action object", action, FlowUtils.createSetFieldDestinationMacAddress(0, "d2:00:1f:e5:8b:e4")); }