Skip to content

Commit 27508a5

Browse files
committed
Fix gmail snippet tests
1 parent 4ceffc4 commit 27508a5

19 files changed

Lines changed: 147 additions & 130 deletions

gmail/snippets/build.gradle

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,5 +13,6 @@ dependencies {
1313
implementation 'org.apache.commons:commons-csv:1.1'
1414
testImplementation 'junit:junit:4.13.2'
1515
testImplementation 'org.hamcrest:hamcrest-all:1.3'
16-
testImplementation 'org.mockito:mockito-core:4.2.0'
16+
//testImplementation 'org.mockito:mockito-core:4.2.0'
17+
testImplementation 'org.mockito:mockito-inline:4.3.1'
1718
}

gmail/snippets/files/certs.csv

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
UserId,Certificate File Path,Certificate Password
2+
user1@example.com,files/cert.p12,password
3+
user2@example.com,files/cert.p12,
4+
user3@example.com,files/notfound.p12,

gmail/snippets/src/main/java/CreateDraft.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -52,9 +52,9 @@ public static Draft createDraftMessage(String fromEmailAddress,
5252
// Load pre-authorized user credentials from the environment.
5353
// TODO(developer) - See https://developers.google.com/identity for
5454
// guides on implementing OAuth2 for your application.
55-
GoogleCredentials credentials = GoogleCredentials.getApplicationDefault().createScoped(Collections.singletonList(GmailScopes.GMAIL_COMPOSE));
56-
HttpRequestInitializer requestInitializer = new HttpCredentialsAdapter(
57-
credentials);
55+
GoogleCredentials credentials = GoogleCredentials.getApplicationDefault()
56+
.createScoped(GmailScopes.GMAIL_COMPOSE);
57+
HttpRequestInitializer requestInitializer = new HttpCredentialsAdapter(credentials);
5858

5959
// Create the gmail API client
6060
Gmail service = new Gmail.Builder(new NetHttpTransport(),

gmail/snippets/src/main/java/CreateDraftWithAttachment.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -61,9 +61,9 @@ public static Draft createDraftMessageWithAttachment(String fromEmailAddress,
6161
// Load pre-authorized user credentials from the environment.
6262
// TODO(developer) - See https://developers.google.com/identity for
6363
// guides on implementing OAuth2 for your application.
64-
GoogleCredentials credentials = GoogleCredentials.getApplicationDefault().createScoped(Collections.singletonList(GmailScopes.GMAIL_COMPOSE));
65-
HttpRequestInitializer requestInitializer = new HttpCredentialsAdapter(
66-
credentials);
64+
GoogleCredentials credentials = GoogleCredentials.getApplicationDefault().createScoped(
65+
GmailScopes.GMAIL_COMPOSE);
66+
HttpRequestInitializer requestInitializer = new HttpCredentialsAdapter(credentials);
6767

6868
// Create the gmail API client
6969
Gmail service = new Gmail.Builder(new NetHttpTransport(),

gmail/snippets/src/main/java/CreateFilter.java

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -39,16 +39,15 @@ public class CreateFilter {
3939
*/
4040
public static String createNewFilter(String realLabelId) throws IOException {
4141
// TODO(developer) - Replace with your email address.
42-
String USER_EMAIL_ADDRESS = "gduser1@workspacesamples.dev";
42+
String userEmail = "ci-test01@workspacesamples.dev";
4343

4444
/* Load pre-authorized user credentials from the environment.
4545
TODO(developer) - See https://developers.google.com/identity for
4646
guides on implementing OAuth2 for your application. */
4747
GoogleCredentials credentials = GoogleCredentials.getApplicationDefault()
48-
.createScoped(Arrays.asList(GmailScopes.GMAIL_SETTINGS_BASIC, GmailScopes.GMAIL_LABELS))
49-
.createDelegated(USER_EMAIL_ADDRESS);
50-
HttpRequestInitializer requestInitializer = new HttpCredentialsAdapter(
51-
credentials);
48+
.createScoped(GmailScopes.GMAIL_SETTINGS_BASIC, GmailScopes.GMAIL_LABELS)
49+
.createDelegated(userEmail);
50+
HttpRequestInitializer requestInitializer = new HttpCredentialsAdapter(credentials);
5251

5352
// Create the gmail API client
5453
Gmail service = new Gmail.Builder(new NetHttpTransport(),

gmail/snippets/src/main/java/EnableAutoReply.java

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -39,16 +39,15 @@ public class EnableAutoReply {
3939
*/
4040
public static VacationSettings autoReply() throws IOException{
4141
// TODO(developer) - Replace with your email address.
42-
String USER_EMAIL_ADDRESS = "gduser1@workspacesamples.dev";
42+
String userEmail = "ci-test01@workspacesamples.dev";
4343

4444
/* Load pre-authorized user credentials from the environment.
4545
TODO(developer) - See https://developers.google.com/identity for
4646
guides on implementing OAuth2 for your application. */
4747
GoogleCredentials credentials = GoogleCredentials.getApplicationDefault()
4848
.createScoped(Collections.singleton(GmailScopes.GMAIL_SETTINGS_BASIC))
49-
.createDelegated(USER_EMAIL_ADDRESS);
50-
HttpRequestInitializer requestInitializer = new HttpCredentialsAdapter(
51-
credentials);
49+
.createDelegated(userEmail);
50+
HttpRequestInitializer requestInitializer = new HttpCredentialsAdapter(credentials);
5251

5352
// Create the gmail API client
5453
Gmail service = new Gmail.Builder(new NetHttpTransport(),

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

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -38,16 +38,15 @@ public class EnableForwarding {
3838
*/
3939
public static AutoForwarding enableAutoForwarding(String forwardingEmail) throws IOException{
4040
// TODO(developer) - Replace with your email address.
41-
String USER_EMAIL_ADDRESS = "gduser1@workspacesamples.dev";
41+
String userEmail = "ci-test01@workspacesamples.dev";
4242

4343
/* Load pre-authorized user credentials from the environment.
4444
TODO(developer) - See https://developers.google.com/identity for
4545
guides on implementing OAuth2 for your application. */
4646
GoogleCredentials credentials = GoogleCredentials.getApplicationDefault()
47-
.createScoped(Collections.singletonList(GmailScopes.GMAIL_SETTINGS_SHARING))
48-
.createDelegated(USER_EMAIL_ADDRESS);
49-
HttpRequestInitializer requestInitializer = new HttpCredentialsAdapter(
50-
credentials);
47+
.createScoped(GmailScopes.GMAIL_SETTINGS_SHARING)
48+
.createDelegated(userEmail);
49+
HttpRequestInitializer requestInitializer = new HttpCredentialsAdapter(credentials);
5150

5251
// Create the gmail API client
5352
Gmail service = new Gmail.Builder(new NetHttpTransport(),

gmail/snippets/src/main/java/SendEmail.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
import com.google.api.client.repackaged.org.apache.commons.codec.binary.Base64;
21
import com.google.api.services.gmail.Gmail;
32
import com.google.api.services.gmail.model.Draft;
43
import com.google.api.services.gmail.model.Message;
4+
import org.apache.commons.codec.binary.Base64;
55

66
import java.io.ByteArrayOutputStream;
77
import java.io.File;

gmail/snippets/src/main/java/SendMessage.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -52,9 +52,9 @@ public static Message sendEmail(String fromEmailAddress,
5252
// Load pre-authorized user credentials from the environment.
5353
// TODO(developer) - See https://developers.google.com/identity for
5454
// guides on implementing OAuth2 for your application.
55-
GoogleCredentials credentials = GoogleCredentials.getApplicationDefault().createScoped(Collections.singletonList(GmailScopes.GMAIL_SEND));
56-
HttpRequestInitializer requestInitializer = new HttpCredentialsAdapter(
57-
credentials);
55+
GoogleCredentials credentials = GoogleCredentials.getApplicationDefault()
56+
.createScoped(GmailScopes.GMAIL_SEND);
57+
HttpRequestInitializer requestInitializer = new HttpCredentialsAdapter(credentials);
5858

5959
// Create the gmail API client
6060
Gmail service = new Gmail.Builder(new NetHttpTransport(),

gmail/snippets/src/main/java/SendMessageWithAttachment.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -61,9 +61,9 @@ public static Message sendEmailWithAttachment(String fromEmailAddress,
6161
// Load pre-authorized user credentials from the environment.
6262
// TODO(developer) - See https://developers.google.com/identity for
6363
// guides on implementing OAuth2 for your application.
64-
GoogleCredentials credentials = GoogleCredentials.getApplicationDefault().createScoped(Collections.singletonList(GmailScopes.GMAIL_SEND));
65-
HttpRequestInitializer requestInitializer = new HttpCredentialsAdapter(
66-
credentials);
64+
GoogleCredentials credentials = GoogleCredentials.getApplicationDefault()
65+
.createScoped(GmailScopes.GMAIL_SEND);
66+
HttpRequestInitializer requestInitializer = new HttpCredentialsAdapter(credentials);
6767

6868
// Create the gmail API client
6969
Gmail service = new Gmail.Builder(new NetHttpTransport(),

0 commit comments

Comments
 (0)