Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Checkstyle fixes for Cloud Storage transfer sample. #111

Merged
merged 2 commits into from
Mar 16, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 0 additions & 13 deletions storage/storage-transfer/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -59,17 +59,4 @@
<scope>test</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.1</version>
<configuration>
<source>1.7</source>
<target>1.7</target>
</configuration>
</plugin>
</plugins>
</build>
</project>
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/**
/*
* Copyright 2015 Google Inc. All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
Expand All @@ -16,6 +16,7 @@

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

import static org.junit.Assert.assertEquals;
import static org.mockito.Mockito.when;

import com.google.api.services.storagetransfer.Storagetransfer;
Expand All @@ -30,8 +31,6 @@
import com.google.cloud.storage.storagetransfer.samples.TransferClientCreator;
import com.google.cloud.storage.storagetransfer.samples.TransferJobUtils;

import junit.framework.TestCase;

import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Matchers;
Expand All @@ -42,7 +41,7 @@

@RunWith(PowerMockRunner.class)
@PrepareForTest({ TransferJobUtils.class, TransferClientCreator.class })
public class AwsRequesterTest extends TestCase {
public class AwsRequesterTest {

/**
* Tests whether AwsRequester executes a request to create a TransferJob.
Expand All @@ -52,13 +51,13 @@ public void testTest() throws Exception {
Date date = TransferJobUtils.createDate("2000-1-1");
TimeOfDay time = TransferJobUtils.createTimeOfDay("1:1:1");
TransferJob dummyJob = TransferJob.class
.newInstance()
.setDescription("DUMMY DESCRIPTION")
.setProjectId("DUMMY_PROJECT_ID")
.setTransferSpec(TransferSpec.class.newInstance())
.setSchedule(
Schedule.class.newInstance().setScheduleStartDate(date).setScheduleEndDate(date)
.setStartTimeOfDay(time)).setStatus("ENABLED");
.newInstance()
.setDescription("DUMMY DESCRIPTION")
.setProjectId("DUMMY_PROJECT_ID")
.setTransferSpec(TransferSpec.class.newInstance())
.setSchedule(
Schedule.class.newInstance().setScheduleStartDate(date).setScheduleEndDate(date)
.setStartTimeOfDay(time)).setStatus("ENABLED");

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

assertEquals(returnedJob, dummyJob);
}
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/**
/*
* Copyright 2015 Google Inc. All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
Expand All @@ -16,16 +16,8 @@

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

import static org.junit.Assert.assertEquals;
import static org.mockito.Mockito.when;
import junit.framework.TestCase;

import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Matchers;
import org.mockito.Mockito;
import org.powermock.api.mockito.PowerMockito;
import org.powermock.core.classloader.annotations.PrepareForTest;
import org.powermock.modules.junit4.PowerMockRunner;

import com.google.api.services.storagetransfer.Storagetransfer;
import com.google.api.services.storagetransfer.Storagetransfer.TransferJobs;
Expand All @@ -39,9 +31,17 @@
import com.google.cloud.storage.storagetransfer.samples.TransferClientCreator;
import com.google.cloud.storage.storagetransfer.samples.TransferJobUtils;

import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Matchers;
import org.mockito.Mockito;
import org.powermock.api.mockito.PowerMockito;
import org.powermock.core.classloader.annotations.PrepareForTest;
import org.powermock.modules.junit4.PowerMockRunner;

@RunWith(PowerMockRunner.class)
@PrepareForTest({ TransferJobUtils.class, TransferClientCreator.class })
public class NearlineRequesterTest extends TestCase {
public class NearlineRequesterTest {

/**
* Tests whether NearlineRequester executes a request to create a TransferJob.
Expand All @@ -51,13 +51,13 @@ public void testTest() throws Exception {
Date date = TransferJobUtils.createDate("2000-1-1");
TimeOfDay time = TransferJobUtils.createTimeOfDay("1:1:1");
TransferJob dummyJob = TransferJob.class
.newInstance()
.setDescription("DUMMY DESCRIPTION")
.setProjectId("DUMMY_PROJECT_ID")
.setTransferSpec(TransferSpec.class.newInstance())
.setSchedule(
Schedule.class.newInstance().setScheduleStartDate(date).setScheduleEndDate(date)
.setStartTimeOfDay(time)).setStatus("ENABLED");
.newInstance()
.setDescription("DUMMY DESCRIPTION")
.setProjectId("DUMMY_PROJECT_ID")
.setTransferSpec(TransferSpec.class.newInstance())
.setSchedule(
Schedule.class.newInstance().setScheduleStartDate(date).setScheduleEndDate(date)
.setStartTimeOfDay(time)).setStatus("ENABLED");

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

assertEquals(returnedJob, dummyJob);
}
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/**
/*
* Copyright 2015 Google Inc. All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
Expand All @@ -18,18 +18,17 @@

import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
import junit.framework.TestCase;

import org.junit.Test;
import org.mockito.Matchers;
import org.mockito.Mockito;

import com.google.api.services.storagetransfer.Storagetransfer;
import com.google.api.services.storagetransfer.Storagetransfer.TransferOperations;
import com.google.api.services.storagetransfer.Storagetransfer.TransferOperations.List;
import com.google.cloud.storage.storagetransfer.samples.RequestChecker;

public class RequestCheckerTest extends TestCase {
import org.junit.Test;
import org.mockito.Matchers;
import org.mockito.Mockito;

public class RequestCheckerTest {
private Storagetransfer mockClient = Mockito.mock(Storagetransfer.class);
private List mockList = Mockito.mock(List.class);
private TransferOperations mockOps = Mockito.mock(TransferOperations.class);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/**
/*
* Copyright 2015 Google Inc. All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
Expand All @@ -18,7 +18,14 @@

import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
import junit.framework.TestCase;

import com.google.api.client.googleapis.auth.oauth2.GoogleCredential;
import com.google.api.client.googleapis.util.Utils;
import com.google.api.client.http.HttpTransport;
import com.google.api.client.json.JsonFactory;
import com.google.api.services.storagetransfer.Storagetransfer.Builder;
import com.google.cloud.storage.storagetransfer.samples.RetryHttpInitializerWrapper;
import com.google.cloud.storage.storagetransfer.samples.TransferClientCreator;

import org.junit.Before;
import org.junit.Test;
Expand All @@ -29,32 +36,24 @@
import org.powermock.core.classloader.annotations.PrepareForTest;
import org.powermock.modules.junit4.PowerMockRunner;

import com.google.api.client.googleapis.auth.oauth2.GoogleCredential;
import com.google.api.client.googleapis.util.Utils;
import com.google.api.client.http.HttpTransport;
import com.google.api.client.json.JsonFactory;
import com.google.api.services.storagetransfer.Storagetransfer.Builder;
import com.google.cloud.storage.storagetransfer.samples.RetryHttpInitializerWrapper;
import com.google.cloud.storage.storagetransfer.samples.TransferClientCreator;

@RunWith(PowerMockRunner.class)
@PrepareForTest({ TransferClientCreator.class, Builder.class })
public class TransferClientCreatorTest extends TestCase {
public class TransferClientCreatorTest {

private Builder mockBuilder = PowerMockito.mock(Builder.class);
private GoogleCredential mockCredential = Mockito.mock(GoogleCredential.class);
private RetryHttpInitializerWrapper mockInitializer = Mockito
.mock(RetryHttpInitializerWrapper.class);
private RetryHttpInitializerWrapper mockInitializer =
Mockito.mock(RetryHttpInitializerWrapper.class);
private HttpTransport httpTransport = Utils.getDefaultTransport();
private JsonFactory jsonFactory = Utils.getDefaultJsonFactory();

@Before
public void setUp() throws Exception {
PowerMockito.whenNew(RetryHttpInitializerWrapper.class).withArguments(mockCredential)
.thenReturn(mockInitializer);
.thenReturn(mockInitializer);
PowerMockito.mockStatic(Builder.class);
PowerMockito.whenNew(Builder.class).withArguments(httpTransport, jsonFactory, mockInitializer)
.thenReturn(mockBuilder);
.thenReturn(mockBuilder);
when(mockBuilder.setApplicationName(Matchers.anyString())).thenReturn(mockBuilder);
PowerMockito.mockStatic(GoogleCredential.class);
}
Expand All @@ -67,8 +66,8 @@ public void setUp() throws Exception {
public void testCreateStorageTransferClientScopedRequiredFalse() throws Exception {
when(mockCredential.createScopedRequired()).thenReturn(false);

TransferClientCreator.createStorageTransferClient(Utils.getDefaultTransport(),
Utils.getDefaultJsonFactory(), mockCredential);
TransferClientCreator.createStorageTransferClient(
Utils.getDefaultTransport(), Utils.getDefaultJsonFactory(), mockCredential);

verify(mockBuilder).build();
}
Expand All @@ -80,11 +79,11 @@ public void testCreateStorageTransferClientScopedRequiredFalse() throws Exceptio
@Test
public void testCreateStorageTransferClientScopedRequiredTrue() throws Exception {
when(mockCredential.createScopedRequired()).thenReturn(true);
when(mockCredential.createScoped(Matchers.anyCollectionOf(String.class))).thenReturn(
mockCredential);
when(mockCredential.createScoped(Matchers.anyCollectionOf(String.class)))
.thenReturn(mockCredential);

TransferClientCreator.createStorageTransferClient(Utils.getDefaultTransport(),
Utils.getDefaultJsonFactory(), mockCredential);
TransferClientCreator.createStorageTransferClient(
Utils.getDefaultTransport(), Utils.getDefaultJsonFactory(), mockCredential);

verify(mockBuilder).build();
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/**
/*
* Copyright 2015 Google Inc. All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
Expand All @@ -16,29 +16,29 @@

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

import java.util.Random;

import junit.framework.TestCase;

import org.junit.Test;
import static org.junit.Assert.assertEquals;

import com.google.api.services.storagetransfer.model.Date;
import com.google.api.services.storagetransfer.model.TimeOfDay;
import com.google.cloud.storage.storagetransfer.samples.TransferJobUtils;

public class TransferJobUtilsTest extends TestCase {
private Random r = new Random();
import org.junit.Test;

import java.util.Random;

public class TransferJobUtilsTest {
private Random rand = new Random();

/**
* Tests whether createDate() builds the correct date from a formatted String.
*/
@Test
public void testCreateDate() throws Exception {
int year = r.nextInt(2000) + 1;
int month = r.nextInt(12) + 1;
int day = r.nextInt(30) + 1;
String dateString = Integer.toString(year) + "-" + Integer.toString(month) + "-"
+ Integer.toString(day);
int year = rand.nextInt(2000) + 1;
int month = rand.nextInt(12) + 1;
int day = rand.nextInt(30) + 1;
String dateString =
Integer.toString(year) + "-" + Integer.toString(month) + "-" + Integer.toString(day);

Date date = TransferJobUtils.createDate(dateString);

Expand All @@ -50,16 +50,15 @@ public void testCreateDate() throws Exception {
*/
@Test
public void testCreateTimeOfDay() throws Exception {
int hour = r.nextInt(24);
int minute = r.nextInt(60);
int second = r.nextInt(60);
String timeString = Integer.toString(hour) + ":" + Integer.toString(minute) + ":"
+ Integer.toString(second);
int hour = rand.nextInt(24);
int minute = rand.nextInt(60);
int second = rand.nextInt(60);
String timeString =
Integer.toString(hour) + ":" + Integer.toString(minute) + ":" + Integer.toString(second);

TimeOfDay time = TransferJobUtils.createTimeOfDay(timeString);

assertEquals(time,
TimeOfDay.class.newInstance().setHours(hour).setMinutes(minute).setSeconds(second));

TimeOfDay.class.newInstance().setHours(hour).setMinutes(minute).setSeconds(second));
}
}
}
17 changes: 3 additions & 14 deletions storage/xml-api/cmdline-sample/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -65,22 +65,11 @@
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.hamcrest</groupId>
<artifactId>hamcrest-core</artifactId>
<version>1.3</version>
<groupId>com.google.truth</groupId>
<artifactId>truth</artifactId>
<version>0.28</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.hamcrest</groupId>
<artifactId>hamcrest-library</artifactId>
<version>1.3</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.jcabi</groupId>
<artifactId>jcabi-matchers</artifactId>
<version>1.3</version>
</dependency>
</dependencies>
<properties>
<project.http.version>1.20.0</project.http.version>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/**
/*
* Copyright 2015 Google Inc. All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
Expand All @@ -15,22 +15,19 @@
*/

// [START StorageSampleTest]

import static com.jcabi.matchers.RegexMatchers.*;
import static org.junit.Assert.assertThat;
import static com.google.common.truth.Truth.assertThat;

import org.junit.Test;

import java.util.regex.Pattern;

public class StorageSampleTest {
@Test
public void testListBucket() throws Exception {
String listing = StorageSample.listBucket("cloud-samples-tests");
assertThat(listing, matchesPattern(
".*<ListBucketResult.*"
+ "<Name>cloud-samples-tests</Name>.*"
+ "</ListBucketResult>.*"));
assertThat(listing)
.containsMatch(
".*<ListBucketResult.*"
+ "<Name>cloud-samples-tests</Name>.*"
+ "</ListBucketResult>.*");
}
}

Expand Down