ensure setting options still uses the default template

This commit is contained in:
Adrian Cole 2010-05-21 15:12:38 -07:00
parent 8940e1cc03
commit 3a1ff2e29c
2 changed files with 32 additions and 4 deletions

View File

@ -394,7 +394,7 @@ public class TemplateBuilderImpl implements TemplateBuilder {
*/
@Override
public Template build() {
if (nothingChanged())
if (nothingChangedExceptOptions())
return defaultTemplateProvider.get().build();
if (locationId == null)
locationId = defaultLocation.getId();
@ -550,11 +550,10 @@ public class TemplateBuilderImpl implements TemplateBuilder {
}
@VisibleForTesting
boolean nothingChanged() {
boolean nothingChangedExceptOptions() {
return os == null && arch == null && locationId == null && imageId == null && sizeId == null
&& osDescription == null && imageVersion == null && imageName == null
&& imageDescription == null && minCores == 0 && minRam == 0 && !biggest && !fastest
&& options == null;
&& imageDescription == null && minCores == 0 && minRam == 0 && !biggest && !fastest;
}
/**

View File

@ -47,6 +47,35 @@ import com.google.common.collect.ImmutableSet;
@Test(groups = "unit")
public class TemplateBuilderImplTest {
@SuppressWarnings("unchecked")
@Test
public void testOptionsUsesDefaultTemplateBuilder() {
Set<Location> locations = ImmutableSet.<Location> of();
Set<Image> images = ImmutableSet.<Image> of();
Set<Size> sizes = ImmutableSet.<Size> of();
Location defaultLocation = createMock(Location.class);
Provider<TemplateOptions> optionsProvider = createMock(Provider.class);
Provider<TemplateBuilder> templateBuilderProvider = createMock(Provider.class);
TemplateBuilder defaultTemplate = createMock(TemplateBuilder.class);
expect(templateBuilderProvider.get()).andReturn(defaultTemplate);
expect(defaultTemplate.build()).andReturn(null);
replay(defaultTemplate);
replay(defaultLocation);
replay(optionsProvider);
replay(templateBuilderProvider);
TemplateBuilderImpl template = createTemplateBuilder(locations, images, sizes,
defaultLocation, optionsProvider, templateBuilderProvider);
template.options(new TemplateOptions()).build();
verify(defaultTemplate);
verify(defaultLocation);
verify(optionsProvider);
verify(templateBuilderProvider);
}
@SuppressWarnings("unchecked")
@Test
public void testNothingUsesDefaultTemplateBuilder() {