From 1fc5806ec9fdae248b9e7de5267d52eb8b09d193 Mon Sep 17 00:00:00 2001 From: JoshVote Date: Tue, 10 Sep 2013 16:22:04 +0800 Subject: [PATCH] JCLOUDS-277: Made the description in org.jclouds.compute.domain.Image nullable --- .../org/jclouds/compute/domain/Image.java | 2 + .../jclouds/compute/domain/ImageBuilder.java | 4 +- .../compute/domain/internal/ImageImpl.java | 4 +- .../compute/domain/ImageBuilderTest.java | 42 +++++++++++++++++++ 4 files changed, 48 insertions(+), 4 deletions(-) create mode 100644 compute/src/test/java/org/jclouds/compute/domain/ImageBuilderTest.java diff --git a/compute/src/main/java/org/jclouds/compute/domain/Image.java b/compute/src/main/java/org/jclouds/compute/domain/Image.java index c7b42100ab..260b4a7818 100644 --- a/compute/src/main/java/org/jclouds/compute/domain/Image.java +++ b/compute/src/main/java/org/jclouds/compute/domain/Image.java @@ -18,6 +18,7 @@ package org.jclouds.compute.domain; import org.jclouds.compute.domain.internal.ImageImpl; import org.jclouds.domain.LoginCredentials; +import org.jclouds.javax.annotation.Nullable; import com.google.common.annotations.Beta; import com.google.inject.ImplementedBy; @@ -68,6 +69,7 @@ public interface Image extends ComputeMetadataIncludingStatus { /** * Description of the image. */ + @Nullable String getDescription(); /** diff --git a/compute/src/main/java/org/jclouds/compute/domain/ImageBuilder.java b/compute/src/main/java/org/jclouds/compute/domain/ImageBuilder.java index a35bd93c35..3c19c0cbe3 100644 --- a/compute/src/main/java/org/jclouds/compute/domain/ImageBuilder.java +++ b/compute/src/main/java/org/jclouds/compute/domain/ImageBuilder.java @@ -62,8 +62,8 @@ public class ImageBuilder extends ComputeMetadataBuilder { return this; } - public ImageBuilder description(String description) { - this.description = checkNotNull(description, "description"); + public ImageBuilder description(@Nullable String description) { + this.description = description; return this; } diff --git a/compute/src/main/java/org/jclouds/compute/domain/internal/ImageImpl.java b/compute/src/main/java/org/jclouds/compute/domain/internal/ImageImpl.java index ddb23df308..7de3c7720e 100644 --- a/compute/src/main/java/org/jclouds/compute/domain/internal/ImageImpl.java +++ b/compute/src/main/java/org/jclouds/compute/domain/internal/ImageImpl.java @@ -46,14 +46,14 @@ public class ImageImpl extends ComputeMetadataImpl implements Image { public ImageImpl(String providerId, String name, String id, Location location, URI uri, Map userMetadata, Set tags, OperatingSystem operatingSystem, Image.Status status, - @Nullable String backendStatus, String description, @Nullable String version, + @Nullable String backendStatus, @Nullable String description, @Nullable String version, @Nullable LoginCredentials defaultCredentials) { super(ComputeType.IMAGE, providerId, name, id, location, uri, userMetadata, tags); this.operatingSystem = checkNotNull(operatingSystem, "operatingSystem"); this.status = checkNotNull(status, "status"); this.backendStatus = backendStatus; this.version = version; - this.description = checkNotNull(description, "description"); + this.description = description; this.defaultCredentials = defaultCredentials; } diff --git a/compute/src/test/java/org/jclouds/compute/domain/ImageBuilderTest.java b/compute/src/test/java/org/jclouds/compute/domain/ImageBuilderTest.java new file mode 100644 index 0000000000..c1f60d8433 --- /dev/null +++ b/compute/src/test/java/org/jclouds/compute/domain/ImageBuilderTest.java @@ -0,0 +1,42 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.jclouds.compute.domain; + +import static org.testng.Assert.assertNull; + +import org.jclouds.compute.domain.Image.Status; +import org.testng.annotations.Test; + +/** + * Unit tests for org.jclouds.compute.domain.ImageBuilder + * + */ +@Test(testName = "ImageBuilderTest") +public class ImageBuilderTest { + + /** + * Ensures that an explicitly set null Image description results in no errors. + */ + public void testNullDescription() { + Image img = new ImageBuilder().id("test-id") + .description(null) + .status(Status.AVAILABLE) + .operatingSystem(new OperatingSystem(OsFamily.CLOUD_LINUX, null, null, null, "os-description", true)) + .build(); + assertNull(img.getDescription()); + } +}