AutonomiccsSystemVmsGuru implements VirtualMachineGuru, InitializingBean { protected void configureIpAndMaskOnNicWithIpAddressNullOrNotNull(StringBuilder buf, NicProfile nic, int deviceId) { if (nic.getIPv4Address() == null) { buf.append(" eth").append(deviceId).append("ip=").append(ipAddressInternet); buf.append(" eth").append(deviceId).append("mask=").append(maskForIpAddressInternet); } else { buf.append(" eth").append(deviceId).append("ip=").append(nic.getIPv4Address()); buf.append(" eth").append(deviceId).append("mask=").append(nic.getIPv4Netmask()); } }  @Override void afterPropertiesSet(); @Override boolean finalizeCommandsOnStart(Commands arg0, VirtualMachineProfile arg1); @Override boolean finalizeDeployment(Commands cmds, VirtualMachineProfile profile, DeployDestination dest, ReservationContext context); @Override void finalizeExpunge(VirtualMachine vm); @Override boolean finalizeStart(VirtualMachineProfile arg0, long arg1, Commands arg2, ReservationContext arg3); @Override void finalizeStop(VirtualMachineProfile arg0, Answer arg1); @Override boolean finalizeVirtualMachineProfile(VirtualMachineProfile profile, DeployDestination dest, ReservationContext context); @Override void prepareStop(VirtualMachineProfile arg0);  }
@Test public void configureIpAndMaskOnNicWithIpAddressNullOrNotNullTestIpAddressNotNull() { StringBuilder buf = new StringBuilder(); NicProfile nic = Mockito.mock(NicProfile.class); Mockito.when(nic.getIPv4Address()).thenReturn("ipv4Address"); Mockito.when(nic.getIPv4Netmask()).thenReturn("ipv4Netmask"); spy.configureIpAndMaskOnNicWithIpAddressNullOrNotNull(buf, nic, 0); Assert.assertEquals(" eth0ip=ipv4Address eth0mask=ipv4Netmask", buf.toString()); }
@Test public void configureIpAndMaskOnNicWithIpAddressNullOrNotNullTestIpAddressNull() { spy.ipAddressInternet = "ipAddressInternet"; spy.maskForIpAddressInternet = "maskForIpAddressInternet"; StringBuilder buf = new StringBuilder(); NicProfile nic = Mockito.mock(NicProfile.class); Mockito.when(nic.getIPv4Address()).thenReturn(null); spy.configureIpAndMaskOnNicWithIpAddressNullOrNotNull(buf, nic, 0); Assert.assertEquals(" eth0ip=ipAddressInternet eth0mask=maskForIpAddressInternet", buf.toString()); }