Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(3)

Side by Side Diff: third_party/protobuf/java/compatibility_tests/v2.5.0/tests/src/main/java/com/google/protobuf/test/ServiceTest.java

Issue 2495533002: third_party/protobuf: Update to HEAD (83d681ee2c) (Closed)
Patch Set: Make chrome settings proto generated file a component Created 4 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Protocol Buffers - Google's data interchange format 1 // Protocol Buffers - Google's data interchange format
2 // Copyright 2008 Google Inc. All rights reserved. 2 // Copyright 2008 Google Inc. All rights reserved.
3 // https://developers.google.com/protocol-buffers/ 3 // http://code.google.com/p/protobuf/
4 // 4 //
5 // Redistribution and use in source and binary forms, with or without 5 // Redistribution and use in source and binary forms, with or without
6 // modification, are permitted provided that the following conditions are 6 // modification, are permitted provided that the following conditions are
7 // met: 7 // met:
8 // 8 //
9 // * Redistributions of source code must retain the above copyright 9 // * Redistributions of source code must retain the above copyright
10 // notice, this list of conditions and the following disclaimer. 10 // notice, this list of conditions and the following disclaimer.
11 // * Redistributions in binary form must reproduce the above 11 // * Redistributions in binary form must reproduce the above
12 // copyright notice, this list of conditions and the following disclaimer 12 // copyright notice, this list of conditions and the following disclaimer
13 // in the documentation and/or other materials provided with the 13 // in the documentation and/or other materials provided with the
14 // distribution. 14 // distribution.
15 // * Neither the name of Google Inc. nor the names of its 15 // * Neither the name of Google Inc. nor the names of its
16 // contributors may be used to endorse or promote products derived from 16 // contributors may be used to endorse or promote products derived from
17 // this software without specific prior written permission. 17 // this software without specific prior written permission.
18 // 18 //
19 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 19 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
20 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 20 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
21 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 21 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
22 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 22 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
23 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 23 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
24 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 24 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
25 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 25 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
26 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 26 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
27 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 27 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
28 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 28 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
29 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 29 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30 30
31 package com.google.protobuf; 31 package com.google.protobuf.test;
32 import com.google.protobuf.*;
32 33
33 import com.google.protobuf.Descriptors.FileDescriptor; 34 import com.google.protobuf.Descriptors.FileDescriptor;
34 import com.google.protobuf.Descriptors.MethodDescriptor; 35 import com.google.protobuf.Descriptors.MethodDescriptor;
35 import google.protobuf.no_generic_services_test.UnittestNoGenericServices; 36 import google.protobuf.no_generic_services_test.UnittestNoGenericServices;
36 import protobuf_unittest.MessageWithNoOuter; 37 import protobuf_unittest.MessageWithNoOuter;
37 import protobuf_unittest.ServiceWithNoOuter; 38 import protobuf_unittest.ServiceWithNoOuter;
39 import protobuf_unittest.UnittestProto.TestAllTypes;
40 import protobuf_unittest.UnittestProto.TestService;
41 import protobuf_unittest.UnittestProto.FooRequest;
42 import protobuf_unittest.UnittestProto.FooResponse;
38 import protobuf_unittest.UnittestProto.BarRequest; 43 import protobuf_unittest.UnittestProto.BarRequest;
39 import protobuf_unittest.UnittestProto.BarResponse; 44 import protobuf_unittest.UnittestProto.BarResponse;
40 import protobuf_unittest.UnittestProto.FooRequest;
41 import protobuf_unittest.UnittestProto.FooResponse;
42 import protobuf_unittest.UnittestProto.TestAllTypes;
43 import protobuf_unittest.UnittestProto.TestService;
44
45 import junit.framework.TestCase;
46 45
47 import org.easymock.classextension.EasyMock; 46 import org.easymock.classextension.EasyMock;
47 import org.easymock.classextension.IMocksControl;
48 import org.easymock.IArgumentMatcher; 48 import org.easymock.IArgumentMatcher;
49 import org.easymock.classextension.IMocksControl;
50 49
51 import java.util.HashSet; 50 import java.util.HashSet;
52 import java.util.Set; 51 import java.util.Set;
53 52
53 import junit.framework.TestCase;
54
54 /** 55 /**
55 * Tests services and stubs. 56 * Tests services and stubs.
56 * 57 *
57 * @author kenton@google.com Kenton Varda 58 * @author kenton@google.com Kenton Varda
58 */ 59 */
59 public class ServiceTest extends TestCase { 60 public class ServiceTest extends TestCase {
60 private IMocksControl control; 61 private IMocksControl control;
61 private RpcController mockController; 62 private RpcController mockController;
62 63
63 private final Descriptors.MethodDescriptor fooDescriptor = 64 private final Descriptors.MethodDescriptor fooDescriptor =
(...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after
168 169
169 public void testNewReflectiveService() { 170 public void testNewReflectiveService() {
170 ServiceWithNoOuter.Interface impl = 171 ServiceWithNoOuter.Interface impl =
171 control.createMock(ServiceWithNoOuter.Interface.class); 172 control.createMock(ServiceWithNoOuter.Interface.class);
172 RpcController controller = control.createMock(RpcController.class); 173 RpcController controller = control.createMock(RpcController.class);
173 Service service = ServiceWithNoOuter.newReflectiveService(impl); 174 Service service = ServiceWithNoOuter.newReflectiveService(impl);
174 175
175 MethodDescriptor fooMethod = 176 MethodDescriptor fooMethod =
176 ServiceWithNoOuter.getDescriptor().findMethodByName("Foo"); 177 ServiceWithNoOuter.getDescriptor().findMethodByName("Foo");
177 MessageWithNoOuter request = MessageWithNoOuter.getDefaultInstance(); 178 MessageWithNoOuter request = MessageWithNoOuter.getDefaultInstance();
178 RpcCallback<Message> callback = 179 RpcCallback<Message> callback = new RpcCallback<Message>() {
179 new RpcCallback<Message>() { 180 public void run(Message parameter) {
180 @Override 181 // No reason this should be run.
181 public void run(Message parameter) { 182 fail();
182 // No reason this should be run. 183 }
183 fail(); 184 };
184 }
185 };
186 RpcCallback<TestAllTypes> specializedCallback = 185 RpcCallback<TestAllTypes> specializedCallback =
187 RpcUtil.specializeCallback(callback); 186 RpcUtil.specializeCallback(callback);
188 187
189 impl.foo(EasyMock.same(controller), EasyMock.same(request), 188 impl.foo(EasyMock.same(controller), EasyMock.same(request),
190 EasyMock.same(specializedCallback)); 189 EasyMock.same(specializedCallback));
191 EasyMock.expectLastCall(); 190 EasyMock.expectLastCall();
192 191
193 control.replay(); 192 control.replay();
194 193
195 service.callMethod(fooMethod, controller, request, callback); 194 service.callMethod(fooMethod, controller, request, callback);
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after
285 } 284 }
286 285
287 /** The parameter to wrapsCallback() must be a MockCallback. */ 286 /** The parameter to wrapsCallback() must be a MockCallback. */
288 private static class MockCallback<Type extends Message> 287 private static class MockCallback<Type extends Message>
289 implements RpcCallback<Type> { 288 implements RpcCallback<Type> {
290 private boolean called = false; 289 private boolean called = false;
291 290
292 public boolean isCalled() { return called; } 291 public boolean isCalled() { return called; }
293 292
294 public void reset() { called = false; } 293 public void reset() { called = false; }
295 @Override 294 public void run(Type message) { called = true; }
296 public void run(Type message) {
297 called = true; }
298 } 295 }
299 296
300 /** Implementation of the wrapsCallback() argument matcher. */ 297 /** Implementation of the wrapsCallback() argument matcher. */
301 private static class WrapsCallback implements IArgumentMatcher { 298 private static class WrapsCallback implements IArgumentMatcher {
302 private MockCallback<?> callback; 299 private MockCallback<?> callback;
303 300
304 public WrapsCallback(MockCallback<?> callback) { 301 public WrapsCallback(MockCallback<?> callback) {
305 this.callback = callback; 302 this.callback = callback;
306 } 303 }
307 304
308 @Override
309 @SuppressWarnings("unchecked") 305 @SuppressWarnings("unchecked")
310 public boolean matches(Object actual) { 306 public boolean matches(Object actual) {
311 if (!(actual instanceof RpcCallback)) { 307 if (!(actual instanceof RpcCallback)) {
312 return false; 308 return false;
313 } 309 }
314 RpcCallback actualCallback = (RpcCallback)actual; 310 RpcCallback actualCallback = (RpcCallback)actual;
315 311
316 callback.reset(); 312 callback.reset();
317 actualCallback.run(null); 313 actualCallback.run(null);
318 return callback.isCalled(); 314 return callback.isCalled();
319 } 315 }
320 316
321 @Override
322 public void appendTo(StringBuffer buffer) { 317 public void appendTo(StringBuffer buffer) {
323 buffer.append("wrapsCallback(mockCallback)"); 318 buffer.append("wrapsCallback(mockCallback)");
324 } 319 }
325 } 320 }
326 } 321 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698