Skip to content
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
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;

import com.google.api.gax.paging.Page;
import com.google.cloud.MonitoredResource;
Expand All @@ -44,7 +45,6 @@
import java.util.logging.Logger;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.ExpectedException;
import org.junit.rules.Timeout;

/**
Expand All @@ -53,8 +53,6 @@
*/
public abstract class BaseSystemTest {

@Rule public ExpectedException thrown = ExpectedException.none();

@Rule public Timeout globalTimeout = Timeout.seconds(300);

/**
Expand Down Expand Up @@ -114,9 +112,12 @@ public void testUpdateNonExistingSink() {
.setVersionFormat(SinkInfo.VersionFormat.V2)
.build();
assertNull(logging().getSink(name));
thrown.expect(LoggingException.class);
thrown.expectMessage("NOT_FOUND");
logging().update(sinkInfo);
try {
logging().update(sinkInfo);
fail();
} catch (LoggingException expected) {
assertNotNull(expected.getMessage());
}
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,7 @@
import static org.junit.Assert.assertTrue;

import com.google.cloud.logging.HttpRequest.RequestMethod;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.ExpectedException;
import org.threeten.bp.Duration;

public class HttpRequestTest {
Expand Down Expand Up @@ -61,8 +59,6 @@ public class HttpRequestTest {
.setLatency(Duration.ofSeconds(123, 456))
.build();

@Rule public ExpectedException thrown = ExpectedException.none();

@Test
public void testBuilder() {
assertEquals(REQUEST_METHOD, HTTP_REQUEST.getRequestMethod());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,9 +75,7 @@
import org.easymock.EasyMock;
import org.junit.After;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.ExpectedException;

public class LoggingImplTest {

Expand Down Expand Up @@ -143,8 +141,6 @@ public com.google.api.MonitoredResourceDescriptor apply(
private LoggingRpc loggingRpcMock;
private Logging logging;

@Rule public ExpectedException thrown = ExpectedException.none();

@Before
public void setUp() {
rpcFactoryMock = EasyMock.createStrictMock(LoggingRpcFactory.class);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,18 +18,19 @@

import com.google.cloud.TransportOptions;
import org.easymock.EasyMock;
import org.junit.Rule;
import org.junit.Assert;
import org.junit.Test;
import org.junit.rules.ExpectedException;

public class LoggingOptionsTest {

@Rule public ExpectedException thrown = ExpectedException.none();

@Test
public void testInvalidTransport() {
thrown.expect(IllegalArgumentException.class);
LoggingOptions.newBuilder()
.setTransportOptions(EasyMock.<TransportOptions>createMock(TransportOptions.class));
try {
LoggingOptions.newBuilder()
.setTransportOptions(EasyMock.<TransportOptions>createMock(TransportOptions.class));
Assert.fail();
} catch (IllegalArgumentException expected) {
Assert.assertNotNull(expected.getMessage());
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,8 @@

import com.google.cloud.logging.Logging.ListOption;
import com.google.cloud.logging.Option.OptionType;
import org.junit.Rule;
import org.junit.Assert;
import org.junit.Test;
import org.junit.rules.ExpectedException;

public class OptionTest {

Expand All @@ -37,8 +36,6 @@ public class OptionTest {
private static final Option OPTION_NOT_EQUALS1 = new Option(ANOTHER_OPTION_TYPE, OTHER_VALUE) {};
private static final Option OPTION_NOT_EQUALS2 = new Option(ANOTHER_OPTION_TYPE, VALUE) {};

@Rule public ExpectedException thrown = ExpectedException.none();

@Test
public void testEquals() {
assertEquals(OPTION, OPTION_EQUALS);
Expand All @@ -58,8 +55,12 @@ public void testConstructor() {
Option option = new Option(OPTION_TYPE, null) {};
assertEquals(OPTION_TYPE, option.getOptionType());
assertNull(option.getValue());
thrown.expect(NullPointerException.class);
new Option(null, VALUE) {};
try {
new Option(null, VALUE) {};
Assert.fail();
} catch (NullPointerException expected) {

}
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,14 @@

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.fail;

import com.google.cloud.logging.SinkInfo.Destination;
import com.google.cloud.logging.SinkInfo.Destination.BucketDestination;
import com.google.cloud.logging.SinkInfo.Destination.DatasetDestination;
import com.google.cloud.logging.SinkInfo.Destination.TopicDestination;
import com.google.cloud.logging.SinkInfo.VersionFormat;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.ExpectedException;

public class SinkInfoTest {

Expand Down Expand Up @@ -54,8 +53,6 @@ public class SinkInfoTest {
.setVersionFormat(VERSION)
.build();

@Rule public ExpectedException thrown = ExpectedException.none();

@Test
public void testOfBucketDestination() {
assertEquals(Destination.Type.BUCKET, BUCKET_DESTINATION.getType());
Expand Down Expand Up @@ -98,9 +95,12 @@ public void testToAndFromPbDestination() {
assertEquals("project", topicDestination.getProject());
assertEquals("topic", topicDestination.getTopic());
compareTopicDestination(TOPIC_DESTINATION, topicDestination);
thrown.expect(IllegalArgumentException.class);
thrown.expectMessage("wrongDestination is not a valid sink destination");
Destination.fromPb("wrongDestination");
try {
Destination.fromPb("wrongDestination");
fail();
} catch (IllegalArgumentException expected) {
assertEquals("wrongDestination is not a valid sink destination", expected.getMessage());
}
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;

import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableMap;
Expand All @@ -30,9 +31,7 @@
import java.util.List;
import java.util.Map;
import org.junit.BeforeClass;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.ExpectedException;

public class StructsTest {

Expand Down Expand Up @@ -75,8 +74,6 @@ public class StructsTest {
private static final Struct STRUCT = Struct.newBuilder().putAllFields(VALUE_MAP).build();
private static final Map<String, Object> EMPTY_MAP = Collections.emptyMap();

@Rule public ExpectedException thrown = ExpectedException.none();

@BeforeClass
public static void beforeClass() {
INNER_MAP.put("null", null);
Expand Down Expand Up @@ -117,15 +114,23 @@ public void testAsMap() {
@Test
public void testAsMapPut() {
Map<String, Object> map = Structs.asMap(STRUCT);
thrown.expect(UnsupportedOperationException.class);
map.put("key", "value");
try {
map.put("key", "value");
fail();
} catch (UnsupportedOperationException expected) {

}
}

@Test
public void testAsMapRemove() {
Map<String, Object> map = Structs.asMap(STRUCT);
thrown.expect(UnsupportedOperationException.class);
map.remove("null");
try {
map.remove("null");
fail();
} catch (UnsupportedOperationException expected) {

}
}

@Test
Expand All @@ -137,8 +142,11 @@ public void testAsMapEmpty() {

@Test
public void testAsMapNull() {
thrown.expect(NullPointerException.class);
Structs.asMap(null);
try {
Structs.asMap(null);
fail();
} catch (NullPointerException expected) {
}
}

@Test
Expand All @@ -161,8 +169,11 @@ public void testNewStructEmpty() {

@Test
public void testNewStructNull() {
thrown.expect(NullPointerException.class);
Structs.newStruct(null);
try {
Structs.newStruct(null);
fail();
} catch (NullPointerException expected) {
}
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ public void listLogEntries(
ListLogEntriesRequest request, StreamObserver<ListLogEntriesResponse> responseObserver) {
List<LogEntry> entries = new ArrayList<>();

for (ByteString proj : request.getProjectIdsList().asByteStringList()) {
for (ByteString proj : request.getResourceNamesList().asByteStringList()) {
String prefix = "projects/" + proj.toStringUtf8() + "/";
for (Map.Entry<String, List<LogEntry>> entry : logs.entrySet()) {
if (entry.getKey().startsWith(prefix)) {
Expand Down