I know this is a test, but how about something like:
```
ImmutableSet.Builder<String> deprecatedMachineTypes = ImmutableSet.builder();
for (MachineType machine : api.getMachineTypeApiForProject(userProject.get())
                                             .listInZone(DEFAULT_ZONE_NAME).concat()) {
   if (input.getDeprecated().isPresent()) {
      deprecatedMachineTypes.add(input.getId());
   }
}
ImmutableSet<String> deprecatedMachineTypeIds = deprecatedMachineTypes.build();
```
?