From 1057d6f45e16a7bda5e97e680e72ecbb284fde81 Mon Sep 17 00:00:00 2001 From: David Xia Date: Tue, 14 Nov 2017 00:23:21 -0500 Subject: [PATCH 01/11] Add test for ContainerSpec having no Labels or Command --- .../messages/swarm/ContainerSpecTest.java | 47 +++++++++++++++++++ .../1.32/containerSpecWithoutNullables.json | 33 +++++++++++++ 2 files changed, 80 insertions(+) create mode 100644 src/test/java/com/spotify/docker/client/messages/swarm/ContainerSpecTest.java create mode 100644 src/test/resources/fixtures/1.32/containerSpecWithoutNullables.json diff --git a/src/test/java/com/spotify/docker/client/messages/swarm/ContainerSpecTest.java b/src/test/java/com/spotify/docker/client/messages/swarm/ContainerSpecTest.java new file mode 100644 index 000000000..41749c007 --- /dev/null +++ b/src/test/java/com/spotify/docker/client/messages/swarm/ContainerSpecTest.java @@ -0,0 +1,47 @@ +/*- + * -\-\- + * docker-client + * -- + * Copyright (C) 2016 - 2017 Spotify AB + * -- + * Licensed 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 com.spotify.docker.client.messages.swarm; + +import static com.spotify.docker.FixtureUtil.fixture; +import static org.hamcrest.MatcherAssert.assertThat; +import static org.hamcrest.Matchers.equalTo; +import static org.hamcrest.Matchers.is; +import static org.hamcrest.Matchers.nullValue; + +import com.fasterxml.jackson.databind.ObjectMapper; +import com.spotify.docker.client.ObjectMapperProvider; +import org.junit.Test; + +public class ContainerSpecTest { + + private ObjectMapper objectMapper = ObjectMapperProvider.objectMapper(); + + @Test + public void test1_32_WithoutNullables() throws Exception { + final ContainerSpec spec = objectMapper.readValue(fixture( + "fixtures/1.32/containerSpecWithoutNullables.json"), ContainerSpec.class); + assertThat(spec.labels().size(), equalTo(0)); + assertThat(spec.command(), is(nullValue())); + assertThat(spec.secrets(), is(nullValue())); + assertThat(spec.configs(), is(nullValue())); + } + +} \ No newline at end of file diff --git a/src/test/resources/fixtures/1.32/containerSpecWithoutNullables.json b/src/test/resources/fixtures/1.32/containerSpecWithoutNullables.json new file mode 100644 index 000000000..9372f5a95 --- /dev/null +++ b/src/test/resources/fixtures/1.32/containerSpecWithoutNullables.json @@ -0,0 +1,33 @@ +{ + "Image": "nginx:alpine", + "Mounts": [ + { + "ReadOnly": true, + "Source": "web-data", + "Target": "/usr/share/nginx/html", + "Type": "volume", + "VolumeOptions": { + "DriverConfig": { }, + "Labels": { + "com.example.something": "something-value" + } + } + } + ], + "Hosts": [ + "10.10.10.10 host1", + "ABCD:EF01:2345:6789:ABCD:EF01:2345:6789 host2" + ], + "User": "33", + "DNSConfig": { + "Nameservers": [ + "8.8.8.8" + ], + "Search": [ + "example.org" + ], + "Options": [ + "timeout:3" + ] + } +} From 1c3540163814d123292a31256b7eff1b7fddce44 Mon Sep 17 00:00:00 2001 From: David Xia Date: Tue, 14 Nov 2017 11:06:58 -0500 Subject: [PATCH 02/11] Remove unnecessary null checks for nullables in ContainerSpec --- .../client/messages/swarm/ContainerSpec.java | 17 ++++------------- 1 file changed, 4 insertions(+), 13 deletions(-) diff --git a/src/main/java/com/spotify/docker/client/messages/swarm/ContainerSpec.java b/src/main/java/com/spotify/docker/client/messages/swarm/ContainerSpec.java index db3a82ddb..29db35f89 100644 --- a/src/main/java/com/spotify/docker/client/messages/swarm/ContainerSpec.java +++ b/src/main/java/com/spotify/docker/client/messages/swarm/ContainerSpec.java @@ -387,24 +387,15 @@ static ContainerSpec create( .stopGracePeriod(stopGracePeriod) .healthcheck(healthcheck) .hosts(hosts) - .dnsConfig(dnsConfig); + .dnsConfig(dnsConfig) + .command(command) + .secrets(secrets) + .configs(configs); if (labels != null) { builder.labels(labels); } - if (command != null) { - builder.command(command); - } - - if (secrets != null) { - builder.secrets(secrets); - } - - if (configs != null) { - builder.configs(configs); - } - return builder.build(); } } From 3a3c2185a57d4617c3280cc61875cc27366e51bd Mon Sep 17 00:00:00 2001 From: David Xia Date: Tue, 14 Nov 2017 11:14:42 -0500 Subject: [PATCH 03/11] Add test for DnsConfig deserialization without nullables --- .../client/messages/swarm/DnsConfigTest.java | 53 +++++++++++++++++++ .../resources/fixtures/1.32/dnsConfig.json | 11 ++++ 2 files changed, 64 insertions(+) create mode 100644 src/test/java/com/spotify/docker/client/messages/swarm/DnsConfigTest.java create mode 100644 src/test/resources/fixtures/1.32/dnsConfig.json diff --git a/src/test/java/com/spotify/docker/client/messages/swarm/DnsConfigTest.java b/src/test/java/com/spotify/docker/client/messages/swarm/DnsConfigTest.java new file mode 100644 index 000000000..5467c6933 --- /dev/null +++ b/src/test/java/com/spotify/docker/client/messages/swarm/DnsConfigTest.java @@ -0,0 +1,53 @@ +/*- + * -\-\- + * docker-client + * -- + * Copyright (C) 2016 - 2017 Spotify AB + * -- + * Licensed 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 com.spotify.docker.client.messages.swarm; + +import static com.spotify.docker.FixtureUtil.fixture; +import static org.hamcrest.Matchers.contains; +import static org.hamcrest.Matchers.is; +import static org.hamcrest.Matchers.nullValue; +import static org.junit.Assert.assertThat; + +import com.fasterxml.jackson.databind.ObjectMapper; +import com.spotify.docker.client.ObjectMapperProvider; +import org.junit.Test; + +public class DnsConfigTest { + + private ObjectMapper objectMapper = ObjectMapperProvider.objectMapper(); + + @Test + public void test1_32() throws Exception { + final DnsConfig config = objectMapper.readValue(fixture( + "fixtures/1.32/dnsConfig.json"), DnsConfig.class); + assertThat(config.nameServers(), contains("8.8.8.8")); + assertThat(config.search(), contains("example.org")); + assertThat(config.options(), contains("timeout:3")); + } + + @Test + public void test1_32_WithoutNullables() throws Exception { + final DnsConfig config = objectMapper.readValue("{}", DnsConfig.class); + assertThat(config.nameServers(), is(nullValue())); + assertThat(config.search(), is(nullValue())); + assertThat(config.options(), is(nullValue())); + } +} \ No newline at end of file diff --git a/src/test/resources/fixtures/1.32/dnsConfig.json b/src/test/resources/fixtures/1.32/dnsConfig.json new file mode 100644 index 000000000..1b7d8e04c --- /dev/null +++ b/src/test/resources/fixtures/1.32/dnsConfig.json @@ -0,0 +1,11 @@ +{ + "Nameservers": [ + "8.8.8.8" + ], + "Search": [ + "example.org" + ], + "Options": [ + "timeout:3" + ] +} From bdc8936b04a4e4ee319c88fa31c4caf5a7a48aec Mon Sep 17 00:00:00 2001 From: David Xia Date: Tue, 14 Nov 2017 11:14:52 -0500 Subject: [PATCH 04/11] Remove unnecessary null checks for nullables in DnsConfig --- .../docker/client/messages/swarm/DnsConfig.java | 16 +++++----------- 1 file changed, 5 insertions(+), 11 deletions(-) diff --git a/src/main/java/com/spotify/docker/client/messages/swarm/DnsConfig.java b/src/main/java/com/spotify/docker/client/messages/swarm/DnsConfig.java index da0556fe5..ec45a4675 100644 --- a/src/main/java/com/spotify/docker/client/messages/swarm/DnsConfig.java +++ b/src/main/java/com/spotify/docker/client/messages/swarm/DnsConfig.java @@ -77,17 +77,11 @@ static DnsConfig create( @JsonProperty("Nameservers") final List nameServers, @JsonProperty("Search") final List search, @JsonProperty("Options") final List options) { - final Builder builder = builder(); - if (nameServers != null) { - builder.nameServers(nameServers); - } - if (search != null) { - builder.search(search); - } - if (options != null) { - builder.options(options); - } - return builder.build(); + return builder() + .nameServers(nameServers) + .search(search) + .options(options) + .build(); } } From e19408b5872f68f80e7fad1717d2bb7fc91a8cb8 Mon Sep 17 00:00:00 2001 From: David Xia Date: Tue, 14 Nov 2017 11:22:47 -0500 Subject: [PATCH 05/11] Add test for Driver deserialization without nullables --- .../client/messages/swarm/DriverTest.java | 54 +++++++++++++++++++ src/test/resources/fixtures/1.32/driver.json | 7 +++ 2 files changed, 61 insertions(+) create mode 100644 src/test/java/com/spotify/docker/client/messages/swarm/DriverTest.java create mode 100644 src/test/resources/fixtures/1.32/driver.json diff --git a/src/test/java/com/spotify/docker/client/messages/swarm/DriverTest.java b/src/test/java/com/spotify/docker/client/messages/swarm/DriverTest.java new file mode 100644 index 000000000..17af05e91 --- /dev/null +++ b/src/test/java/com/spotify/docker/client/messages/swarm/DriverTest.java @@ -0,0 +1,54 @@ +/*- + * -\-\- + * docker-client + * -- + * Copyright (C) 2016 - 2017 Spotify AB + * -- + * Licensed 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 com.spotify.docker.client.messages.swarm; + +import static com.spotify.docker.FixtureUtil.fixture; +import static org.hamcrest.Matchers.equalTo; +import static org.hamcrest.Matchers.is; +import static org.hamcrest.Matchers.nullValue; +import static org.junit.Assert.assertThat; + +import com.fasterxml.jackson.databind.ObjectMapper; +import com.google.common.collect.ImmutableMap; +import com.spotify.docker.client.ObjectMapperProvider; +import java.util.Collections; +import org.junit.Test; + +public class DriverTest { + + private ObjectMapper objectMapper = ObjectMapperProvider.objectMapper(); + + @Test + public void test1_32() throws Exception { + final Driver driver = objectMapper.readValue(fixture( + "fixtures/1.32/driver.json"), Driver.class); + assertThat(driver.name(), equalTo("my-driver")); + assertThat(driver.options(), equalTo(ImmutableMap.of("1", "A", "2", "B"))); + } + + @Test + public void test1_32_WithoutNullables() throws Exception { + final Driver driver = objectMapper.readValue("{}", Driver.class); + assertThat(driver.name(), is(nullValue())); + assertThat(driver.options(), is(Collections.emptyMap())); + } + +} \ No newline at end of file diff --git a/src/test/resources/fixtures/1.32/driver.json b/src/test/resources/fixtures/1.32/driver.json new file mode 100644 index 000000000..352541efe --- /dev/null +++ b/src/test/resources/fixtures/1.32/driver.json @@ -0,0 +1,7 @@ +{ + "Name": "my-driver", + "Options": { + "1": "A", + "2": "B" + } +} \ No newline at end of file From 5cbbd71cc6b3e9424ec158df2d55c50547d77c42 Mon Sep 17 00:00:00 2001 From: David Xia Date: Tue, 14 Nov 2017 11:30:26 -0500 Subject: [PATCH 06/11] Add test for ServiceSpec deserialization without nullables --- .../messages/swarm/ServiceSpecTest.java | 49 +++++++++++++ .../1.32/serviceSpecWithoutNullables.json | 68 +++++++++++++++++++ 2 files changed, 117 insertions(+) create mode 100644 src/test/java/com/spotify/docker/client/messages/swarm/ServiceSpecTest.java create mode 100644 src/test/resources/fixtures/1.32/serviceSpecWithoutNullables.json diff --git a/src/test/java/com/spotify/docker/client/messages/swarm/ServiceSpecTest.java b/src/test/java/com/spotify/docker/client/messages/swarm/ServiceSpecTest.java new file mode 100644 index 000000000..2ea68c5e3 --- /dev/null +++ b/src/test/java/com/spotify/docker/client/messages/swarm/ServiceSpecTest.java @@ -0,0 +1,49 @@ +/*- + * -\-\- + * docker-client + * -- + * Copyright (C) 2016 - 2017 Spotify AB + * -- + * Licensed 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 com.spotify.docker.client.messages.swarm; + +import static com.spotify.docker.FixtureUtil.fixture; +import static org.hamcrest.Matchers.is; +import static org.hamcrest.Matchers.notNullValue; +import static org.hamcrest.Matchers.nullValue; +import static org.junit.Assert.assertThat; + +import com.fasterxml.jackson.databind.ObjectMapper; +import com.spotify.docker.client.ObjectMapperProvider; +import org.junit.Test; + +public class ServiceSpecTest { + + private ObjectMapper objectMapper = ObjectMapperProvider.objectMapper(); + + @Test + public void test1_32_WithoutNullables() throws Exception { + final ServiceSpec spec = objectMapper.readValue(fixture( + "fixtures/1.32/serviceSpecWithoutNullables.json"), ServiceSpec.class); + assertThat(spec.name(), is(nullValue())); + assertThat(spec.labels(), is(nullValue())); + assertThat(spec.taskTemplate(), is(notNullValue())); + assertThat(spec.mode(), is(nullValue())); + assertThat(spec.updateConfig(), is(nullValue())); + assertThat(spec.networks(), is(nullValue())); + assertThat(spec.endpointSpec(), is(nullValue())); + } +} diff --git a/src/test/resources/fixtures/1.32/serviceSpecWithoutNullables.json b/src/test/resources/fixtures/1.32/serviceSpecWithoutNullables.json new file mode 100644 index 000000000..7d99bb4d7 --- /dev/null +++ b/src/test/resources/fixtures/1.32/serviceSpecWithoutNullables.json @@ -0,0 +1,68 @@ +{ + "TaskTemplate": { + "ContainerSpec": { + "Image": "nginx:alpine", + "Mounts": [ + { + "ReadOnly": true, + "Source": "web-data", + "Target": "/usr/share/nginx/html", + "Type": "volume", + "VolumeOptions": { + "DriverConfig": {}, + "Labels": { + "com.example.something": "something-value" + } + } + } + ], + "Hosts": [ + "10.10.10.10 host1", + "ABCD:EF01:2345:6789:ABCD:EF01:2345:6789 host2" + ], + "User": "33", + "DNSConfig": { + "Nameservers": [ + "8.8.8.8" + ], + "Search": [ + "example.org" + ], + "Options": [ + "timeout:3" + ] + }, + "Secrets": [ + { + "File": { + "Name": "www.example.org.key", + "UID": "33", + "GID": "33", + "Mode": 384 + }, + "SecretID": "fpjqlhnwb19zds35k8wn80lq9", + "SecretName": "example_org_domain_key" + } + ] + }, + "LogDriver": { + "Name": "json-file", + "Options": { + "max-file": "3", + "max-size": "10M" + } + }, + "Placement": {}, + "Resources": { + "Limits": { + "MemoryBytes": 104857600 + }, + "Reservations": {} + }, + "RestartPolicy": { + "Condition": "on-failure", + "Delay": 10000000000, + "MaxAttempts": 10 + } + } +} From ce027406c4acdcb82f68f5b0a9291a4b52830286 Mon Sep 17 00:00:00 2001 From: David Xia Date: Tue, 14 Nov 2017 11:31:00 -0500 Subject: [PATCH 07/11] Remove unnecessary null checks for nullables in ServiceSpec --- .../client/messages/swarm/ServiceSpec.java | 16 +++++----------- 1 file changed, 5 insertions(+), 11 deletions(-) diff --git a/src/main/java/com/spotify/docker/client/messages/swarm/ServiceSpec.java b/src/main/java/com/spotify/docker/client/messages/swarm/ServiceSpec.java index 408691410..f4bd1e207 100644 --- a/src/main/java/com/spotify/docker/client/messages/swarm/ServiceSpec.java +++ b/src/main/java/com/spotify/docker/client/messages/swarm/ServiceSpec.java @@ -188,21 +188,15 @@ static ServiceSpec create( @JsonProperty("UpdateConfig") final UpdateConfig updateConfig, @JsonProperty("Networks") final List networks, @JsonProperty("EndpointSpec") final EndpointSpec endpointSpec) { - final Builder builder = builder() + return builder() .name(name) .labels(labels) .taskTemplate(taskTemplate) .mode(mode) .updateConfig(updateConfig) - .endpointSpec(endpointSpec); - - if (labels != null) { - builder.labels(labels); - } - if (networks != null) { - builder.networks(networks); - } - - return builder.build(); + .endpointSpec(endpointSpec) + .labels(labels) + .networks(networks) + .build(); } } From f2370480832521d8e02a477fa75b91ca77582e46 Mon Sep 17 00:00:00 2001 From: David Xia Date: Tue, 14 Nov 2017 11:34:03 -0500 Subject: [PATCH 08/11] Add test for SwarmInit deserialization without nullables --- .../client/messages/swarm/SwarmInitTest.java | 46 +++++++++++++++++++ .../1.32/swarmInitWithoutNullables.json | 4 ++ 2 files changed, 50 insertions(+) create mode 100644 src/test/java/com/spotify/docker/client/messages/swarm/SwarmInitTest.java create mode 100644 src/test/resources/fixtures/1.32/swarmInitWithoutNullables.json diff --git a/src/test/java/com/spotify/docker/client/messages/swarm/SwarmInitTest.java b/src/test/java/com/spotify/docker/client/messages/swarm/SwarmInitTest.java new file mode 100644 index 000000000..d1ea9613b --- /dev/null +++ b/src/test/java/com/spotify/docker/client/messages/swarm/SwarmInitTest.java @@ -0,0 +1,46 @@ +/*- + * -\-\- + * docker-client + * -- + * Copyright (C) 2016 - 2017 Spotify AB + * -- + * Licensed 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 com.spotify.docker.client.messages.swarm; + +import static com.spotify.docker.FixtureUtil.fixture; +import static org.hamcrest.Matchers.equalTo; +import static org.hamcrest.Matchers.is; +import static org.hamcrest.Matchers.nullValue; +import static org.junit.Assert.assertThat; + +import com.fasterxml.jackson.databind.ObjectMapper; +import com.spotify.docker.client.ObjectMapperProvider; +import org.junit.Test; + +public class SwarmInitTest { + + private ObjectMapper objectMapper = ObjectMapperProvider.objectMapper(); + + @Test + public void test1_32_WithoutNullables() throws Exception { + final SwarmInit init = objectMapper.readValue(fixture( + "fixtures/1.32/swarmInitWithoutNullables.json"), SwarmInit.class); + assertThat(init.listenAddr(), equalTo("0.0.0.0:2377")); + assertThat(init.advertiseAddr(), equalTo("192.168.1.1:2377")); + assertThat(init.forceNewCluster(), is(nullValue())); + assertThat(init.swarmSpec(), is(nullValue())); + } +} \ No newline at end of file diff --git a/src/test/resources/fixtures/1.32/swarmInitWithoutNullables.json b/src/test/resources/fixtures/1.32/swarmInitWithoutNullables.json new file mode 100644 index 000000000..32545ba68 --- /dev/null +++ b/src/test/resources/fixtures/1.32/swarmInitWithoutNullables.json @@ -0,0 +1,4 @@ +{ + "ListenAddr": "0.0.0.0:2377", + "AdvertiseAddr": "192.168.1.1:2377" +} \ No newline at end of file From 6814694a16d7fc8653c12dfbe3729a2501b2a338 Mon Sep 17 00:00:00 2001 From: David Xia Date: Tue, 14 Nov 2017 11:34:37 -0500 Subject: [PATCH 09/11] Remove unnecessary null checks for nullables in SwarmInit --- .../docker/client/messages/swarm/SwarmInit.java | 13 ++++--------- 1 file changed, 4 insertions(+), 9 deletions(-) diff --git a/src/main/java/com/spotify/docker/client/messages/swarm/SwarmInit.java b/src/main/java/com/spotify/docker/client/messages/swarm/SwarmInit.java index 80557474a..38868609f 100644 --- a/src/main/java/com/spotify/docker/client/messages/swarm/SwarmInit.java +++ b/src/main/java/com/spotify/docker/client/messages/swarm/SwarmInit.java @@ -71,16 +71,11 @@ static SwarmInit create( @JsonProperty("AdvertiseAddr") final String advertiseAddr, @JsonProperty("ForceNewCluster") final Boolean forceNewCluster, @JsonProperty("Spec") final SwarmSpec swarmSpec) { - final Builder builder = builder() + return builder() .listenAddr(listenAddr) .advertiseAddr(advertiseAddr) - .forceNewCluster(forceNewCluster); - - if (swarmSpec != null) { - builder.swarmSpec(swarmSpec); - } - - return builder.build(); - + .forceNewCluster(forceNewCluster) + .swarmSpec(swarmSpec) + .build(); } } From cb6a3ae73466aebe93db84ca65e43276cb5db887 Mon Sep 17 00:00:00 2001 From: David Xia Date: Tue, 14 Nov 2017 11:38:07 -0500 Subject: [PATCH 10/11] Add test for TaskSpec deserialization without nullables --- .../client/messages/swarm/TaskSpecTest.java | 45 +++++++++++++++++++ 1 file changed, 45 insertions(+) create mode 100644 src/test/java/com/spotify/docker/client/messages/swarm/TaskSpecTest.java diff --git a/src/test/java/com/spotify/docker/client/messages/swarm/TaskSpecTest.java b/src/test/java/com/spotify/docker/client/messages/swarm/TaskSpecTest.java new file mode 100644 index 000000000..716d10bdb --- /dev/null +++ b/src/test/java/com/spotify/docker/client/messages/swarm/TaskSpecTest.java @@ -0,0 +1,45 @@ +/*- + * -\-\- + * docker-client + * -- + * Copyright (C) 2016 - 2017 Spotify AB + * -- + * Licensed 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 com.spotify.docker.client.messages.swarm; + +import static org.hamcrest.Matchers.is; +import static org.hamcrest.Matchers.nullValue; +import static org.junit.Assert.assertThat; + +import com.fasterxml.jackson.databind.ObjectMapper; +import com.spotify.docker.client.ObjectMapperProvider; +import org.junit.Test; + +public class TaskSpecTest { + + private ObjectMapper objectMapper = ObjectMapperProvider.objectMapper(); + + @Test + public void test1_32_WithoutNullables() throws Exception { + final TaskSpec spec = objectMapper.readValue("{}", TaskSpec.class); + assertThat(spec.containerSpec(), is(nullValue())); + assertThat(spec.resources(), is(nullValue())); + assertThat(spec.restartPolicy(), is(nullValue())); + assertThat(spec.placement(), is(nullValue())); + assertThat(spec.networks(), is(nullValue())); + assertThat(spec.logDriver(), is(nullValue())); + } +} \ No newline at end of file From 42a163bad892cdfd66cd0bbc6cbcae0a79090971 Mon Sep 17 00:00:00 2001 From: David Xia Date: Tue, 14 Nov 2017 11:38:15 -0500 Subject: [PATCH 11/11] Remove unnecessary null checks for nullables in TaskSpec --- .../docker/client/messages/swarm/TaskSpec.java | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/src/main/java/com/spotify/docker/client/messages/swarm/TaskSpec.java b/src/main/java/com/spotify/docker/client/messages/swarm/TaskSpec.java index f7a390ea7..302bf6ee7 100644 --- a/src/main/java/com/spotify/docker/client/messages/swarm/TaskSpec.java +++ b/src/main/java/com/spotify/docker/client/messages/swarm/TaskSpec.java @@ -159,17 +159,13 @@ static TaskSpec create( @JsonProperty("Placement") final Placement placement, @JsonProperty("Networks") final List networks, @JsonProperty("LogDriver") final Driver logDriver) { - final Builder builder = builder() + return builder() .containerSpec(containerSpec) .resources(resources) .restartPolicy(restartPolicy) .placement(placement) - .logDriver(logDriver); - - if (networks != null) { - builder.networks(networks); - } - - return builder.build(); + .logDriver(logDriver) + .networks(networks) + .build(); } }