Delete some dead Apple/Xcode code in Bazel.
`Interspersing` was only used in one place in a test, so I've inlined it. The rest of the deleted code had no uses anywhere.
PiperOrigin-RevId: 625759063
Change-Id: I69a2e2bff69e16077497c9fbab47cf3ae47f1235
diff --git a/src/main/java/com/google/devtools/build/lib/bazel/rules/ObjcRules.java b/src/main/java/com/google/devtools/build/lib/bazel/rules/ObjcRules.java
index 5474f74..e56f9c3 100644
--- a/src/main/java/com/google/devtools/build/lib/bazel/rules/ObjcRules.java
+++ b/src/main/java/com/google/devtools/build/lib/bazel/rules/ObjcRules.java
@@ -13,17 +13,13 @@
// limitations under the License.
package com.google.devtools.build.lib.bazel.rules;
-import static com.google.common.base.Preconditions.checkNotNull;
-
import com.google.common.collect.ImmutableList;
import com.google.devtools.build.lib.analysis.BaseRuleClasses.EmptyRule;
import com.google.devtools.build.lib.analysis.ConfiguredRuleClassProvider;
import com.google.devtools.build.lib.analysis.ConfiguredRuleClassProvider.RuleSet;
-import com.google.devtools.build.lib.cmdline.RepositoryName;
import com.google.devtools.build.lib.rules.apple.AppleConfiguration;
import com.google.devtools.build.lib.rules.core.CoreRules;
import com.google.devtools.build.lib.rules.objc.AppleStarlarkCommon;
-import com.google.devtools.build.lib.rules.objc.AppleToolchain;
import com.google.devtools.build.lib.rules.objc.J2ObjcConfiguration;
import com.google.devtools.build.lib.rules.objc.ObjcConfiguration;
import com.google.devtools.build.lib.starlarkbuildapi.objc.AppleBootstrap;
@@ -38,15 +34,12 @@
@Override
public void init(ConfiguredRuleClassProvider.Builder builder) {
- RepositoryName toolsRepository = checkNotNull(builder.getToolsRepository());
-
builder.addConfigurationFragment(ObjcConfiguration.class);
builder.addConfigurationFragment(AppleConfiguration.class);
// j2objc shouldn't be here!
builder.addConfigurationFragment(J2ObjcConfiguration.class);
builder.addRuleDefinition(new EmptyRule("j2objc_library") {});
- builder.addRuleDefinition(new AppleToolchain.RequiresXcodeConfigRule(toolsRepository));
builder.addRuleDefinition(new EmptyRule("objc_import") {});
builder.addRuleDefinition(new EmptyRule("objc_library") {});
builder.addRuleDefinition(new EmptyRule("available_xcodes") {});
diff --git a/src/main/java/com/google/devtools/build/lib/rules/apple/XcodeVersionRule.java b/src/main/java/com/google/devtools/build/lib/rules/apple/XcodeVersionRule.java
deleted file mode 100644
index 2ccebf7..0000000
--- a/src/main/java/com/google/devtools/build/lib/rules/apple/XcodeVersionRule.java
+++ /dev/null
@@ -1,114 +0,0 @@
-// Copyright 2015 The Bazel Authors. All rights reserved.
-//
-// 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.google.devtools.build.lib.rules.apple;
-
-import static com.google.devtools.build.lib.packages.Attribute.attr;
-import static com.google.devtools.build.lib.packages.Type.STRING;
-import static com.google.devtools.build.lib.packages.Types.STRING_LIST;
-
-import com.google.devtools.build.lib.analysis.BaseRuleClasses;
-import com.google.devtools.build.lib.analysis.BaseRuleClasses.EmptyRuleConfiguredTargetFactory;
-import com.google.devtools.build.lib.analysis.RuleDefinition;
-import com.google.devtools.build.lib.analysis.RuleDefinitionEnvironment;
-import com.google.devtools.build.lib.packages.RuleClass;
-
-/**
- * Rule definition for {@code xcode_version} rule.
- */
-public class XcodeVersionRule implements RuleDefinition {
-
- static final String VERSION_ATTR_NAME = "version";
- static final String ALIASES_ATTR_NAME = "aliases";
- static final String DEFAULT_IOS_SDK_VERSION_ATTR_NAME = "default_ios_sdk_version";
- static final String DEFAULT_VISIONOS_SDK_VERSION_ATTR_NAME = "default_visionos_sdk_version";
- static final String DEFAULT_WATCHOS_SDK_VERSION_ATTR_NAME = "default_watchos_sdk_version";
- static final String DEFAULT_TVOS_SDK_VERSION_ATTR_NAME = "default_tvos_sdk_version";
- static final String DEFAULT_MACOS_SDK_VERSION_ATTR_NAME = "default_macos_sdk_version";
-
- @Override
- public RuleClass build(RuleClass.Builder builder, RuleDefinitionEnvironment env) {
- return builder
- .requiresConfigurationFragments(AppleConfiguration.class)
- .exemptFromConstraintChecking(
- "this rule refines configuration variables and does not build actual content")
- /* <!-- #BLAZE_RULE(xcode_version).ATTRIBUTE(version) -->
- The official version number of a version of Xcode.
- <!-- #END_BLAZE_RULE.ATTRIBUTE --> */
- .add(
- attr(VERSION_ATTR_NAME, STRING)
- .mandatory()
- .nonconfigurable("this rule determines configuration"))
- /* <!-- #BLAZE_RULE(xcode_version).ATTRIBUTE(version) -->
- Accepted aliases for this version of Xcode.
- If the value of the <code>xcode_version</code> build flag matches any of the given
- alias strings, this Xcode version will be used.
- <!-- #END_BLAZE_RULE.ATTRIBUTE --> */
- .add(
- attr(ALIASES_ATTR_NAME, STRING_LIST)
- .nonconfigurable("this rule determines configuration"))
-
- /* <!-- #BLAZE_RULE(xcode_version).ATTRIBUTE(default_ios_sdk_version) -->
- The iOS SDK version that is used by default when this version of Xcode is being used.
- The <code>ios_sdk_version</code> build flag will override the value specified here.
- <!-- #END_BLAZE_RULE.ATTRIBUTE --> */
- .add(
- attr(DEFAULT_IOS_SDK_VERSION_ATTR_NAME, STRING)
- .nonconfigurable("this rule determines configuration"))
- /* <!-- #BLAZE_RULE(xcode_version).ATTRIBUTE(default_visionos_sdk_version) -->
- The visionOS SDK version that is used by default when this version of Xcode is being used.
- <!-- #END_BLAZE_RULE.ATTRIBUTE --> */
- .add(
- attr(DEFAULT_VISIONOS_SDK_VERSION_ATTR_NAME, STRING)
- .nonconfigurable("this rule determines configuration"))
- /* <!-- #BLAZE_RULE(xcode_version).ATTRIBUTE(default_watchos_sdk_version) -->
- The watchOS SDK version that is used by default when this version of Xcode is being used.
- The <code>watchos_sdk_version</code> build flag will override the value specified here.
- <!-- #END_BLAZE_RULE.ATTRIBUTE --> */
- .add(
- attr(DEFAULT_WATCHOS_SDK_VERSION_ATTR_NAME, STRING)
- .nonconfigurable("this rule determines configuration"))
- /* <!-- #BLAZE_RULE(xcode_version).ATTRIBUTE(default_tvos_sdk_version) -->
- The tvOS SDK version that is used by default when this version of Xcode is being used.
- The <code>tvos_sdk_version</code> build flag will override the value specified here.
- <!-- #END_BLAZE_RULE.ATTRIBUTE --> */
- .add(
- attr(DEFAULT_TVOS_SDK_VERSION_ATTR_NAME, STRING)
- .nonconfigurable("this rule determines configuration"))
- /* <!-- #BLAZE_RULE(xcode_version).ATTRIBUTE(default_macos_sdk_version) -->
- The macOS SDK version that is used by default when this version of Xcode is being used.
- The <code>macos_sdk_version</code> build flag will override the value specified here.
- <!-- #END_BLAZE_RULE.ATTRIBUTE --> */
- .add(
- attr(DEFAULT_MACOS_SDK_VERSION_ATTR_NAME, STRING)
- .nonconfigurable("this rule determines configuration"))
- .build();
- }
-
- @Override
- public Metadata getMetadata() {
- return RuleDefinition.Metadata.builder()
- .name("xcode_version")
- .ancestors(BaseRuleClasses.NativeBuildRule.class)
- .factoryClass(EmptyRuleConfiguredTargetFactory.class)
- .build();
- }
-}
-
-/*<!-- #BLAZE_RULE (NAME = xcode_version, TYPE = OTHER, FAMILY = Objective-C) -->
-
-<p>Represents a single official Xcode version with acceptable aliases for that Xcode version.
-See the <code>xcode_config</code> rule.</p>
-
-<!-- #END_BLAZE_RULE -->*/
diff --git a/src/main/java/com/google/devtools/build/lib/rules/objc/AppleToolchain.java b/src/main/java/com/google/devtools/build/lib/rules/objc/AppleToolchain.java
index c6a7396..cb33164 100644
--- a/src/main/java/com/google/devtools/build/lib/rules/objc/AppleToolchain.java
+++ b/src/main/java/com/google/devtools/build/lib/rules/objc/AppleToolchain.java
@@ -14,24 +14,11 @@
package com.google.devtools.build.lib.rules.objc;
-import static com.google.devtools.build.lib.packages.Attribute.attr;
-import static com.google.devtools.build.lib.packages.BuildType.LABEL;
-
import com.google.common.annotations.VisibleForTesting;
-import com.google.devtools.build.lib.analysis.RuleDefinition;
-import com.google.devtools.build.lib.analysis.RuleDefinitionEnvironment;
-import com.google.devtools.build.lib.cmdline.Label;
-import com.google.devtools.build.lib.cmdline.RepositoryName;
import com.google.devtools.build.lib.concurrent.ThreadSafety.Immutable;
-import com.google.devtools.build.lib.packages.Attribute;
-import com.google.devtools.build.lib.packages.Attribute.LabelLateBoundDefault;
-import com.google.devtools.build.lib.packages.RuleClass;
-import com.google.devtools.build.lib.packages.RuleClass.Builder.RuleClassType;
-import com.google.devtools.build.lib.rules.apple.AppleCommandLineOptions;
import com.google.devtools.build.lib.rules.apple.AppleConfiguration;
import com.google.devtools.build.lib.rules.apple.ApplePlatform;
import com.google.devtools.build.lib.starlarkbuildapi.apple.AppleToolchainApi;
-import java.io.Serializable;
/**
* Utility class for resolving items for the Apple toolchain (such as common tool flags, and paths).
@@ -51,9 +38,6 @@
@VisibleForTesting
public static final String SYSTEM_FRAMEWORK_PATH = "/System/Library/Frameworks";
- /** XcodeConfig attribute name for Apple rules that take an xcode_config parameter */
- public static final String XCODE_CONFIG_ATTR_NAME = ":xcode_config";
-
/** Returns the platform directory inside of Xcode for a platform name. */
public static String platformDir(String platformName) {
return developerDir() + "/Platforms/" + platformName + ".platform";
@@ -81,17 +65,6 @@
return platformDir + "/Developer/Library/Frameworks";
}
- /** The default label of the build-wide {@code xcode_config} configuration rule. */
- public static LabelLateBoundDefault<AppleConfiguration> getXcodeConfigLabel(
- RepositoryName toolsRepository) {
- return LabelLateBoundDefault.fromTargetConfiguration(
- AppleConfiguration.class,
- Label.parseCanonicalUnchecked(
- toolsRepository + AppleCommandLineOptions.DEFAULT_XCODE_VERSION_CONFIG_LABEL),
- (Attribute.LateBoundDefault.Resolver<AppleConfiguration, Label> & Serializable)
- (rule, attributes, appleConfig) -> appleConfig.getXcodeConfigLabel());
- }
-
@Override
public boolean isImmutable() {
return true; // immutable and Starlark-hashable
@@ -120,31 +93,4 @@
public String platformFrameworkDirFromConfig(AppleConfiguration configuration) {
return platformDeveloperFrameworkDir(configuration.getSingleArchPlatform());
}
-
- /** Base rule definition to be ancestor for rules which may require an Xcode toolchain. */
- public static class RequiresXcodeConfigRule implements RuleDefinition {
- private final RepositoryName toolsRepository;
-
- public RequiresXcodeConfigRule(RepositoryName toolsRepository) {
- this.toolsRepository = toolsRepository;
- }
-
- @Override
- public RuleClass build(RuleClass.Builder builder, RuleDefinitionEnvironment env) {
- return builder
- .add(
- attr(XCODE_CONFIG_ATTR_NAME, LABEL)
- .allowedRuleClasses("xcode_config")
- .checkConstraints()
- .value(getXcodeConfigLabel(toolsRepository)))
- .build();
- }
- @Override
- public Metadata getMetadata() {
- return RuleDefinition.Metadata.builder()
- .name("$requires_xcode_config")
- .type(RuleClassType.ABSTRACT)
- .build();
- }
- }
}
diff --git a/src/main/java/com/google/devtools/build/lib/rules/objc/BUILD b/src/main/java/com/google/devtools/build/lib/rules/objc/BUILD
index 0173058..a7f7ff1 100644
--- a/src/main/java/com/google/devtools/build/lib/rules/objc/BUILD
+++ b/src/main/java/com/google/devtools/build/lib/rules/objc/BUILD
@@ -27,7 +27,6 @@
"//src/main/java/com/google/devtools/build/lib/analysis:config/core_options",
"//src/main/java/com/google/devtools/build/lib/analysis:config/fragment",
"//src/main/java/com/google/devtools/build/lib/analysis:config/fragment_options",
- "//src/main/java/com/google/devtools/build/lib/analysis:rule_definition_environment",
"//src/main/java/com/google/devtools/build/lib/analysis/platform",
"//src/main/java/com/google/devtools/build/lib/analysis/starlark/annotations",
"//src/main/java/com/google/devtools/build/lib/cmdline",
diff --git a/src/main/java/com/google/devtools/build/lib/rules/objc/Interspersing.java b/src/main/java/com/google/devtools/build/lib/rules/objc/Interspersing.java
deleted file mode 100644
index 5084d02..0000000
--- a/src/main/java/com/google/devtools/build/lib/rules/objc/Interspersing.java
+++ /dev/null
@@ -1,56 +0,0 @@
-// Copyright 2014 The Bazel Authors. All rights reserved.
-//
-// 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.google.devtools.build.lib.rules.objc;
-
-import com.google.common.base.Function;
-import com.google.common.base.Preconditions;
-import com.google.common.collect.ImmutableList;
-import com.google.common.collect.Iterables;
-
-/**
- * Utility code for interspersing items into sequences.
- */
-public class Interspersing {
- private Interspersing() {}
-
- /**
- * Inserts {@code what} before each item in {@code sequence}, returning a lazy sequence of twice
- * the length.
- */
- public static <E> Iterable<E> beforeEach(final E what, Iterable<E> sequence) {
- Preconditions.checkNotNull(what);
- return Iterables.concat(
- Iterables.transform(sequence, element -> ImmutableList.of(what, element)));
- }
-
- /**
- * Prepends {@code what} to each string in {@code sequence}, returning a lazy sequence of the
- * same length.
- */
- public static Iterable<String>
- prependEach(final String what, Iterable<String> sequence) {
- Preconditions.checkNotNull(what);
- return Iterables.transform(sequence, input -> what + input);
- }
-
- /**
- * Similar to {@link #prependEach(String, Iterable)}, but also converts each item in the sequence
- * to a string.
- */
- public static <E> Iterable<String>
- prependEach(String what, Iterable<E> sequence, Function<? super E, String> toString) {
- return prependEach(what, Iterables.transform(sequence, toString));
- }
-}
diff --git a/src/main/java/com/google/devtools/build/lib/rules/objc/Value.java b/src/main/java/com/google/devtools/build/lib/rules/objc/Value.java
deleted file mode 100644
index 6f142f5..0000000
--- a/src/main/java/com/google/devtools/build/lib/rules/objc/Value.java
+++ /dev/null
@@ -1,70 +0,0 @@
-// Copyright 2014 The Bazel Authors. All rights reserved.
-//
-// 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.google.devtools.build.lib.rules.objc;
-
-import com.google.common.base.Preconditions;
-import com.google.common.collect.ImmutableList;
-
-/**
- * Represents a type whose equality, hash code, and string representation are defined by a single
- * immutable array. This class is designed to be extended by a final class, and to pass the member
- * data to this class's constructor.
- *
- * @param <V> the base class that extends {@code Value}
- */
-// TODO(bazel-team): Replace with AutoValue once that is supported in bazel.
-public class Value<V extends Value<V>> {
- private final Object memberData;
-
- /**
- * Constructs a new instance with the given member data. Generally, all member data should be
- * reflected in final fields in the child class.
- * @throws NullPointerException if any element in {@code memberData} is null
- */
- public Value(Object... memberData) {
- Preconditions.checkArgument(memberData.length > 0);
- this.memberData = (memberData.length == 1)
- ? Preconditions.checkNotNull(memberData[0]) : ImmutableList.copyOf(memberData);
- }
-
- /**
- * A type-safe alternative to calling {@code a.equals(b)}. When using {@code a.equals(b)},
- * {@code b} may accidentally be a different class from {@code a}, in which case there will be no
- * compiler warning and the result will always be false. This method requires both values to have
- * compatible types and to be non-null.
- */
- public boolean equalsOther(V other) {
- return equals(Preconditions.checkNotNull(other));
- }
-
- @Override
- public boolean equals(Object o) {
- if ((o == null) || (o.getClass() != getClass())) {
- return false;
- }
- Value<?> other = (Value<?>) o;
- return memberData.equals(other.memberData);
- }
-
- @Override
- public int hashCode() {
- return memberData.hashCode();
- }
-
- @Override
- public String toString() {
- return getClass().getSimpleName() + ":" + memberData.toString();
- }
-}
diff --git a/src/test/java/com/google/devtools/build/lib/rules/objc/InterspersingTest.java b/src/test/java/com/google/devtools/build/lib/rules/objc/InterspersingTest.java
deleted file mode 100644
index fe62a0f..0000000
--- a/src/test/java/com/google/devtools/build/lib/rules/objc/InterspersingTest.java
+++ /dev/null
@@ -1,74 +0,0 @@
-// Copyright 2017 The Bazel Authors. All rights reserved.
-//
-// 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.google.devtools.build.lib.rules.objc;
-
-import static com.google.common.truth.Truth.assertThat;
-import static org.junit.Assert.assertThrows;
-
-import com.google.common.base.Functions;
-import com.google.common.collect.ImmutableList;
-import com.google.common.collect.Iterables;
-import org.junit.Test;
-import org.junit.runner.RunWith;
-import org.junit.runners.JUnit4;
-
-/** Test case for the Interspersing utility. */
-@RunWith(JUnit4.class)
-public class InterspersingTest {
- @Test
- public void beforeEach_empty() {
- assertThat(Interspersing.beforeEach("foo", ImmutableList.<String>of())).isEmpty();
- }
-
- @Test
- public void beforeEach_isLazy() {
- Iterable<Integer> result = Interspersing.beforeEach(1011, Iterables.cycle(1, 2, 3));
- assertThat(Iterables.get(result, 0)).isEqualTo((Object) 1011);
- assertThat(Iterables.get(result, 1)).isEqualTo((Object) 1);
- assertThat(Iterables.get(result, 2)).isEqualTo((Object) 1011);
- assertThat(Iterables.get(result, 3)).isEqualTo((Object) 2);
- }
-
- @Test
- public void beforeEach_throwsForNullWhat() {
- assertThrows(
- NullPointerException.class, () -> Interspersing.beforeEach(null, ImmutableList.of("a")));
- }
-
- @Test
- public void prependEach_empty() {
- assertThat(Interspersing.prependEach("foo", ImmutableList.<String>of())).isEmpty();
- }
-
- @Test
- public void prependEach_isLazy() {
- Iterable<String> result = Interspersing.prependEach(
- "#", Iterables.cycle(1, 2, 3), Functions.toStringFunction());
- assertThat(Iterables.get(result, 0)).isEqualTo("#1");
- }
-
- @Test
- public void prependEach_typicalList() {
- Iterable<String> result = Interspersing.prependEach(
- "*", ImmutableList.of("a", "b", "c"));
- assertThat(result).containsExactly("*a", "*b", "*c").inOrder();
- }
-
- @Test
- public void prependEach_throwsForNullWhat() {
- assertThrows(
- NullPointerException.class, () -> Interspersing.prependEach(null, ImmutableList.of("a")));
- }
-}
diff --git a/src/test/java/com/google/devtools/build/lib/rules/objc/ObjcLibraryTest.java b/src/test/java/com/google/devtools/build/lib/rules/objc/ObjcLibraryTest.java
index 7a35081..39b4a35 100644
--- a/src/test/java/com/google/devtools/build/lib/rules/objc/ObjcLibraryTest.java
+++ b/src/test/java/com/google/devtools/build/lib/rules/objc/ObjcLibraryTest.java
@@ -1310,7 +1310,10 @@
assertContainsSublist(
removeConfigFragment(removeConfigFragment(compileAction.getArguments())),
ImmutableList.copyOf(
- Interspersing.beforeEach("-isystem", rootedIncludePaths("package/foo/bar"))));
+ Iterables.concat(
+ Iterables.transform(
+ rootedIncludePaths("package/foo/bar"),
+ element -> ImmutableList.of("-isystem", element)))));
}
@Test
diff --git a/src/test/java/com/google/devtools/build/lib/rules/objc/ValueTest.java b/src/test/java/com/google/devtools/build/lib/rules/objc/ValueTest.java
deleted file mode 100644
index ea98476..0000000
--- a/src/test/java/com/google/devtools/build/lib/rules/objc/ValueTest.java
+++ /dev/null
@@ -1,72 +0,0 @@
-// Copyright 2017 The Bazel Authors. All rights reserved.
-//
-// 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.google.devtools.build.lib.rules.objc;
-
-import static com.google.common.truth.Truth.assertThat;
-import static org.junit.Assert.assertThrows;
-
-import com.google.common.testing.EqualsTester;
-import org.junit.Test;
-import org.junit.runner.RunWith;
-import org.junit.runners.JUnit4;
-
-/**
- * Unit tests for {@class Value}.
- */
-@RunWith(JUnit4.class)
-public class ValueTest {
- private static final class PersonName extends Value<PersonName> {
- public PersonName(String first, String last) {
- super(first, last);
- }
- }
-
- private enum NameData {
- JOHN_DOE, JANE_DOE, JOHN_SMITH,
- }
-
- private PersonName make(NameData what) {
- switch (what) {
- case JOHN_DOE:
- return new PersonName("John", "Doe");
- case JANE_DOE:
- return new PersonName("Jane", "Doe");
- case JOHN_SMITH:
- return new PersonName("John", "Smith");
- default:
- throw new IllegalArgumentException("unknown: " + what);
- }
- }
-
- @Test
- public void nullNotAllowedInMemberData() {
- assertThrows(NullPointerException.class, () -> new PersonName(null, "Doe"));
- }
-
- @Test
- public void equality() {
- EqualsTester tester = new EqualsTester();
- for (NameData what : NameData.values()) {
- tester.addEqualityGroup(make(what), make(what));
- }
- tester.testEquals();
- }
-
- @Test
- public void testToString() {
- assertThat(make(NameData.JOHN_DOE).toString()).contains("John");
- assertThat(make(NameData.JOHN_DOE).toString()).contains("Doe");
- }
-}