Skip to content

Commit 011b32f

Browse files
committed
Merge pull request #111 from GoogleCloudPlatform/cststyle
Checkstyle fixes for Cloud Storage transfer sample.
2 parents 980a739 + 7d4d832 commit 011b32f

File tree

8 files changed

+86
-117
lines changed

8 files changed

+86
-117
lines changed

storage/storage-transfer/pom.xml

-13
Original file line numberDiff line numberDiff line change
@@ -59,17 +59,4 @@
5959
<scope>test</scope>
6060
</dependency>
6161
</dependencies>
62-
<build>
63-
<plugins>
64-
<plugin>
65-
<groupId>org.apache.maven.plugins</groupId>
66-
<artifactId>maven-compiler-plugin</artifactId>
67-
<version>3.1</version>
68-
<configuration>
69-
<source>1.7</source>
70-
<target>1.7</target>
71-
</configuration>
72-
</plugin>
73-
</plugins>
74-
</build>
7562
</project>

storage/storage-transfer/src/test/java/com/google/cloud/storage/storagetransfer/samples/test/AwsRequesterTest.java

+11-12
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/**
1+
/*
22
* Copyright 2015 Google Inc. All Rights Reserved.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
@@ -16,6 +16,7 @@
1616

1717
package com.google.cloud.storage.storagetransfer.samples.test;
1818

19+
import static org.junit.Assert.assertEquals;
1920
import static org.mockito.Mockito.when;
2021

2122
import com.google.api.services.storagetransfer.Storagetransfer;
@@ -30,8 +31,6 @@
3031
import com.google.cloud.storage.storagetransfer.samples.TransferClientCreator;
3132
import com.google.cloud.storage.storagetransfer.samples.TransferJobUtils;
3233

33-
import junit.framework.TestCase;
34-
3534
import org.junit.Test;
3635
import org.junit.runner.RunWith;
3736
import org.mockito.Matchers;
@@ -42,7 +41,7 @@
4241

4342
@RunWith(PowerMockRunner.class)
4443
@PrepareForTest({ TransferJobUtils.class, TransferClientCreator.class })
45-
public class AwsRequesterTest extends TestCase {
44+
public class AwsRequesterTest {
4645

4746
/**
4847
* Tests whether AwsRequester executes a request to create a TransferJob.
@@ -52,13 +51,13 @@ public void testTest() throws Exception {
5251
Date date = TransferJobUtils.createDate("2000-1-1");
5352
TimeOfDay time = TransferJobUtils.createTimeOfDay("1:1:1");
5453
TransferJob dummyJob = TransferJob.class
55-
.newInstance()
56-
.setDescription("DUMMY DESCRIPTION")
57-
.setProjectId("DUMMY_PROJECT_ID")
58-
.setTransferSpec(TransferSpec.class.newInstance())
59-
.setSchedule(
60-
Schedule.class.newInstance().setScheduleStartDate(date).setScheduleEndDate(date)
61-
.setStartTimeOfDay(time)).setStatus("ENABLED");
54+
.newInstance()
55+
.setDescription("DUMMY DESCRIPTION")
56+
.setProjectId("DUMMY_PROJECT_ID")
57+
.setTransferSpec(TransferSpec.class.newInstance())
58+
.setSchedule(
59+
Schedule.class.newInstance().setScheduleStartDate(date).setScheduleEndDate(date)
60+
.setStartTimeOfDay(time)).setStatus("ENABLED");
6261

6362
PowerMockito.mockStatic(TransferClientCreator.class);
6463
PowerMockito.mockStatic(TransferJobUtils.class);
@@ -75,4 +74,4 @@ public void testTest() throws Exception {
7574

7675
assertEquals(returnedJob, dummyJob);
7776
}
78-
}
77+
}

storage/storage-transfer/src/test/java/com/google/cloud/storage/storagetransfer/samples/test/NearlineRequesterTest.java

+19-19
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/**
1+
/*
22
* Copyright 2015 Google Inc. All Rights Reserved.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
@@ -16,16 +16,8 @@
1616

1717
package com.google.cloud.storage.storagetransfer.samples.test;
1818

19+
import static org.junit.Assert.assertEquals;
1920
import static org.mockito.Mockito.when;
20-
import junit.framework.TestCase;
21-
22-
import org.junit.Test;
23-
import org.junit.runner.RunWith;
24-
import org.mockito.Matchers;
25-
import org.mockito.Mockito;
26-
import org.powermock.api.mockito.PowerMockito;
27-
import org.powermock.core.classloader.annotations.PrepareForTest;
28-
import org.powermock.modules.junit4.PowerMockRunner;
2921

3022
import com.google.api.services.storagetransfer.Storagetransfer;
3123
import com.google.api.services.storagetransfer.Storagetransfer.TransferJobs;
@@ -39,9 +31,17 @@
3931
import com.google.cloud.storage.storagetransfer.samples.TransferClientCreator;
4032
import com.google.cloud.storage.storagetransfer.samples.TransferJobUtils;
4133

34+
import org.junit.Test;
35+
import org.junit.runner.RunWith;
36+
import org.mockito.Matchers;
37+
import org.mockito.Mockito;
38+
import org.powermock.api.mockito.PowerMockito;
39+
import org.powermock.core.classloader.annotations.PrepareForTest;
40+
import org.powermock.modules.junit4.PowerMockRunner;
41+
4242
@RunWith(PowerMockRunner.class)
4343
@PrepareForTest({ TransferJobUtils.class, TransferClientCreator.class })
44-
public class NearlineRequesterTest extends TestCase {
44+
public class NearlineRequesterTest {
4545

4646
/**
4747
* Tests whether NearlineRequester executes a request to create a TransferJob.
@@ -51,13 +51,13 @@ public void testTest() throws Exception {
5151
Date date = TransferJobUtils.createDate("2000-1-1");
5252
TimeOfDay time = TransferJobUtils.createTimeOfDay("1:1:1");
5353
TransferJob dummyJob = TransferJob.class
54-
.newInstance()
55-
.setDescription("DUMMY DESCRIPTION")
56-
.setProjectId("DUMMY_PROJECT_ID")
57-
.setTransferSpec(TransferSpec.class.newInstance())
58-
.setSchedule(
59-
Schedule.class.newInstance().setScheduleStartDate(date).setScheduleEndDate(date)
60-
.setStartTimeOfDay(time)).setStatus("ENABLED");
54+
.newInstance()
55+
.setDescription("DUMMY DESCRIPTION")
56+
.setProjectId("DUMMY_PROJECT_ID")
57+
.setTransferSpec(TransferSpec.class.newInstance())
58+
.setSchedule(
59+
Schedule.class.newInstance().setScheduleStartDate(date).setScheduleEndDate(date)
60+
.setStartTimeOfDay(time)).setStatus("ENABLED");
6161

6262
PowerMockito.mockStatic(TransferClientCreator.class);
6363
PowerMockito.mockStatic(TransferJobUtils.class);
@@ -74,4 +74,4 @@ public void testTest() throws Exception {
7474

7575
assertEquals(returnedJob, dummyJob);
7676
}
77-
}
77+
}

storage/storage-transfer/src/test/java/com/google/cloud/storage/storagetransfer/samples/test/RequestCheckerTest.java

+6-7
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/**
1+
/*
22
* Copyright 2015 Google Inc. All Rights Reserved.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
@@ -18,18 +18,17 @@
1818

1919
import static org.mockito.Mockito.verify;
2020
import static org.mockito.Mockito.when;
21-
import junit.framework.TestCase;
22-
23-
import org.junit.Test;
24-
import org.mockito.Matchers;
25-
import org.mockito.Mockito;
2621

2722
import com.google.api.services.storagetransfer.Storagetransfer;
2823
import com.google.api.services.storagetransfer.Storagetransfer.TransferOperations;
2924
import com.google.api.services.storagetransfer.Storagetransfer.TransferOperations.List;
3025
import com.google.cloud.storage.storagetransfer.samples.RequestChecker;
3126

32-
public class RequestCheckerTest extends TestCase {
27+
import org.junit.Test;
28+
import org.mockito.Matchers;
29+
import org.mockito.Mockito;
30+
31+
public class RequestCheckerTest {
3332
private Storagetransfer mockClient = Mockito.mock(Storagetransfer.class);
3433
private List mockList = Mockito.mock(List.class);
3534
private TransferOperations mockOps = Mockito.mock(TransferOperations.class);

storage/storage-transfer/src/test/java/com/google/cloud/storage/storagetransfer/samples/test/TransferClientCreatorTest.java

+20-21
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/**
1+
/*
22
* Copyright 2015 Google Inc. All Rights Reserved.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
@@ -18,7 +18,14 @@
1818

1919
import static org.mockito.Mockito.verify;
2020
import static org.mockito.Mockito.when;
21-
import junit.framework.TestCase;
21+
22+
import com.google.api.client.googleapis.auth.oauth2.GoogleCredential;
23+
import com.google.api.client.googleapis.util.Utils;
24+
import com.google.api.client.http.HttpTransport;
25+
import com.google.api.client.json.JsonFactory;
26+
import com.google.api.services.storagetransfer.Storagetransfer.Builder;
27+
import com.google.cloud.storage.storagetransfer.samples.RetryHttpInitializerWrapper;
28+
import com.google.cloud.storage.storagetransfer.samples.TransferClientCreator;
2229

2330
import org.junit.Before;
2431
import org.junit.Test;
@@ -29,32 +36,24 @@
2936
import org.powermock.core.classloader.annotations.PrepareForTest;
3037
import org.powermock.modules.junit4.PowerMockRunner;
3138

32-
import com.google.api.client.googleapis.auth.oauth2.GoogleCredential;
33-
import com.google.api.client.googleapis.util.Utils;
34-
import com.google.api.client.http.HttpTransport;
35-
import com.google.api.client.json.JsonFactory;
36-
import com.google.api.services.storagetransfer.Storagetransfer.Builder;
37-
import com.google.cloud.storage.storagetransfer.samples.RetryHttpInitializerWrapper;
38-
import com.google.cloud.storage.storagetransfer.samples.TransferClientCreator;
39-
4039
@RunWith(PowerMockRunner.class)
4140
@PrepareForTest({ TransferClientCreator.class, Builder.class })
42-
public class TransferClientCreatorTest extends TestCase {
41+
public class TransferClientCreatorTest {
4342

4443
private Builder mockBuilder = PowerMockito.mock(Builder.class);
4544
private GoogleCredential mockCredential = Mockito.mock(GoogleCredential.class);
46-
private RetryHttpInitializerWrapper mockInitializer = Mockito
47-
.mock(RetryHttpInitializerWrapper.class);
45+
private RetryHttpInitializerWrapper mockInitializer =
46+
Mockito.mock(RetryHttpInitializerWrapper.class);
4847
private HttpTransport httpTransport = Utils.getDefaultTransport();
4948
private JsonFactory jsonFactory = Utils.getDefaultJsonFactory();
5049

5150
@Before
5251
public void setUp() throws Exception {
5352
PowerMockito.whenNew(RetryHttpInitializerWrapper.class).withArguments(mockCredential)
54-
.thenReturn(mockInitializer);
53+
.thenReturn(mockInitializer);
5554
PowerMockito.mockStatic(Builder.class);
5655
PowerMockito.whenNew(Builder.class).withArguments(httpTransport, jsonFactory, mockInitializer)
57-
.thenReturn(mockBuilder);
56+
.thenReturn(mockBuilder);
5857
when(mockBuilder.setApplicationName(Matchers.anyString())).thenReturn(mockBuilder);
5958
PowerMockito.mockStatic(GoogleCredential.class);
6059
}
@@ -67,8 +66,8 @@ public void setUp() throws Exception {
6766
public void testCreateStorageTransferClientScopedRequiredFalse() throws Exception {
6867
when(mockCredential.createScopedRequired()).thenReturn(false);
6968

70-
TransferClientCreator.createStorageTransferClient(Utils.getDefaultTransport(),
71-
Utils.getDefaultJsonFactory(), mockCredential);
69+
TransferClientCreator.createStorageTransferClient(
70+
Utils.getDefaultTransport(), Utils.getDefaultJsonFactory(), mockCredential);
7271

7372
verify(mockBuilder).build();
7473
}
@@ -80,11 +79,11 @@ public void testCreateStorageTransferClientScopedRequiredFalse() throws Exceptio
8079
@Test
8180
public void testCreateStorageTransferClientScopedRequiredTrue() throws Exception {
8281
when(mockCredential.createScopedRequired()).thenReturn(true);
83-
when(mockCredential.createScoped(Matchers.anyCollectionOf(String.class))).thenReturn(
84-
mockCredential);
82+
when(mockCredential.createScoped(Matchers.anyCollectionOf(String.class)))
83+
.thenReturn(mockCredential);
8584

86-
TransferClientCreator.createStorageTransferClient(Utils.getDefaultTransport(),
87-
Utils.getDefaultJsonFactory(), mockCredential);
85+
TransferClientCreator.createStorageTransferClient(
86+
Utils.getDefaultTransport(), Utils.getDefaultJsonFactory(), mockCredential);
8887

8988
verify(mockBuilder).build();
9089
}
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/**
1+
/*
22
* Copyright 2015 Google Inc. All Rights Reserved.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
@@ -16,29 +16,29 @@
1616

1717
package com.google.cloud.storage.storagetransfer.samples.test;
1818

19-
import java.util.Random;
20-
21-
import junit.framework.TestCase;
22-
23-
import org.junit.Test;
19+
import static org.junit.Assert.assertEquals;
2420

2521
import com.google.api.services.storagetransfer.model.Date;
2622
import com.google.api.services.storagetransfer.model.TimeOfDay;
2723
import com.google.cloud.storage.storagetransfer.samples.TransferJobUtils;
2824

29-
public class TransferJobUtilsTest extends TestCase {
30-
private Random r = new Random();
25+
import org.junit.Test;
26+
27+
import java.util.Random;
28+
29+
public class TransferJobUtilsTest {
30+
private Random rand = new Random();
3131

3232
/**
3333
* Tests whether createDate() builds the correct date from a formatted String.
3434
*/
3535
@Test
3636
public void testCreateDate() throws Exception {
37-
int year = r.nextInt(2000) + 1;
38-
int month = r.nextInt(12) + 1;
39-
int day = r.nextInt(30) + 1;
40-
String dateString = Integer.toString(year) + "-" + Integer.toString(month) + "-"
41-
+ Integer.toString(day);
37+
int year = rand.nextInt(2000) + 1;
38+
int month = rand.nextInt(12) + 1;
39+
int day = rand.nextInt(30) + 1;
40+
String dateString =
41+
Integer.toString(year) + "-" + Integer.toString(month) + "-" + Integer.toString(day);
4242

4343
Date date = TransferJobUtils.createDate(dateString);
4444

@@ -50,16 +50,15 @@ public void testCreateDate() throws Exception {
5050
*/
5151
@Test
5252
public void testCreateTimeOfDay() throws Exception {
53-
int hour = r.nextInt(24);
54-
int minute = r.nextInt(60);
55-
int second = r.nextInt(60);
56-
String timeString = Integer.toString(hour) + ":" + Integer.toString(minute) + ":"
57-
+ Integer.toString(second);
53+
int hour = rand.nextInt(24);
54+
int minute = rand.nextInt(60);
55+
int second = rand.nextInt(60);
56+
String timeString =
57+
Integer.toString(hour) + ":" + Integer.toString(minute) + ":" + Integer.toString(second);
5858

5959
TimeOfDay time = TransferJobUtils.createTimeOfDay(timeString);
6060

6161
assertEquals(time,
62-
TimeOfDay.class.newInstance().setHours(hour).setMinutes(minute).setSeconds(second));
63-
62+
TimeOfDay.class.newInstance().setHours(hour).setMinutes(minute).setSeconds(second));
6463
}
65-
}
64+
}

