Skip to content

Commit 67ce459

Browse files
Praful Makanichingor13
authored andcommitted
chore: remove deprecated method (#74)
* chore: remove deprecated method * chore: modified test failed
1 parent 571cee6 commit 67ce459

File tree

8 files changed

+53
-47
lines changed

8 files changed

+53
-47
lines changed

google-cloud-logging/src/test/java/com/google/cloud/logging/BaseSystemTest.java

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
import static org.junit.Assert.assertNotNull;
2323
import static org.junit.Assert.assertNull;
2424
import static org.junit.Assert.assertTrue;
25+
import static org.junit.Assert.fail;
2526

2627
import com.google.api.gax.paging.Page;
2728
import com.google.cloud.MonitoredResource;
@@ -44,7 +45,6 @@
4445
import java.util.logging.Logger;
4546
import org.junit.Rule;
4647
import org.junit.Test;
47-
import org.junit.rules.ExpectedException;
4848
import org.junit.rules.Timeout;
4949

5050
/**
@@ -53,8 +53,6 @@
5353
*/
5454
public abstract class BaseSystemTest {
5555

56-
@Rule public ExpectedException thrown = ExpectedException.none();
57-
5856
@Rule public Timeout globalTimeout = Timeout.seconds(300);
5957

6058
/**
@@ -114,9 +112,12 @@ public void testUpdateNonExistingSink() {
114112
.setVersionFormat(SinkInfo.VersionFormat.V2)
115113
.build();
116114
assertNull(logging().getSink(name));
117-
thrown.expect(LoggingException.class);
118-
thrown.expectMessage("NOT_FOUND");
119-
logging().update(sinkInfo);
115+
try {
116+
logging().update(sinkInfo);
117+
fail();
118+
} catch (LoggingException expected) {
119+
assertNotNull(expected.getMessage());
120+
}
120121
}
121122

122123
@Test

google-cloud-logging/src/test/java/com/google/cloud/logging/HttpRequestTest.java

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,7 @@
2222
import static org.junit.Assert.assertTrue;
2323

2424
import com.google.cloud.logging.HttpRequest.RequestMethod;
25-
import org.junit.Rule;
2625
import org.junit.Test;
27-
import org.junit.rules.ExpectedException;
2826
import org.threeten.bp.Duration;
2927

3028
public class HttpRequestTest {
@@ -61,8 +59,6 @@ public class HttpRequestTest {
6159
.setLatency(Duration.ofSeconds(123, 456))
6260
.build();
6361

64-
@Rule public ExpectedException thrown = ExpectedException.none();
65-
6662
@Test
6763
public void testBuilder() {
6864
assertEquals(REQUEST_METHOD, HTTP_REQUEST.getRequestMethod());

google-cloud-logging/src/test/java/com/google/cloud/logging/LoggingImplTest.java

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -75,9 +75,7 @@
7575
import org.easymock.EasyMock;
7676
import org.junit.After;
7777
import org.junit.Before;
78-
import org.junit.Rule;
7978
import org.junit.Test;
80-
import org.junit.rules.ExpectedException;
8179

8280
public class LoggingImplTest {
8381

@@ -143,8 +141,6 @@ public com.google.api.MonitoredResourceDescriptor apply(
143141
private LoggingRpc loggingRpcMock;
144142
private Logging logging;
145143

146-
@Rule public ExpectedException thrown = ExpectedException.none();
147-
148144
@Before
149145
public void setUp() {
150146
rpcFactoryMock = EasyMock.createStrictMock(LoggingRpcFactory.class);

google-cloud-logging/src/test/java/com/google/cloud/logging/LoggingOptionsTest.java

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -18,18 +18,19 @@
1818

1919
import com.google.cloud.TransportOptions;
2020
import org.easymock.EasyMock;
21-
import org.junit.Rule;
21+
import org.junit.Assert;
2222
import org.junit.Test;
23-
import org.junit.rules.ExpectedException;
2423

2524
public class LoggingOptionsTest {
2625

27-
@Rule public ExpectedException thrown = ExpectedException.none();
28-
2926
@Test
3027
public void testInvalidTransport() {
31-
thrown.expect(IllegalArgumentException.class);
32-
LoggingOptions.newBuilder()
33-
.setTransportOptions(EasyMock.<TransportOptions>createMock(TransportOptions.class));
28+
try {
29+
LoggingOptions.newBuilder()
30+
.setTransportOptions(EasyMock.<TransportOptions>createMock(TransportOptions.class));
31+
Assert.fail();
32+
} catch (IllegalArgumentException expected) {
33+
Assert.assertNotNull(expected.getMessage());
34+
}
3435
}
3536
}

google-cloud-logging/src/test/java/com/google/cloud/logging/OptionTest.java

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,8 @@
2222

2323
import com.google.cloud.logging.Logging.ListOption;
2424
import com.google.cloud.logging.Option.OptionType;
25-
import org.junit.Rule;
25+
import org.junit.Assert;
2626
import org.junit.Test;
27-
import org.junit.rules.ExpectedException;
2827

2928
public class OptionTest {
3029

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

40-
@Rule public ExpectedException thrown = ExpectedException.none();
41-
4239
@Test
4340
public void testEquals() {
4441
assertEquals(OPTION, OPTION_EQUALS);
@@ -58,8 +55,12 @@ public void testConstructor() {
5855
Option option = new Option(OPTION_TYPE, null) {};
5956
assertEquals(OPTION_TYPE, option.getOptionType());
6057
assertNull(option.getValue());
61-
thrown.expect(NullPointerException.class);
62-
new Option(null, VALUE) {};
58+
try {
59+
new Option(null, VALUE) {};
60+
Assert.fail();
61+
} catch (NullPointerException expected) {
62+
63+
}
6364
}
6465

6566
@Test

google-cloud-logging/src/test/java/com/google/cloud/logging/SinkInfoTest.java

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -18,15 +18,14 @@
1818

1919
import static org.junit.Assert.assertEquals;
2020
import static org.junit.Assert.assertNull;
21+
import static org.junit.Assert.fail;
2122

2223
import com.google.cloud.logging.SinkInfo.Destination;
2324
import com.google.cloud.logging.SinkInfo.Destination.BucketDestination;
2425
import com.google.cloud.logging.SinkInfo.Destination.DatasetDestination;
2526
import com.google.cloud.logging.SinkInfo.Destination.TopicDestination;
2627
import com.google.cloud.logging.SinkInfo.VersionFormat;
27-
import org.junit.Rule;
2828
import org.junit.Test;
29-
import org.junit.rules.ExpectedException;
3029

3130
public class SinkInfoTest {
3231

@@ -54,8 +53,6 @@ public class SinkInfoTest {
5453
.setVersionFormat(VERSION)
5554
.build();
5655

57-
@Rule public ExpectedException thrown = ExpectedException.none();
58-
5956
@Test
6057
public void testOfBucketDestination() {
6158
assertEquals(Destination.Type.BUCKET, BUCKET_DESTINATION.getType());
@@ -98,9 +95,12 @@ public void testToAndFromPbDestination() {
9895
assertEquals("project", topicDestination.getProject());
9996
assertEquals("topic", topicDestination.getTopic());
10097
compareTopicDestination(TOPIC_DESTINATION, topicDestination);
101-
thrown.expect(IllegalArgumentException.class);
102-
thrown.expectMessage("wrongDestination is not a valid sink destination");
103-
Destination.fromPb("wrongDestination");
98+
try {
99+
Destination.fromPb("wrongDestination");
100+
fail();
101+
} catch (IllegalArgumentException expected) {
102+
assertEquals("wrongDestination is not a valid sink destination", expected.getMessage());
103+
}
104104
}
105105

106106
@Test

google-cloud-logging/src/test/java/com/google/cloud/logging/StructsTest.java

Lines changed: 23 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818

1919
import static org.junit.Assert.assertEquals;
2020
import static org.junit.Assert.assertTrue;
21+
import static org.junit.Assert.fail;
2122

2223
import com.google.common.collect.ImmutableList;
2324
import com.google.common.collect.ImmutableMap;
@@ -30,9 +31,7 @@
3031
import java.util.List;
3132
import java.util.Map;
3233
import org.junit.BeforeClass;
33-
import org.junit.Rule;
3434
import org.junit.Test;
35-
import org.junit.rules.ExpectedException;
3635

3736
public class StructsTest {
3837

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

78-
@Rule public ExpectedException thrown = ExpectedException.none();
79-
8077
@BeforeClass
8178
public static void beforeClass() {
8279
INNER_MAP.put("null", null);
@@ -117,15 +114,23 @@ public void testAsMap() {
117114
@Test
118115
public void testAsMapPut() {
119116
Map<String, Object> map = Structs.asMap(STRUCT);
120-
thrown.expect(UnsupportedOperationException.class);
121-
map.put("key", "value");
117+
try {
118+
map.put("key", "value");
119+
fail();
120+
} catch (UnsupportedOperationException expected) {
121+
122+
}
122123
}
123124

124125
@Test
125126
public void testAsMapRemove() {
126127
Map<String, Object> map = Structs.asMap(STRUCT);
127-
thrown.expect(UnsupportedOperationException.class);
128-
map.remove("null");
128+
try {
129+
map.remove("null");
130+
fail();
131+
} catch (UnsupportedOperationException expected) {
132+
133+
}
129134
}
130135

131136
@Test
@@ -137,8 +142,11 @@ public void testAsMapEmpty() {
137142

138143
@Test
139144
public void testAsMapNull() {
140-
thrown.expect(NullPointerException.class);
141-
Structs.asMap(null);
145+
try {
146+
Structs.asMap(null);
147+
fail();
148+
} catch (NullPointerException expected) {
149+
}
142150
}
143151

144152
@Test
@@ -161,8 +169,11 @@ public void testNewStructEmpty() {
161169

162170
@Test
163171
public void testNewStructNull() {
164-
thrown.expect(NullPointerException.class);
165-
Structs.newStruct(null);
172+
try {
173+
Structs.newStruct(null);
174+
fail();
175+
} catch (NullPointerException expected) {
176+
}
166177
}
167178

168179
@Test

google-cloud-logging/src/test/java/com/google/cloud/logging/v2/testing/LocalLoggingImpl.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ public void listLogEntries(
6363
ListLogEntriesRequest request, StreamObserver<ListLogEntriesResponse> responseObserver) {
6464
List<LogEntry> entries = new ArrayList<>();
6565

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

0 commit comments

Comments
 (0)