Fix error-prone StringEquality

This commit is contained in:
Andrew Gaul 2015-03-29 16:48:14 -07:00
parent db5acb8588
commit df8407a1e8
5 changed files with 14 additions and 8 deletions

View File

@ -30,6 +30,7 @@ import org.jclouds.compute.reference.ComputeServiceConstants;
import org.jclouds.logging.Logger;
import com.google.common.base.Function;
import com.google.common.base.Objects;
import com.google.inject.assistedinject.Assisted;
public class StaticNATVirtualMachineInNetwork implements Function<VirtualMachine, PublicIPAddress> {
@ -55,10 +56,11 @@ public class StaticNATVirtualMachineInNetwork implements Function<VirtualMachine
public PublicIPAddress apply(VirtualMachine vm) {
PublicIPAddress ip;
for (ip = reuseOrAssociate.apply(network); !ip.isStaticNAT() || ip.getVirtualMachineId() != vm.getId(); ip = reuseOrAssociate
.apply(network)) {
for (ip = reuseOrAssociate.apply(network);
!ip.isStaticNAT() || !Objects.equal(ip.getVirtualMachineId(), vm.getId());
ip = reuseOrAssociate .apply(network)) {
// check to see if someone already grabbed this ip
if (ip.getVirtualMachineId() != null && ip.getVirtualMachineId() != vm.getId())
if (ip.getVirtualMachineId() != null && !ip.getVirtualMachineId().equals(vm.getId()))
continue;
try {
logger.debug(">> static NATing IPAddress(%s) to virtualMachine(%s)", ip.getId(), vm.getId());

View File

@ -44,6 +44,7 @@ import org.testng.annotations.AfterGroups;
import org.testng.annotations.BeforeGroups;
import org.testng.annotations.Test;
import com.google.common.base.Objects;
import com.google.common.base.Predicate;
import com.google.common.base.Predicates;
import com.google.common.net.HostAndPort;
@ -113,7 +114,7 @@ public class LoadBalancerApiLiveTest extends BaseCloudStackApiLiveTest {
}
}
assertNotNull(rule, "Failed to get a load balancer rule after " + attempts + " attempts");
assert rule.getPublicIPId() == ip.getId() : rule;
assertEquals(rule.getPublicIPId(), ip.getId());
assertEquals(rule.getPublicPort(), 22);
assertEquals(rule.getPrivatePort(), 22);
assertEquals(rule.getAlgorithm(), Algorithm.LEASTCONN);
@ -203,7 +204,7 @@ public class LoadBalancerApiLiveTest extends BaseCloudStackApiLiveTest {
@Override
public boolean apply(LoadBalancerRule arg0) {
return arg0.getId() == id;
return Objects.equal(arg0.getId(), id);
}
});

View File

@ -38,6 +38,7 @@ import org.testng.SkipException;
import org.testng.annotations.AfterGroups;
import org.testng.annotations.Test;
import com.google.common.base.Objects;
import com.google.common.base.Predicate;
import com.google.common.collect.ImmutableSet;
import com.google.common.collect.Iterables;
@ -119,7 +120,7 @@ public class SecurityGroupApiLiveTest extends BaseCloudStackApiLiveTest {
@Override
public boolean apply(SecurityGroup input) {
return input.getId() == group.getId();
return Objects.equal(input.getId(), group.getId());
}
});

View File

@ -55,6 +55,7 @@ import org.testng.annotations.AfterGroups;
import org.testng.annotations.Test;
import com.google.common.base.Function;
import com.google.common.base.Objects;
import com.google.common.base.Predicate;
import com.google.common.base.Throwables;
import com.google.common.collect.ComparisonChain;
@ -251,7 +252,7 @@ public class VirtualMachineApiLiveTest extends BaseCloudStackApiLiveTest {
boolean hasStaticIpNic = false;
for (NIC nic : vm.getNICs()) {
if (nic.getNetworkId() == network.getId()) {
if (Objects.equal(nic.getNetworkId(), network.getId())) {
hasStaticIpNic = true;
assertEquals(nic.getIPAddress(), ipAddress);
}

View File

@ -58,6 +58,7 @@ import org.jclouds.rest.RequestSigner;
import org.jclouds.rest.annotations.ApiVersion;
import com.google.common.annotations.VisibleForTesting;
import com.google.common.base.Objects;
import com.google.common.base.Supplier;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableSet;
@ -123,7 +124,7 @@ public interface FormSigner extends HttpRequestFilter {
@Override
public int compare(String left, String right) {
if (left == right) {
if (Objects.equal(left, right)) {
return 0;
}
if ("Action".equals(right) || "AWSAccessKeyId".equals(left)) {