Skip to content

Commit

Permalink
Use TO_PB_FUNCTION when possible in ComputeImplTest
Browse files Browse the repository at this point in the history
  • Loading branch information
mziccard committed Mar 22, 2016
1 parent 3e9c62e commit e541400
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 121 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,6 @@
package com.google.gcloud.compute;

import static com.google.common.base.Preconditions.checkNotNull;
import static com.google.gcloud.compute.OperationId.Type.REGION;
import static com.google.gcloud.compute.OperationId.Type.ZONE;

import com.google.common.base.Function;
import com.google.common.base.MoreObjects;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -319,6 +319,15 @@ public class ComputeImplTest {
private static final Compute.AddressAggregatedListOption ADDRESS_AGGREGATED_LIST_FILTER =
Compute.AddressAggregatedListOption.filter(ADDRESS_FILTER);

private static final Function<Operation, com.google.api.services.compute.model.Operation>
OPERATION_TO_PB_FUNCTION = new Function<Operation,
com.google.api.services.compute.model.Operation>() {
@Override
public com.google.api.services.compute.model.Operation apply(Operation operation) {
return operation.toPb();
}
};

private ComputeOptions options;
private ComputeRpcFactory rpcFactoryMock;
private ComputeRpc computeRpcMock;
Expand Down Expand Up @@ -1130,13 +1139,7 @@ public void testListGlobalOperations() {
compute = options.service();
ImmutableList<Operation> operationList = ImmutableList.of(globalOperation, globalOperation);
Tuple<String, Iterable<com.google.api.services.compute.model.Operation>> result =
Tuple.of(cursor, Iterables.transform(operationList,
new Function<Operation, com.google.api.services.compute.model.Operation>() {
@Override
public com.google.api.services.compute.model.Operation apply(Operation operation) {
return operation.toPb();
}
}));
Tuple.of(cursor, Iterables.transform(operationList, OPERATION_TO_PB_FUNCTION));
EasyMock.expect(computeRpcMock.listGlobalOperations(EMPTY_RPC_OPTIONS)).andReturn(result);
EasyMock.replay(computeRpcMock);
Page<Operation> page = compute.listGlobalOperations();
Expand All @@ -1152,21 +1155,9 @@ public void testListGlobalOperationsNextPage() {
ImmutableList<Operation> operationList = ImmutableList.of(globalOperation, globalOperation);
ImmutableList<Operation> nextOperationList = ImmutableList.of(globalOperation);
Tuple<String, Iterable<com.google.api.services.compute.model.Operation>> result =
Tuple.of(cursor, Iterables.transform(operationList,
new Function<Operation, com.google.api.services.compute.model.Operation>() {
@Override
public com.google.api.services.compute.model.Operation apply(Operation operation) {
return operation.toPb();
}
}));
Tuple.of(cursor, Iterables.transform(operationList, OPERATION_TO_PB_FUNCTION));
Tuple<String, Iterable<com.google.api.services.compute.model.Operation>> nextResult =
Tuple.of(nextCursor, Iterables.transform(nextOperationList,
new Function<Operation, com.google.api.services.compute.model.Operation>() {
@Override
public com.google.api.services.compute.model.Operation apply(Operation operation) {
return operation.toPb();
}
}));
Tuple.of(nextCursor, Iterables.transform(nextOperationList, OPERATION_TO_PB_FUNCTION));
Map<ComputeRpc.Option, ?> nextOptions = ImmutableMap.of(PAGE_TOKEN, cursor);
EasyMock.expect(computeRpcMock.listGlobalOperations(EMPTY_RPC_OPTIONS)).andReturn(result);
EasyMock.expect(computeRpcMock.listGlobalOperations(nextOptions)).andReturn(nextResult);
Expand Down Expand Up @@ -1200,13 +1191,7 @@ public void testListGlobalOperationsWithOptions() {
compute = options.service();
ImmutableList<Operation> operationList = ImmutableList.of(globalOperation, globalOperation);
Tuple<String, Iterable<com.google.api.services.compute.model.Operation>> result =
Tuple.of(cursor, Iterables.transform(operationList,
new Function<Operation, com.google.api.services.compute.model.Operation>() {
@Override
public com.google.api.services.compute.model.Operation apply(Operation operation) {
return operation.toPb();
}
}));
Tuple.of(cursor, Iterables.transform(operationList, OPERATION_TO_PB_FUNCTION));
EasyMock.expect(computeRpcMock.listGlobalOperations(OPERATION_LIST_OPTIONS)).andReturn(result);
EasyMock.replay(computeRpcMock);
Page<Operation> page = compute.listGlobalOperations(OPERATION_LIST_PAGE_SIZE,
Expand Down Expand Up @@ -1278,13 +1263,7 @@ public void testListRegionOperations() {
compute = options.service();
ImmutableList<Operation> operationList = ImmutableList.of(regionOperation, regionOperation);
Tuple<String, Iterable<com.google.api.services.compute.model.Operation>> result =
Tuple.of(cursor, Iterables.transform(operationList,
new Function<Operation, com.google.api.services.compute.model.Operation>() {
@Override
public com.google.api.services.compute.model.Operation apply(Operation operation) {
return operation.toPb();
}
}));
Tuple.of(cursor, Iterables.transform(operationList, OPERATION_TO_PB_FUNCTION));
EasyMock.expect(
computeRpcMock.listRegionOperations(REGION_OPERATION_ID.region(), EMPTY_RPC_OPTIONS))
.andReturn(result);
Expand All @@ -1302,21 +1281,9 @@ public void testListRegionOperationsNextPage() {
ImmutableList<Operation> operationList = ImmutableList.of(regionOperation, regionOperation);
ImmutableList<Operation> nextOperationList = ImmutableList.of(regionOperation);
Tuple<String, Iterable<com.google.api.services.compute.model.Operation>> result =
Tuple.of(cursor, Iterables.transform(operationList,
new Function<Operation, com.google.api.services.compute.model.Operation>() {
@Override
public com.google.api.services.compute.model.Operation apply(Operation operation) {
return operation.toPb();
}
}));
Tuple.of(cursor, Iterables.transform(operationList, OPERATION_TO_PB_FUNCTION));
Tuple<String, Iterable<com.google.api.services.compute.model.Operation>> nextResult =
Tuple.of(nextCursor, Iterables.transform(nextOperationList,
new Function<Operation, com.google.api.services.compute.model.Operation>() {
@Override
public com.google.api.services.compute.model.Operation apply(Operation operation) {
return operation.toPb();
}
}));
Tuple.of(nextCursor, Iterables.transform(nextOperationList, OPERATION_TO_PB_FUNCTION));
Map<ComputeRpc.Option, ?> nextOptions = ImmutableMap.of(PAGE_TOKEN, cursor);
EasyMock.expect(computeRpcMock.listRegionOperations(REGION_OPERATION_ID.region(),
EMPTY_RPC_OPTIONS)).andReturn(result);
Expand Down Expand Up @@ -1354,13 +1321,7 @@ public void testListRegionOperationsWithOptions() {
compute = options.service();
ImmutableList<Operation> operationList = ImmutableList.of(regionOperation, regionOperation);
Tuple<String, Iterable<com.google.api.services.compute.model.Operation>> result =
Tuple.of(cursor, Iterables.transform(operationList,
new Function<Operation, com.google.api.services.compute.model.Operation>() {
@Override
public com.google.api.services.compute.model.Operation apply(Operation operation) {
return operation.toPb();
}
}));
Tuple.of(cursor, Iterables.transform(operationList, OPERATION_TO_PB_FUNCTION));
EasyMock.expect(
computeRpcMock.listRegionOperations(REGION_OPERATION_ID.region(), OPERATION_LIST_OPTIONS))
.andReturn(result);
Expand Down Expand Up @@ -1431,13 +1392,7 @@ public void testListZoneOperations() {
compute = options.service();
ImmutableList<Operation> operationList = ImmutableList.of(zoneOperation, zoneOperation);
Tuple<String, Iterable<com.google.api.services.compute.model.Operation>> result =
Tuple.of(cursor, Iterables.transform(operationList,
new Function<Operation, com.google.api.services.compute.model.Operation>() {
@Override
public com.google.api.services.compute.model.Operation apply(Operation operation) {
return operation.toPb();
}
}));
Tuple.of(cursor, Iterables.transform(operationList, OPERATION_TO_PB_FUNCTION));
EasyMock.expect(
computeRpcMock.listZoneOperations(ZONE_OPERATION_ID.zone(), EMPTY_RPC_OPTIONS))
.andReturn(result);
Expand All @@ -1455,21 +1410,9 @@ public void testListZoneOperationsNextPage() {
ImmutableList<Operation> operationList = ImmutableList.of(zoneOperation, zoneOperation);
ImmutableList<Operation> nextOperationList = ImmutableList.of(zoneOperation);
Tuple<String, Iterable<com.google.api.services.compute.model.Operation>> result =
Tuple.of(cursor, Iterables.transform(operationList,
new Function<Operation, com.google.api.services.compute.model.Operation>() {
@Override
public com.google.api.services.compute.model.Operation apply(Operation operation) {
return operation.toPb();
}
}));
Tuple.of(cursor, Iterables.transform(operationList, OPERATION_TO_PB_FUNCTION));
Tuple<String, Iterable<com.google.api.services.compute.model.Operation>> nextResult =
Tuple.of(nextCursor, Iterables.transform(nextOperationList,
new Function<Operation, com.google.api.services.compute.model.Operation>() {
@Override
public com.google.api.services.compute.model.Operation apply(Operation operation) {
return operation.toPb();
}
}));
Tuple.of(nextCursor, Iterables.transform(nextOperationList, OPERATION_TO_PB_FUNCTION));
Map<ComputeRpc.Option, ?> nextOptions = ImmutableMap.of(PAGE_TOKEN, cursor);
EasyMock.expect(computeRpcMock.listZoneOperations(ZONE_OPERATION_ID.zone(), EMPTY_RPC_OPTIONS))
.andReturn(result);
Expand Down Expand Up @@ -1507,13 +1450,7 @@ public void testListZoneOperationsWithOptions() {
compute = options.service();
ImmutableList<Operation> operationList = ImmutableList.of(zoneOperation, zoneOperation);
Tuple<String, Iterable<com.google.api.services.compute.model.Operation>> result =
Tuple.of(cursor, Iterables.transform(operationList,
new Function<Operation, com.google.api.services.compute.model.Operation>() {
@Override
public com.google.api.services.compute.model.Operation apply(Operation operation) {
return operation.toPb();
}
}));
Tuple.of(cursor, Iterables.transform(operationList, OPERATION_TO_PB_FUNCTION));
EasyMock.expect(
computeRpcMock.listZoneOperations(ZONE_OPERATION_ID.zone(), OPERATION_LIST_OPTIONS))
.andReturn(result);
Expand Down Expand Up @@ -1713,21 +1650,9 @@ public void testListGlobalAddressesNextPage() {
ImmutableList<Address> nextAddressList = ImmutableList.of(
new Address(compute, new AddressInfo.BuilderImpl(GLOBAL_ADDRESS)));
Tuple<String, Iterable<com.google.api.services.compute.model.Address>> result =
Tuple.of(cursor, Iterables.transform(addressList,
new Function<Address, com.google.api.services.compute.model.Address>() {
@Override
public com.google.api.services.compute.model.Address apply(Address address) {
return address.toPb();
}
}));
Tuple.of(cursor, Iterables.transform(addressList, AddressInfo.TO_PB_FUNCTION));
Tuple<String, Iterable<com.google.api.services.compute.model.Address>> nextResult =
Tuple.of(nextCursor, Iterables.transform(nextAddressList,
new Function<Address, com.google.api.services.compute.model.Address>() {
@Override
public com.google.api.services.compute.model.Address apply(Address address) {
return address.toPb();
}
}));
Tuple.of(nextCursor, Iterables.transform(nextAddressList, AddressInfo.TO_PB_FUNCTION));
Map<ComputeRpc.Option, ?> nextOptions = ImmutableMap.of(PAGE_TOKEN, cursor);
EasyMock.expect(computeRpcMock.listGlobalAddresses(EMPTY_RPC_OPTIONS)).andReturn(result);
EasyMock.expect(computeRpcMock.listGlobalAddresses(nextOptions)).andReturn(nextResult);
Expand Down Expand Up @@ -1778,13 +1703,7 @@ public void testListRegionAddresses() {
new Address(compute, new AddressInfo.BuilderImpl(REGION_ADDRESS)),
new Address(compute, new AddressInfo.BuilderImpl(REGION_ADDRESS)));
Tuple<String, Iterable<com.google.api.services.compute.model.Address>> result =
Tuple.of(cursor, Iterables.transform(addressList,
new Function<Address, com.google.api.services.compute.model.Address>() {
@Override
public com.google.api.services.compute.model.Address apply(Address address) {
return address.toPb();
}
}));
Tuple.of(cursor, Iterables.transform(addressList, AddressInfo.TO_PB_FUNCTION));
EasyMock.expect(
computeRpcMock.listRegionAddresses(REGION_ADDRESS_ID.region(), EMPTY_RPC_OPTIONS))
.andReturn(result);
Expand All @@ -1805,21 +1724,9 @@ public void testListRegionAddressesNextPage() {
ImmutableList<Address> nextAddressList = ImmutableList.of(
new Address(compute, new AddressInfo.BuilderImpl(REGION_ADDRESS)));
Tuple<String, Iterable<com.google.api.services.compute.model.Address>> result =
Tuple.of(cursor, Iterables.transform(addressList,
new Function<Address, com.google.api.services.compute.model.Address>() {
@Override
public com.google.api.services.compute.model.Address apply(Address address) {
return address.toPb();
}
}));
Tuple.of(cursor, Iterables.transform(addressList, AddressInfo.TO_PB_FUNCTION));
Tuple<String, Iterable<com.google.api.services.compute.model.Address>> nextResult =
Tuple.of(nextCursor, Iterables.transform(nextAddressList,
new Function<Address, com.google.api.services.compute.model.Address>() {
@Override
public com.google.api.services.compute.model.Address apply(Address address) {
return address.toPb();
}
}));
Tuple.of(nextCursor, Iterables.transform(nextAddressList, AddressInfo.TO_PB_FUNCTION));
Map<ComputeRpc.Option, ?> nextOptions = ImmutableMap.of(PAGE_TOKEN, cursor);
EasyMock.expect(
computeRpcMock.listRegionAddresses(REGION_ADDRESS_ID.region(), EMPTY_RPC_OPTIONS))
Expand Down

0 comments on commit e541400

Please sign in to comment.