Skip to content

Commit 039f847

Browse files
author
Ajay Kannan
committed
---
yaml --- r: 4555 b: refs/heads/logging-alpha c: 08295ee h: refs/heads/master i: 4553: bab79b9 4551: 67f05d0
1 parent fbe444a commit 039f847

3 files changed

Lines changed: 36 additions & 26 deletions

File tree

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ refs/heads/compute-alpha: 969cba2627f1d53d352cc4a5ffe0879dacf65e6c
1212
refs/heads/dns-alpha: 2f90e7e338349287ace33375896907af0f032ca1
1313
refs/heads/dns-alpha-batch: 17442b07867021b85d0452f5f3eda29a3413288f
1414
refs/heads/gcs-nio: 283aeaf15efdcf3621eb6859f05e55ad7764375d
15-
refs/heads/logging-alpha: ee78b22a2656517681ab157aecd1667fdb384a4e
15+
refs/heads/logging-alpha: 08295eeca633772ebab9dafab62aa2cc1e8ad627
1616
refs/tags/v0.1.0: a615317f7424ed58621b1f65d5c4d8cbbe8a6ed8
1717
refs/tags/v0.1.1: 7a7f6985fe465e9dd6a075af55493f42b4933be0
1818
refs/tags/v0.1.2: 3eb3fe866ba22487686048f45d927b8c8638ea3f

branches/logging-alpha/gcloud-java-core/src/main/java/com/google/gcloud/IamPolicy.java

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,9 @@ public abstract static class Builder<R, B extends Builder<R, B>> {
5858
private String etag;
5959
private Integer version;
6060

61+
/**
62+
* Constructor for IAM Policy builder.
63+
*/
6164
protected Builder() {}
6265

6366
/**
@@ -73,6 +76,8 @@ public final B bindings(Map<R, Set<Identity>> bindings) {
7376

7477
/**
7578
* Adds a binding to the policy.
79+
*
80+
* @throws IllegalArgumentException if the policy already contains a binding with the same role
7681
*/
7782
public final B addBinding(R role, Set<Identity> identities) {
7883
checkArgument(!bindings.containsKey(role),
@@ -83,6 +88,8 @@ public final B addBinding(R role, Set<Identity> identities) {
8388

8489
/**
8590
* Adds a binding to the policy.
91+
*
92+
* @throws IllegalArgumentException if the policy already contains a binding with the same role
8693
*/
8794
public final B addBinding(R role, Identity first, Identity... others) {
8895
checkArgument(!bindings.containsKey(role),
@@ -104,8 +111,12 @@ public final B removeBinding(R role) {
104111

105112
/**
106113
* Adds one or more identities to an existing binding.
114+
*
115+
* @throws IllegalArgumentException if the policy doesn't contain a binding with the specified
116+
* role
107117
*/
108118
public final B addIdentity(R role, Identity first, Identity... others) {
119+
checkArgument(bindings.containsKey(role), "The policy doesn't contain the specified role.");
109120
Set<Identity> identities = bindings.get(role);
110121
identities.add(first);
111122
identities.addAll(Arrays.asList(others));
@@ -114,8 +125,12 @@ public final B addIdentity(R role, Identity first, Identity... others) {
114125

115126
/**
116127
* Removes one or more identities from an existing binding.
128+
*
129+
* @throws IllegalArgumentException if the policy doesn't contain a binding with the specified
130+
* role
117131
*/
118132
public final B removeIdentity(R role, Identity first, Identity... others) {
133+
checkArgument(bindings.containsKey(role), "The policy doesn't contain the specified role.");
119134
bindings.get(role).remove(first);
120135
bindings.get(role).removeAll(Arrays.asList(others));
121136
return self();

branches/logging-alpha/gcloud-java-core/src/test/java/com/google/gcloud/IdentityTest.java

Lines changed: 20 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818

1919
import static org.junit.Assert.assertEquals;
2020
import static org.junit.Assert.assertNull;
21-
import static org.junit.Assert.fail;
2221

2322
import org.junit.Test;
2423

@@ -48,48 +47,44 @@ public void testAllAuthenticatedUsers() {
4847
public void testUser() {
4948
assertEquals(Identity.Type.USER, USER.type());
5049
assertEquals("[email protected]", USER.id());
51-
try {
52-
Identity.user(null);
53-
fail("Should have thrown exception due to null email address.");
54-
} catch (NullPointerException e) {
55-
// expected
56-
}
50+
}
51+
52+
@Test(expected = NullPointerException.class)
53+
public void testUserNullEmail() {
54+
Identity.user(null);
5755
}
5856

5957
@Test
6058
public void testServiceAccount() {
6159
assertEquals(Identity.Type.SERVICE_ACCOUNT, SERVICE_ACCOUNT.type());
6260
assertEquals("[email protected]", SERVICE_ACCOUNT.id());
63-
try {
64-
Identity.serviceAccount(null);
65-
fail("Should have thrown exception due to null email address.");
66-
} catch (NullPointerException e) {
67-
// expected
68-
}
61+
}
62+
63+
@Test(expected = NullPointerException.class)
64+
public void testServiceAccountNullEmail() {
65+
Identity.serviceAccount(null);
6966
}
7067

7168
@Test
7269
public void testGroup() {
7370
assertEquals(Identity.Type.GROUP, GROUP.type());
7471
assertEquals("[email protected]", GROUP.id());
75-
try {
76-
Identity.group(null);
77-
fail("Should have thrown exception due to null email address.");
78-
} catch (NullPointerException e) {
79-
// expected
80-
}
72+
}
73+
74+
@Test(expected = NullPointerException.class)
75+
public void testGroupNullEmail() {
76+
Identity.group(null);
8177
}
8278

8379
@Test
8480
public void testDomain() {
8581
assertEquals(Identity.Type.DOMAIN, DOMAIN.type());
8682
assertEquals("google.com", DOMAIN.id());
87-
try {
88-
Identity.domain(null);
89-
fail("Should have thrown exception due to null domain.");
90-
} catch (NullPointerException e) {
91-
// expected
92-
}
83+
}
84+
85+
@Test(expected = NullPointerException.class)
86+
public void testDomainNullId() {
87+
Identity.domain(null);
9388
}
9489

9590
@Test

0 commit comments

Comments
 (0)