This repository has been archived by the owner on Mar 21, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 549
Remove unnecessary null checks in AutoValue builders #925
Merged
Merged
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
1057d6f
Add test for ContainerSpec having no Labels or Command
davidxia 1c35401
Remove unnecessary null checks for nullables in ContainerSpec
davidxia 3a3c218
Add test for DnsConfig deserialization without nullables
davidxia bdc8936
Remove unnecessary null checks for nullables in DnsConfig
davidxia e19408b
Add test for Driver deserialization without nullables
davidxia 5cbbd71
Add test for ServiceSpec deserialization without nullables
davidxia ce02740
Remove unnecessary null checks for nullables in ServiceSpec
davidxia f237048
Add test for SwarmInit deserialization without nullables
davidxia 6814694
Remove unnecessary null checks for nullables in SwarmInit
davidxia cb6a3ae
Add test for TaskSpec deserialization without nullables
davidxia 42a163b
Remove unnecessary null checks for nullables in TaskSpec
davidxia File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
47 changes: 47 additions & 0 deletions
47
src/test/java/com/spotify/docker/client/messages/swarm/ContainerSpecTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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())); | ||
} | ||
|
||
} |
53 changes: 53 additions & 0 deletions
53
src/test/java/com/spotify/docker/client/messages/swarm/DnsConfigTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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())); | ||
} | ||
} |
54 changes: 54 additions & 0 deletions
54
src/test/java/com/spotify/docker/client/messages/swarm/DriverTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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.<String, String>emptyMap())); | ||
} | ||
|
||
} |
49 changes: 49 additions & 0 deletions
49
src/test/java/com/spotify/docker/client/messages/swarm/ServiceSpecTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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())); | ||
} | ||
} |
46 changes: 46 additions & 0 deletions
46
src/test/java/com/spotify/docker/client/messages/swarm/SwarmInitTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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())); | ||
} | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The default value set by autovalue is an empty map. If I remove this null check, labels changes from being an empty map to being null. This would be a backwards breaking change. See test here which passes before any changes are made to this class. The test fails if you remove the null check here.
Turns out the default is an empty collection only if you have a builder property that accumulates values.