From 19c6525a9fcb036fff6c1d3865acd267e3ebcc4e Mon Sep 17 00:00:00 2001 From: Andrea Lin Date: Tue, 27 Feb 2018 14:52:39 -0800 Subject: [PATCH 01/13] Update ResourceName.java --- .../com/google/api/resourcenames/ResourceName.java | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/src/main/java/com/google/api/resourcenames/ResourceName.java b/src/main/java/com/google/api/resourcenames/ResourceName.java index 54225babc..4843b081f 100644 --- a/src/main/java/com/google/api/resourcenames/ResourceName.java +++ b/src/main/java/com/google/api/resourcenames/ResourceName.java @@ -37,6 +37,16 @@ @BetaApi public interface ResourceName { + /** + * Return the map of each field name to its value. + */ + public Map getFieldValuesMap(); + + /** + * Return the String value of the field with name fieldName. Returns null if the fieldName was not found. + */ + public String getFieldValue(String fieldName); + /** * The ResourceNameType of the resource name object. * From 1cd4ae731dd26b0cffcf90a3ca5d5fe628b805c6 Mon Sep 17 00:00:00 2001 From: Andrea Lin Date: Tue, 27 Feb 2018 16:43:17 -0800 Subject: [PATCH 02/13] add Map import --- src/main/java/com/google/api/resourcenames/ResourceName.java | 1 + 1 file changed, 1 insertion(+) diff --git a/src/main/java/com/google/api/resourcenames/ResourceName.java b/src/main/java/com/google/api/resourcenames/ResourceName.java index 4843b081f..26b6d6d7e 100644 --- a/src/main/java/com/google/api/resourcenames/ResourceName.java +++ b/src/main/java/com/google/api/resourcenames/ResourceName.java @@ -32,6 +32,7 @@ package com.google.api.resourcenames; import com.google.api.core.BetaApi; +import java.util.Map; /** An interface that generated resource name types must implement. */ @BetaApi From dcf59c80149d7cce0688611287b5f3bcaf960feb Mon Sep 17 00:00:00 2001 From: Andrea Lin Date: Tue, 27 Feb 2018 16:57:47 -0800 Subject: [PATCH 03/13] update UntypedResourceName --- .../api/resourcenames/ResourceName.java | 11 +++++----- .../resourcenames/UntypedResourceName.java | 20 +++++++++++++++++++ 2 files changed, 26 insertions(+), 5 deletions(-) diff --git a/src/main/java/com/google/api/resourcenames/ResourceName.java b/src/main/java/com/google/api/resourcenames/ResourceName.java index 26b6d6d7e..f9468a20d 100644 --- a/src/main/java/com/google/api/resourcenames/ResourceName.java +++ b/src/main/java/com/google/api/resourcenames/ResourceName.java @@ -41,18 +41,19 @@ public interface ResourceName { /** * Return the map of each field name to its value. */ - public Map getFieldValuesMap(); + Map getFieldValuesMap(); /** - * Return the String value of the field with name fieldName. Returns null if the fieldName was not found. + * Return the String value of the field with name fieldName. Returns null if the fieldName was not + * found. */ - public String getFieldValue(String fieldName); - + String getFieldValue(String fieldName); + /** * The ResourceNameType of the resource name object. * * @deprecated With Oneof types being converted to use inheritance, this is no longer necessary. */ @Deprecated - public ResourceNameType getType(); + ResourceNameType getType(); } diff --git a/src/main/java/com/google/api/resourcenames/UntypedResourceName.java b/src/main/java/com/google/api/resourcenames/UntypedResourceName.java index e47a98975..23b28f4bb 100644 --- a/src/main/java/com/google/api/resourcenames/UntypedResourceName.java +++ b/src/main/java/com/google/api/resourcenames/UntypedResourceName.java @@ -33,6 +33,8 @@ import com.google.api.core.BetaApi; import com.google.common.base.Preconditions; +import com.google.common.collect.ImmutableMap; +import java.util.Map; /** * A class to represent a {@link ResourceName} with an unknown format. This class in intended to @@ -44,6 +46,8 @@ public class UntypedResourceName implements ResourceName { private final String rawValue; + private volatile Map fieldValuesMap; + private UntypedResourceName(String rawValue) { this.rawValue = Preconditions.checkNotNull(rawValue); } @@ -78,6 +82,22 @@ public ResourceNameType getType() { return UntypedResourceNameType.instance(); } + @Override + /* Returns a map with an empty String as the sole key, which maps to the raw value of this ResourceName. */ + public Map getFieldValuesMap() { + if (fieldValuesMap != null) { + return fieldValuesMap; + } + fieldValuesMap = ImmutableMap.of("", rawValue); + return fieldValuesMap; + } + + @Override + /* Returns the raw value of this ResourceName, regardless of the fieldName parameter. */ + public String getFieldValue(String fieldName) { + return rawValue; + } + @Override public String toString() { return rawValue; From a50b92de231db2610310b47b5e68e72884f41c46 Mon Sep 17 00:00:00 2001 From: Andrea Lin Date: Tue, 27 Feb 2018 17:11:42 -0800 Subject: [PATCH 04/13] formatting for UntypedResourceName --- .../com/google/api/resourcenames/UntypedResourceName.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/main/java/com/google/api/resourcenames/UntypedResourceName.java b/src/main/java/com/google/api/resourcenames/UntypedResourceName.java index 23b28f4bb..9e362cce6 100644 --- a/src/main/java/com/google/api/resourcenames/UntypedResourceName.java +++ b/src/main/java/com/google/api/resourcenames/UntypedResourceName.java @@ -82,8 +82,8 @@ public ResourceNameType getType() { return UntypedResourceNameType.instance(); } - @Override /* Returns a map with an empty String as the sole key, which maps to the raw value of this ResourceName. */ + @Override public Map getFieldValuesMap() { if (fieldValuesMap != null) { return fieldValuesMap; @@ -92,10 +92,10 @@ public Map getFieldValuesMap() { return fieldValuesMap; } + /* Returns the raw value of this ResourceName iff fieldName.equals(""), else returns null. */ @Override - /* Returns the raw value of this ResourceName, regardless of the fieldName parameter. */ public String getFieldValue(String fieldName) { - return rawValue; + return fieldValuesMap.get(""); } @Override From acabf893ebca428fed75656b7920a8c0ad05dd78 Mon Sep 17 00:00:00 2001 From: Andrea Lin Date: Wed, 28 Feb 2018 14:21:59 -0800 Subject: [PATCH 05/13] synchronized fieldValuesMap for UntypedResourceName.java --- .../google/api/resourcenames/UntypedResourceName.java | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/src/main/java/com/google/api/resourcenames/UntypedResourceName.java b/src/main/java/com/google/api/resourcenames/UntypedResourceName.java index 9e362cce6..2bb49a5a9 100644 --- a/src/main/java/com/google/api/resourcenames/UntypedResourceName.java +++ b/src/main/java/com/google/api/resourcenames/UntypedResourceName.java @@ -85,10 +85,13 @@ public ResourceNameType getType() { /* Returns a map with an empty String as the sole key, which maps to the raw value of this ResourceName. */ @Override public Map getFieldValuesMap() { - if (fieldValuesMap != null) { - return fieldValuesMap; + if (fieldValuesMap == null) { + synchronized (this) { + if (fieldValuesMap == null) { + fieldValuesMap = ImmutableMap.of("", rawValue); + } + } } - fieldValuesMap = ImmutableMap.of("", rawValue); return fieldValuesMap; } From ba8dee4002a58757a70bb90e1ab5d760c5e6a15c Mon Sep 17 00:00:00 2001 From: Andrea Lin Date: Wed, 28 Feb 2018 17:09:55 -0800 Subject: [PATCH 06/13] adding ResourceNameFactory --- .../com/google/api/resourcenames/ResourceNameFactory.java | 7 +++++++ 1 file changed, 7 insertions(+) create mode 100644 src/main/java/com/google/api/resourcenames/ResourceNameFactory.java diff --git a/src/main/java/com/google/api/resourcenames/ResourceNameFactory.java b/src/main/java/com/google/api/resourcenames/ResourceNameFactory.java new file mode 100644 index 000000000..6f54bccd0 --- /dev/null +++ b/src/main/java/com/google/api/resourcenames/ResourceNameFactory.java @@ -0,0 +1,7 @@ +package com.google.api.resourcenames; + +public interface ResourceNameFactory { + + /* Create a new ResourceName from a formatted String representing a ResourceName. */ + ResourceName parseFrom(String formattedString); +} From 12457d5a4462eba2c58f9df0428a9ea61331f8b6 Mon Sep 17 00:00:00 2001 From: Andrea Lin Date: Thu, 1 Mar 2018 08:46:40 -0800 Subject: [PATCH 07/13] parameterize ResourceNameFactory --- .../resourcenames/ResourceNameFactory.java | 34 +++++++++++++++++-- 1 file changed, 32 insertions(+), 2 deletions(-) diff --git a/src/main/java/com/google/api/resourcenames/ResourceNameFactory.java b/src/main/java/com/google/api/resourcenames/ResourceNameFactory.java index 6f54bccd0..340eb3b63 100644 --- a/src/main/java/com/google/api/resourcenames/ResourceNameFactory.java +++ b/src/main/java/com/google/api/resourcenames/ResourceNameFactory.java @@ -1,7 +1,37 @@ +/* + * Copyright 2016, Google Inc. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above + * copyright notice, this list of conditions and the following disclaimer + * in the documentation and/or other materials provided with the + * distribution. + * * Neither the name of Google Inc. nor the names of its + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ package com.google.api.resourcenames; -public interface ResourceNameFactory { +public interface ResourceNameFactory { /* Create a new ResourceName from a formatted String representing a ResourceName. */ - ResourceName parseFrom(String formattedString); + T parseFrom(String formattedString); } From f10b0021799098243845306fed7e7d879c64bc1e Mon Sep 17 00:00:00 2001 From: Andrea Lin Date: Thu, 1 Mar 2018 08:48:39 -0800 Subject: [PATCH 08/13] revert version.txt to origin/master --- version.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/version.txt b/version.txt index 5c73cd1b2..88c5fb891 100644 --- a/version.txt +++ b/version.txt @@ -1 +1 @@ -1.3.1-SNAPSHOT +1.4.0 From 69293fa001cc98914f159dbf95c140c90baa0a3a Mon Sep 17 00:00:00 2001 From: Andrea Lin Date: Thu, 1 Mar 2018 08:54:26 -0800 Subject: [PATCH 09/13] use getFieldValuesMap() in untypedresourcename.getfieldstringvalue() --- .../java/com/google/api/resourcenames/UntypedResourceName.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/com/google/api/resourcenames/UntypedResourceName.java b/src/main/java/com/google/api/resourcenames/UntypedResourceName.java index 9e778b91e..290b95435 100644 --- a/src/main/java/com/google/api/resourcenames/UntypedResourceName.java +++ b/src/main/java/com/google/api/resourcenames/UntypedResourceName.java @@ -80,7 +80,7 @@ public Map getFieldValuesMap() { /* Returns the raw value of this ResourceName iff fieldName.equals(""), else returns null. */ @Override public String getFieldValue(String fieldName) { - return fieldValuesMap.get(""); + return getFieldValuesMap().get(""); } @Override From 3b403c17036e76e139c36c2e6291f4352b0ff960 Mon Sep 17 00:00:00 2001 From: Andrea Lin Date: Thu, 1 Mar 2018 09:18:06 -0800 Subject: [PATCH 10/13] add null check in UntypedResourceName and make tests for that class --- .../resourcenames/ResourceNameFactory.java | 2 +- .../resourcenames/UntypedResourceName.java | 4 +- .../UntypedResourceNameTest.java | 95 +++++++++++++++++++ 3 files changed, 98 insertions(+), 3 deletions(-) create mode 100644 src/test/java/com/google/api/resourcenames/UntypedResourceNameTest.java diff --git a/src/main/java/com/google/api/resourcenames/ResourceNameFactory.java b/src/main/java/com/google/api/resourcenames/ResourceNameFactory.java index 340eb3b63..83301476f 100644 --- a/src/main/java/com/google/api/resourcenames/ResourceNameFactory.java +++ b/src/main/java/com/google/api/resourcenames/ResourceNameFactory.java @@ -1,5 +1,5 @@ /* - * Copyright 2016, Google Inc. + * Copyright 2018, Google Inc. * All rights reserved. * * Redistribution and use in source and binary forms, with or without diff --git a/src/main/java/com/google/api/resourcenames/UntypedResourceName.java b/src/main/java/com/google/api/resourcenames/UntypedResourceName.java index 290b95435..4e2da19c3 100644 --- a/src/main/java/com/google/api/resourcenames/UntypedResourceName.java +++ b/src/main/java/com/google/api/resourcenames/UntypedResourceName.java @@ -61,10 +61,10 @@ public static UntypedResourceName parse(String formattedString) { } public static boolean isParsableFrom(String formattedString) { - return true; + return formattedString != null; } - /* Returns a map with an empty String as the sole key, which maps to the raw value of this ResourceName. */ + /* Returns a map with an empty String "" as the sole key, which maps to the raw value of this ResourceName. */ @Override public Map getFieldValuesMap() { if (fieldValuesMap == null) { diff --git a/src/test/java/com/google/api/resourcenames/UntypedResourceNameTest.java b/src/test/java/com/google/api/resourcenames/UntypedResourceNameTest.java new file mode 100644 index 000000000..ab13287ea --- /dev/null +++ b/src/test/java/com/google/api/resourcenames/UntypedResourceNameTest.java @@ -0,0 +1,95 @@ +/* + * Copyright 2018, Google Inc. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above + * copyright notice, this list of conditions and the following disclaimer + * in the documentation and/or other materials provided with the + * distribution. + * * Neither the name of Google Inc. nor the names of its + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ +package com.google.api.resourcenames; + +import static junit.framework.TestCase.fail; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertTrue; + +import java.util.Map; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.junit.runners.JUnit4; + +/** + * Tests for {@link UntypedResourceNameTest}. + */ +@RunWith(JUnit4.class) +public class UntypedResourceNameTest { + private static final String NAME_STRING = "sunshine"; + private static final String EMPTY_STRING = ""; + + @Test + public void testGetFieldValues() { + assertTrue(UntypedResourceName.isParsableFrom(NAME_STRING)); + UntypedResourceName fooName = UntypedResourceName.parse(NAME_STRING); + + Map fieldValuesMap = fooName.getFieldValuesMap(); + assertTrue(fieldValuesMap.containsKey(EMPTY_STRING)); + assertEquals(NAME_STRING, fieldValuesMap.get(EMPTY_STRING)); + assertEquals(1, fieldValuesMap.size()); + assertEquals(null, fieldValuesMap.get(NAME_STRING)); + } + + @Test + public void testInsertIntoFieldValuesMap() { + UntypedResourceName fooName = UntypedResourceName.parse(NAME_STRING); + Map fieldValuesMap = fooName.getFieldValuesMap(); + + try { + fieldValuesMap.put(EMPTY_STRING, "foo"); + fail("fieldValuesMap should prevent insertion into internal map. "); + } catch (UnsupportedOperationException e) { + } + + try { + fieldValuesMap.put(null, "foo"); + fail("fieldValuesMap should prevent insertion into internal map. "); + } catch (UnsupportedOperationException e) { + } + + try { + fieldValuesMap.put(NAME_STRING, NAME_STRING); + fail("fieldValuesMap should prevent insertion into internal map. "); + } catch (UnsupportedOperationException e) { + } + } + + @Test + public void testNullName() { + assertFalse(UntypedResourceName.isParsableFrom(null)); + try { + UntypedResourceName fooName = UntypedResourceName.parse(null); + } catch (NullPointerException e) { + } + } +} From f13ed35ae4a95253440c33683c8af383b4fbf894 Mon Sep 17 00:00:00 2001 From: Andrea Lin Date: Thu, 1 Mar 2018 09:22:55 -0800 Subject: [PATCH 11/13] null check in UntypedResourceName and tests for that class --- .../resourcenames/ResourceNameFactory.java | 2 +- .../resourcenames/UntypedResourceName.java | 4 +- .../UntypedResourceNameTest.java | 95 +++++++++++++++++++ 3 files changed, 98 insertions(+), 3 deletions(-) create mode 100644 src/test/java/com/google/api/resourcenames/UntypedResourceNameTest.java diff --git a/src/main/java/com/google/api/resourcenames/ResourceNameFactory.java b/src/main/java/com/google/api/resourcenames/ResourceNameFactory.java index 340eb3b63..83301476f 100644 --- a/src/main/java/com/google/api/resourcenames/ResourceNameFactory.java +++ b/src/main/java/com/google/api/resourcenames/ResourceNameFactory.java @@ -1,5 +1,5 @@ /* - * Copyright 2016, Google Inc. + * Copyright 2018, Google Inc. * All rights reserved. * * Redistribution and use in source and binary forms, with or without diff --git a/src/main/java/com/google/api/resourcenames/UntypedResourceName.java b/src/main/java/com/google/api/resourcenames/UntypedResourceName.java index 290b95435..4e2da19c3 100644 --- a/src/main/java/com/google/api/resourcenames/UntypedResourceName.java +++ b/src/main/java/com/google/api/resourcenames/UntypedResourceName.java @@ -61,10 +61,10 @@ public static UntypedResourceName parse(String formattedString) { } public static boolean isParsableFrom(String formattedString) { - return true; + return formattedString != null; } - /* Returns a map with an empty String as the sole key, which maps to the raw value of this ResourceName. */ + /* Returns a map with an empty String "" as the sole key, which maps to the raw value of this ResourceName. */ @Override public Map getFieldValuesMap() { if (fieldValuesMap == null) { diff --git a/src/test/java/com/google/api/resourcenames/UntypedResourceNameTest.java b/src/test/java/com/google/api/resourcenames/UntypedResourceNameTest.java new file mode 100644 index 000000000..ab13287ea --- /dev/null +++ b/src/test/java/com/google/api/resourcenames/UntypedResourceNameTest.java @@ -0,0 +1,95 @@ +/* + * Copyright 2018, Google Inc. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above + * copyright notice, this list of conditions and the following disclaimer + * in the documentation and/or other materials provided with the + * distribution. + * * Neither the name of Google Inc. nor the names of its + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ +package com.google.api.resourcenames; + +import static junit.framework.TestCase.fail; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertTrue; + +import java.util.Map; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.junit.runners.JUnit4; + +/** + * Tests for {@link UntypedResourceNameTest}. + */ +@RunWith(JUnit4.class) +public class UntypedResourceNameTest { + private static final String NAME_STRING = "sunshine"; + private static final String EMPTY_STRING = ""; + + @Test + public void testGetFieldValues() { + assertTrue(UntypedResourceName.isParsableFrom(NAME_STRING)); + UntypedResourceName fooName = UntypedResourceName.parse(NAME_STRING); + + Map fieldValuesMap = fooName.getFieldValuesMap(); + assertTrue(fieldValuesMap.containsKey(EMPTY_STRING)); + assertEquals(NAME_STRING, fieldValuesMap.get(EMPTY_STRING)); + assertEquals(1, fieldValuesMap.size()); + assertEquals(null, fieldValuesMap.get(NAME_STRING)); + } + + @Test + public void testInsertIntoFieldValuesMap() { + UntypedResourceName fooName = UntypedResourceName.parse(NAME_STRING); + Map fieldValuesMap = fooName.getFieldValuesMap(); + + try { + fieldValuesMap.put(EMPTY_STRING, "foo"); + fail("fieldValuesMap should prevent insertion into internal map. "); + } catch (UnsupportedOperationException e) { + } + + try { + fieldValuesMap.put(null, "foo"); + fail("fieldValuesMap should prevent insertion into internal map. "); + } catch (UnsupportedOperationException e) { + } + + try { + fieldValuesMap.put(NAME_STRING, NAME_STRING); + fail("fieldValuesMap should prevent insertion into internal map. "); + } catch (UnsupportedOperationException e) { + } + } + + @Test + public void testNullName() { + assertFalse(UntypedResourceName.isParsableFrom(null)); + try { + UntypedResourceName fooName = UntypedResourceName.parse(null); + } catch (NullPointerException e) { + } + } +} From 65baa195a17df8c4289797baf785433dccb98a9d Mon Sep 17 00:00:00 2001 From: Andrea Lin Date: Thu, 1 Mar 2018 10:58:33 -0800 Subject: [PATCH 12/13] @BetaApi ResourceNameFactory --- .../java/com/google/api/resourcenames/ResourceNameFactory.java | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/main/java/com/google/api/resourcenames/ResourceNameFactory.java b/src/main/java/com/google/api/resourcenames/ResourceNameFactory.java index 83301476f..ed809930a 100644 --- a/src/main/java/com/google/api/resourcenames/ResourceNameFactory.java +++ b/src/main/java/com/google/api/resourcenames/ResourceNameFactory.java @@ -30,6 +30,9 @@ */ package com.google.api.resourcenames; +import com.google.api.core.BetaApi; + +@BetaApi public interface ResourceNameFactory { /* Create a new ResourceName from a formatted String representing a ResourceName. */ From 138784102c19f0db9b4a3a011fe9e01326b31397 Mon Sep 17 00:00:00 2001 From: Andrea Lin Date: Thu, 1 Mar 2018 11:47:12 -0800 Subject: [PATCH 13/13] ResourceNameFactory rename parseFrom() to parse() --- .../java/com/google/api/resourcenames/ResourceNameFactory.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/com/google/api/resourcenames/ResourceNameFactory.java b/src/main/java/com/google/api/resourcenames/ResourceNameFactory.java index ed809930a..13e18d0c5 100644 --- a/src/main/java/com/google/api/resourcenames/ResourceNameFactory.java +++ b/src/main/java/com/google/api/resourcenames/ResourceNameFactory.java @@ -36,5 +36,5 @@ public interface ResourceNameFactory { /* Create a new ResourceName from a formatted String representing a ResourceName. */ - T parseFrom(String formattedString); + T parse(String formattedString); }