Issue 871: renamed LocationPredicate to what it is

This commit is contained in:
Adrian Cole 2012-03-20 11:59:58 -07:00
parent 489777e872
commit 84fc104a31
4 changed files with 21 additions and 21 deletions

View File

@ -38,10 +38,10 @@ import com.google.common.collect.ImmutableSet.Builder;
* *
* If the input location equals, is a parent or grandparent of the specified location, then we are ok. * If the input location equals, is a parent or grandparent of the specified location, then we are ok.
*/ */
public class LocationPredicate implements Predicate<ComputeMetadata> { public class NullEqualToIsParentOrIsGrandparentOfCurrentLocation implements Predicate<ComputeMetadata> {
private final Supplier<Location> locationSupplier; private final Supplier<Location> locationSupplier;
public LocationPredicate(Supplier<Location> locationSupplier) { public NullEqualToIsParentOrIsGrandparentOfCurrentLocation(Supplier<Location> locationSupplier) {
this.locationSupplier = locationSupplier; this.locationSupplier = locationSupplier;
} }
@ -84,6 +84,6 @@ public class LocationPredicate implements Predicate<ComputeMetadata> {
@Override @Override
public String toString() { public String toString() {
// not calling .get() here, as it could accidentally cause eager api fetch // not calling .get() here, as it could accidentally cause eager api fetch
return "equalsParentOrGrandparentOfCurrentLocation()"; return "nullEqualToIsParentOrIsGrandparentOfCurrentLocation()";
} }
} }

View File

@ -133,7 +133,7 @@ public class TemplateBuilderImpl implements TemplateBuilder {
this.defaultTemplateProvider = defaultTemplateProvider; this.defaultTemplateProvider = defaultTemplateProvider;
} }
final Predicate<ComputeMetadata> locationPredicate = new LocationPredicate(new Supplier<Location>(){ final Predicate<ComputeMetadata> locationPredicate = new NullEqualToIsParentOrIsGrandparentOfCurrentLocation(new Supplier<Location>(){
@Override @Override
public Location get() { public Location get() {

View File

@ -34,8 +34,8 @@ import com.google.common.base.Suppliers;
* *
* @author Adrian Cole * @author Adrian Cole
*/ */
@Test(testName = "LocationPredicateTest") @Test(testName = "NullEqualToIsParentOrIsGrandparentOfCurrentLocationTest")
public class LocationPredicateTest { public class NullEqualToIsParentOrIsGrandparentOfCurrentLocationTest {
Location provider = new LocationBuilder().scope(LocationScope.PROVIDER).id("aws-ec2").description("aws-ec2").build(); Location provider = new LocationBuilder().scope(LocationScope.PROVIDER).id("aws-ec2").description("aws-ec2").build();
Location region = new LocationBuilder().scope(LocationScope.REGION).id("us-east-1").description("us-east-1") Location region = new LocationBuilder().scope(LocationScope.REGION).id("us-east-1").description("us-east-1")
@ -61,7 +61,7 @@ public class LocationPredicateTest {
* If the current location id is null, then we don't care where to launch a * If the current location id is null, then we don't care where to launch a
*/ */
public void testReturnTrueWhenIDontSpecifyALocation() { public void testReturnTrueWhenIDontSpecifyALocation() {
LocationPredicate predicate = new LocationPredicate(Suppliers.<Location> ofInstance(null)); NullEqualToIsParentOrIsGrandparentOfCurrentLocation predicate = new NullEqualToIsParentOrIsGrandparentOfCurrentLocation(Suppliers.<Location> ofInstance(null));
Hardware md = new HardwareBuilder().id("foo").location(region).build(); Hardware md = new HardwareBuilder().id("foo").location(region).build();
assertTrue(predicate.apply(md)); assertTrue(predicate.apply(md));
} }
@ -70,7 +70,7 @@ public class LocationPredicateTest {
* If the input location is null, then the data isn't location sensitive * If the input location is null, then the data isn't location sensitive
*/ */
public void testReturnTrueWhenISpecifyALocationAndInputLocationIsNull() { public void testReturnTrueWhenISpecifyALocationAndInputLocationIsNull() {
LocationPredicate predicate = new LocationPredicate(Suppliers.ofInstance(region)); NullEqualToIsParentOrIsGrandparentOfCurrentLocation predicate = new NullEqualToIsParentOrIsGrandparentOfCurrentLocation(Suppliers.ofInstance(region));
Hardware md = new HardwareBuilder().id("foo").location(null).build(); Hardware md = new HardwareBuilder().id("foo").location(null).build();
assertTrue(predicate.apply(md)); assertTrue(predicate.apply(md));
} }
@ -79,14 +79,14 @@ public class LocationPredicateTest {
* If the input location is null, then the data isn't location sensitive * If the input location is null, then the data isn't location sensitive
*/ */
public void testReturnTrueWhenIDontSpecifyALocationAndInputLocationIsNull() { public void testReturnTrueWhenIDontSpecifyALocationAndInputLocationIsNull() {
LocationPredicate predicate = new LocationPredicate(Suppliers.<Location> ofInstance(null)); NullEqualToIsParentOrIsGrandparentOfCurrentLocation predicate = new NullEqualToIsParentOrIsGrandparentOfCurrentLocation(Suppliers.<Location> ofInstance(null));
Hardware md = new HardwareBuilder().id("foo").location(null).build(); Hardware md = new HardwareBuilder().id("foo").location(null).build();
assertTrue(predicate.apply(md)); assertTrue(predicate.apply(md));
} }
@Test @Test
public void testReturnTrueWhenISpecifyARegionAndInputLocationIsProvider() { public void testReturnTrueWhenISpecifyARegionAndInputLocationIsProvider() {
LocationPredicate predicate = new LocationPredicate(Suppliers.ofInstance(region)); NullEqualToIsParentOrIsGrandparentOfCurrentLocation predicate = new NullEqualToIsParentOrIsGrandparentOfCurrentLocation(Suppliers.ofInstance(region));
Hardware md = new HardwareBuilder().id("foo").location(provider).build(); Hardware md = new HardwareBuilder().id("foo").location(provider).build();
assertTrue(predicate.apply(md)); assertTrue(predicate.apply(md));
} }
@ -96,7 +96,7 @@ public class LocationPredicateTest {
*/ */
@Test @Test
public void testReturnFalseWhenISpecifyALocationWhichTheSameScopeByNotEqualToInputLocationAndParentsAreNull() { public void testReturnFalseWhenISpecifyALocationWhichTheSameScopeByNotEqualToInputLocationAndParentsAreNull() {
LocationPredicate predicate = new LocationPredicate(Suppliers.ofInstance(region)); NullEqualToIsParentOrIsGrandparentOfCurrentLocation predicate = new NullEqualToIsParentOrIsGrandparentOfCurrentLocation(Suppliers.ofInstance(region));
Hardware md = new HardwareBuilder().id("foo").location(otherRegion).build(); Hardware md = new HardwareBuilder().id("foo").location(otherRegion).build();
assertFalse(predicate.apply(md)); assertFalse(predicate.apply(md));
} }
@ -105,7 +105,7 @@ public class LocationPredicateTest {
* If the input location is null, then the data isn't location sensitive * If the input location is null, then the data isn't location sensitive
*/ */
public void testReturnFalseWhenISpecifyALocationWhichTheSameScopeByNotEqualToInputLocationAndParentsAreNotNull() { public void testReturnFalseWhenISpecifyALocationWhichTheSameScopeByNotEqualToInputLocationAndParentsAreNotNull() {
LocationPredicate predicate = new LocationPredicate(Suppliers.ofInstance(zone)); NullEqualToIsParentOrIsGrandparentOfCurrentLocation predicate = new NullEqualToIsParentOrIsGrandparentOfCurrentLocation(Suppliers.ofInstance(zone));
Hardware md = new HardwareBuilder().id("foo").location(otherZone).build(); Hardware md = new HardwareBuilder().id("foo").location(otherZone).build();
assertFalse(predicate.apply(md)); assertFalse(predicate.apply(md));
} }
@ -115,7 +115,7 @@ public class LocationPredicateTest {
* ok. * ok.
*/ */
public void testReturnTrueWhenISpecifyALocationWhichIsAChildOfInput() { public void testReturnTrueWhenISpecifyALocationWhichIsAChildOfInput() {
LocationPredicate predicate = new LocationPredicate(Suppliers.ofInstance(zone)); NullEqualToIsParentOrIsGrandparentOfCurrentLocation predicate = new NullEqualToIsParentOrIsGrandparentOfCurrentLocation(Suppliers.ofInstance(zone));
Hardware md = new HardwareBuilder().id("foo").location(region).build(); Hardware md = new HardwareBuilder().id("foo").location(region).build();
assertTrue(predicate.apply(md)); assertTrue(predicate.apply(md));
} }
@ -125,7 +125,7 @@ public class LocationPredicateTest {
* ok. * ok.
*/ */
public void testReturnFalseWhenISpecifyALocationWhichIsNotAChildOfInput() { public void testReturnFalseWhenISpecifyALocationWhichIsNotAChildOfInput() {
LocationPredicate predicate = new LocationPredicate(Suppliers.ofInstance(zone)); NullEqualToIsParentOrIsGrandparentOfCurrentLocation predicate = new NullEqualToIsParentOrIsGrandparentOfCurrentLocation(Suppliers.ofInstance(zone));
Hardware md = new HardwareBuilder().id("foo").location(otherRegion).build(); Hardware md = new HardwareBuilder().id("foo").location(otherRegion).build();
assertFalse(predicate.apply(md)); assertFalse(predicate.apply(md));
} }
@ -135,7 +135,7 @@ public class LocationPredicateTest {
* are ok. * are ok.
*/ */
public void testReturnTrueWhenISpecifyALocationWhichIsAGrandChildOfInput() { public void testReturnTrueWhenISpecifyALocationWhichIsAGrandChildOfInput() {
LocationPredicate predicate = new LocationPredicate(Suppliers.ofInstance(host)); NullEqualToIsParentOrIsGrandparentOfCurrentLocation predicate = new NullEqualToIsParentOrIsGrandparentOfCurrentLocation(Suppliers.ofInstance(host));
Hardware md = new HardwareBuilder().id("foo").location(host).build(); Hardware md = new HardwareBuilder().id("foo").location(host).build();
assertTrue(predicate.apply(md)); assertTrue(predicate.apply(md));
@ -146,7 +146,7 @@ public class LocationPredicateTest {
* are ok. * are ok.
*/ */
public void testReturnFalseWhenISpecifyALocationWhichIsNotAGrandChildOfInput() { public void testReturnFalseWhenISpecifyALocationWhichIsNotAGrandChildOfInput() {
LocationPredicate predicate = new LocationPredicate(Suppliers.ofInstance(host)); NullEqualToIsParentOrIsGrandparentOfCurrentLocation predicate = new NullEqualToIsParentOrIsGrandparentOfCurrentLocation(Suppliers.ofInstance(host));
Hardware md = new HardwareBuilder().id("foo").location(otherRegion).build(); Hardware md = new HardwareBuilder().id("foo").location(otherRegion).build();
assertFalse(predicate.apply(md)); assertFalse(predicate.apply(md));
} }
@ -157,7 +157,7 @@ public class LocationPredicateTest {
*/ */
@Test(expectedExceptions = IllegalStateException.class) @Test(expectedExceptions = IllegalStateException.class)
public void testThrowIllegalStateExceptionWhenInputIsAnOrphanedRegion() { public void testThrowIllegalStateExceptionWhenInputIsAnOrphanedRegion() {
LocationPredicate predicate = new LocationPredicate(Suppliers.ofInstance(region)); NullEqualToIsParentOrIsGrandparentOfCurrentLocation predicate = new NullEqualToIsParentOrIsGrandparentOfCurrentLocation(Suppliers.ofInstance(region));
Hardware md = new HardwareBuilder().id("foo").location(orphanedRegion).build(); Hardware md = new HardwareBuilder().id("foo").location(orphanedRegion).build();
predicate.apply(md); predicate.apply(md);
} }
@ -168,7 +168,7 @@ public class LocationPredicateTest {
*/ */
@Test(expectedExceptions = IllegalStateException.class) @Test(expectedExceptions = IllegalStateException.class)
public void testThrowIllegalStateExceptionWhenInputIsAnOrphanedZone() { public void testThrowIllegalStateExceptionWhenInputIsAnOrphanedZone() {
LocationPredicate predicate = new LocationPredicate(Suppliers.ofInstance(region)); NullEqualToIsParentOrIsGrandparentOfCurrentLocation predicate = new NullEqualToIsParentOrIsGrandparentOfCurrentLocation(Suppliers.ofInstance(region));
Hardware md = new HardwareBuilder().id("foo").location(orphanedZone).build(); Hardware md = new HardwareBuilder().id("foo").location(orphanedZone).build();
predicate.apply(md); predicate.apply(md);
} }
@ -179,7 +179,7 @@ public class LocationPredicateTest {
*/ */
@Test(expectedExceptions = IllegalArgumentException.class) @Test(expectedExceptions = IllegalArgumentException.class)
public void testThrowIllegalArgumentExceptionWhenWhenISpecifyAnOrphanedRegion() { public void testThrowIllegalArgumentExceptionWhenWhenISpecifyAnOrphanedRegion() {
LocationPredicate predicate = new LocationPredicate(Suppliers.ofInstance(orphanedRegion)); NullEqualToIsParentOrIsGrandparentOfCurrentLocation predicate = new NullEqualToIsParentOrIsGrandparentOfCurrentLocation(Suppliers.ofInstance(orphanedRegion));
Hardware md = new HardwareBuilder().id("foo").location(region).build(); Hardware md = new HardwareBuilder().id("foo").location(region).build();
predicate.apply(md); predicate.apply(md);
} }
@ -190,7 +190,7 @@ public class LocationPredicateTest {
*/ */
@Test(expectedExceptions = IllegalArgumentException.class) @Test(expectedExceptions = IllegalArgumentException.class)
public void testThrowIllegalArgumentExceptionWhenWhenISpecifyAnOrphanedZone() { public void testThrowIllegalArgumentExceptionWhenWhenISpecifyAnOrphanedZone() {
LocationPredicate predicate = new LocationPredicate(Suppliers.ofInstance(orphanedZone)); NullEqualToIsParentOrIsGrandparentOfCurrentLocation predicate = new NullEqualToIsParentOrIsGrandparentOfCurrentLocation(Suppliers.ofInstance(orphanedZone));
Hardware md = new HardwareBuilder().id("foo").location(region).build(); Hardware md = new HardwareBuilder().id("foo").location(region).build();
predicate.apply(md); predicate.apply(md);
} }

View File

@ -653,7 +653,7 @@ public class TemplateBuilderImplTest {
assert false; assert false;
} catch (NoSuchElementException e) { } catch (NoSuchElementException e) {
// make sure big data is not in the exception message // make sure big data is not in the exception message
assertEquals(e.getMessage(), "no image matched predicate: And(equalsParentOrGrandparentOfCurrentLocation(),imageDescription(description))"); assertEquals(e.getMessage(), "no image matched predicate: And(nullEqualToIsParentOrIsGrandparentOfCurrentLocation(),imageDescription(description))");
} }
verify(defaultOptions); verify(defaultOptions);