Skip to content

Commit 417cd93

Browse files
committed
CR
1 parent 4d58b5e commit 417cd93

File tree

2 files changed

+37
-2
lines changed

2 files changed

+37
-2
lines changed

stub/src/main/java/io/grpc/stub/StreamObservers.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,14 +25,15 @@
2525
* {@link CallStreamObserver}.
2626
*/
2727
public final class StreamObservers {
28+
// Prevent instantiation
29+
private StreamObservers() { }
30+
2831
/**
2932
* Utility method to call {@link StreamObserver#onNext(Object)} and
3033
* {@link StreamObserver#onCompleted()} on the specified responseObserver.
3134
*/
3235
@ExperimentalApi("https://github.com/grpc/grpc-java/issues/10957")
3336
public static <T> void nextAndComplete(StreamObserver<T> responseObserver, T response) {
34-
Preconditions.checkNotNull(response, "response");
35-
3637
responseObserver.onNext(response);
3738
responseObserver.onCompleted();
3839
}
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
/*
2+
* Copyright 2025 The gRPC Authors
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package io.grpc.stub;
18+
19+
import org.junit.Test;
20+
import org.mockito.InOrder;
21+
import org.mockito.Mockito;
22+
23+
public class StreamObserversTest {
24+
25+
@Test
26+
public void nextAndComplete() {
27+
StreamObserver<String> observer = Mockito.mock(StreamObserver.class);
28+
InOrder inOrder = Mockito.inOrder(observer);
29+
StreamObservers.nextAndComplete(observer, "TEST");
30+
inOrder.verify(observer).onNext("TEST");
31+
inOrder.verify(observer).onCompleted();
32+
inOrder.verifyNoMoreInteractions();
33+
}
34+
}

0 commit comments

Comments
 (0)