Skip to content

Commit 861b132

Browse files
RajeshGovosanjuktaghosh7Manvendra-P-Singh
authored
Unit Test Case for gmail_enable_forwarding (googleworkspace#189)
* git-on-borg files of gmail-api-snippets * Update build.gradle test12 * Update build.gradle * Unit Test Case for gmail_enable_forwarding * Update EnableForwarding.java Co-authored-by: sanjuktaghosh7 <sanjuktaghosh@google.com> Co-authored-by: Manvendra-P-Singh <singhmanvendra@google.com>
1 parent a4c3d39 commit 861b132

2 files changed

Lines changed: 41 additions & 5 deletions

File tree

gmail/snippets/src/main/java/EnableForwarding.java

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -37,10 +37,15 @@ public class EnableForwarding {
3737
* @throws IOException if service account credentials file not found.
3838
*/
3939
public static AutoForwarding enableAutoForwarding(String forwardingEmail) throws IOException{
40-
// Load pre-authorized user credentials from the environment.
41-
// TODO(developer) - See https://developers.google.com/identity for
42-
// guides on implementing OAuth2 for your application.
43-
GoogleCredentials credentials = GoogleCredentials.getApplicationDefault().createScoped(Collections.singletonList(GmailScopes.GMAIL_SETTINGS_SHARING));
40+
// TODO(developer) - Replace with your email address.
41+
String USER_EMAIL_ADDRESS = "gduser1@workspacesamples.dev";
42+
43+
/* Load pre-authorized user credentials from the environment.
44+
TODO(developer) - See https://developers.google.com/identity for
45+
guides on implementing OAuth2 for your application. */
46+
GoogleCredentials credentials = GoogleCredentials.getApplicationDefault()
47+
.createScoped(Collections.singletonList(GmailScopes.GMAIL_SETTINGS_SHARING))
48+
.createDelegated(USER_EMAIL_ADDRESS);
4449
HttpRequestInitializer requestInitializer = new HttpCredentialsAdapter(
4550
credentials);
4651

@@ -74,4 +79,4 @@ public static AutoForwarding enableAutoForwarding(String forwardingEmail) throws
7479
return null;
7580
}
7681
}
77-
// [END gmail_enable_forwarding]
82+
// [END gmail_enable_forwarding]
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
// Copyright 2022 Google LLC
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// https://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
16+
import com.google.api.services.gmail.model.AutoForwarding;
17+
import org.junit.Test;
18+
import java.io.IOException;
19+
import static org.junit.Assert.assertNotNull;
20+
21+
public class TestEnableForwarding extends BaseTest {
22+
23+
@Test
24+
public void TestEnableAutoForwarding() throws IOException {
25+
AutoForwarding forwarding = EnableForwarding.enableAutoForwarding(FORWARDING_ADDRESS);
26+
assertNotNull(forwarding);
27+
forwarding = new AutoForwarding().setEnabled(false);
28+
this.service.users().settings().updateAutoForwarding("me", forwarding).execute();
29+
this.service.users().settings().forwardingAddresses().delete("me", FORWARDING_ADDRESS).execute();
30+
}
31+
}

0 commit comments

Comments
 (0)