storage/xml-api/cmdline-sample/pom.xml

+3-14
Original file line numberDiff line numberDiff line change
@@ -65,22 +65,11 @@
6565
<scope>test</scope>
6666
</dependency>
6767
<dependency>
68-
<groupId>org.hamcrest</groupId>
69-
<artifactId>hamcrest-core</artifactId>
70-
<version>1.3</version>
68+
<groupId>com.google.truth</groupId>
69+
<artifactId>truth</artifactId>
70+
<version>0.28</version>
7171
<scope>test</scope>
7272
</dependency>
73-
<dependency>
74-
<groupId>org.hamcrest</groupId>
75-
<artifactId>hamcrest-library</artifactId>
76-
<version>1.3</version>
77-
<scope>test</scope>
78-
</dependency>
79-
<dependency>
80-
<groupId>com.jcabi</groupId>
81-
<artifactId>jcabi-matchers</artifactId>
82-
<version>1.3</version>
83-
</dependency>
8473
</dependencies>
8574
<properties>
8675
<project.http.version>1.20.0</project.http.version>

storage/xml-api/cmdline-sample/src/test/java/StorageSampleTest.java

+7-10
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/**
1+
/*
22
* Copyright 2015 Google Inc. All Rights Reserved.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
@@ -15,22 +15,19 @@
1515
*/
1616

1717
// [START StorageSampleTest]
18-
19-
import static com.jcabi.matchers.RegexMatchers.*;
20-
import static org.junit.Assert.assertThat;
18+
import static com.google.common.truth.Truth.assertThat;
2119

2220
import org.junit.Test;
2321

24-
import java.util.regex.Pattern;
25-
2622
public class StorageSampleTest {
2723
@Test
2824
public void testListBucket() throws Exception {
2925
String listing = StorageSample.listBucket("cloud-samples-tests");
30-
assertThat(listing, matchesPattern(
31-
".*<ListBucketResult.*"
32-
+ "<Name>cloud-samples-tests</Name>.*"
33-
+ "</ListBucketResult>.*"));
26+
assertThat(listing)
27+
.containsMatch(
28+
".*<ListBucketResult.*"
29+
+ "<Name>cloud-samples-tests</Name>.*"
30+
+ "</ListBucketResult>.*");
3431
}
3532
}
3633

0 commit comments

Comments
 (0)