• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright 2022 Google LLC
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  *      https://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 com.google.cloud.speech.v1p1beta1;
18 
19 import com.google.api.core.BetaApi;
20 import com.google.cloud.speech.v1p1beta1.AdaptationGrpc.AdaptationImplBase;
21 import com.google.protobuf.AbstractMessage;
22 import com.google.protobuf.Empty;
23 import io.grpc.stub.StreamObserver;
24 import java.util.ArrayList;
25 import java.util.LinkedList;
26 import java.util.List;
27 import java.util.Queue;
28 import javax.annotation.Generated;
29 
30 @BetaApi
31 @Generated("by gapic-generator-java")
32 public class MockAdaptationImpl extends AdaptationImplBase {
33   private List<AbstractMessage> requests;
34   private Queue<Object> responses;
35 
MockAdaptationImpl()36   public MockAdaptationImpl() {
37     requests = new ArrayList<>();
38     responses = new LinkedList<>();
39   }
40 
getRequests()41   public List<AbstractMessage> getRequests() {
42     return requests;
43   }
44 
addResponse(AbstractMessage response)45   public void addResponse(AbstractMessage response) {
46     responses.add(response);
47   }
48 
setResponses(List<AbstractMessage> responses)49   public void setResponses(List<AbstractMessage> responses) {
50     this.responses = new LinkedList<Object>(responses);
51   }
52 
addException(Exception exception)53   public void addException(Exception exception) {
54     responses.add(exception);
55   }
56 
reset()57   public void reset() {
58     requests = new ArrayList<>();
59     responses = new LinkedList<>();
60   }
61 
62   @Override
createPhraseSet( CreatePhraseSetRequest request, StreamObserver<PhraseSet> responseObserver)63   public void createPhraseSet(
64       CreatePhraseSetRequest request, StreamObserver<PhraseSet> responseObserver) {
65     Object response = responses.poll();
66     if (response instanceof PhraseSet) {
67       requests.add(request);
68       responseObserver.onNext(((PhraseSet) response));
69       responseObserver.onCompleted();
70     } else if (response instanceof Exception) {
71       responseObserver.onError(((Exception) response));
72     } else {
73       responseObserver.onError(
74           new IllegalArgumentException(
75               String.format(
76                   "Unrecognized response type %s for method CreatePhraseSet, expected %s or %s",
77                   response == null ? "null" : response.getClass().getName(),
78                   PhraseSet.class.getName(),
79                   Exception.class.getName())));
80     }
81   }
82 
83   @Override
getPhraseSet( GetPhraseSetRequest request, StreamObserver<PhraseSet> responseObserver)84   public void getPhraseSet(
85       GetPhraseSetRequest request, StreamObserver<PhraseSet> responseObserver) {
86     Object response = responses.poll();
87     if (response instanceof PhraseSet) {
88       requests.add(request);
89       responseObserver.onNext(((PhraseSet) response));
90       responseObserver.onCompleted();
91     } else if (response instanceof Exception) {
92       responseObserver.onError(((Exception) response));
93     } else {
94       responseObserver.onError(
95           new IllegalArgumentException(
96               String.format(
97                   "Unrecognized response type %s for method GetPhraseSet, expected %s or %s",
98                   response == null ? "null" : response.getClass().getName(),
99                   PhraseSet.class.getName(),
100                   Exception.class.getName())));
101     }
102   }
103 
104   @Override
listPhraseSet( ListPhraseSetRequest request, StreamObserver<ListPhraseSetResponse> responseObserver)105   public void listPhraseSet(
106       ListPhraseSetRequest request, StreamObserver<ListPhraseSetResponse> responseObserver) {
107     Object response = responses.poll();
108     if (response instanceof ListPhraseSetResponse) {
109       requests.add(request);
110       responseObserver.onNext(((ListPhraseSetResponse) response));
111       responseObserver.onCompleted();
112     } else if (response instanceof Exception) {
113       responseObserver.onError(((Exception) response));
114     } else {
115       responseObserver.onError(
116           new IllegalArgumentException(
117               String.format(
118                   "Unrecognized response type %s for method ListPhraseSet, expected %s or %s",
119                   response == null ? "null" : response.getClass().getName(),
120                   ListPhraseSetResponse.class.getName(),
121                   Exception.class.getName())));
122     }
123   }
124 
125   @Override
updatePhraseSet( UpdatePhraseSetRequest request, StreamObserver<PhraseSet> responseObserver)126   public void updatePhraseSet(
127       UpdatePhraseSetRequest request, StreamObserver<PhraseSet> responseObserver) {
128     Object response = responses.poll();
129     if (response instanceof PhraseSet) {
130       requests.add(request);
131       responseObserver.onNext(((PhraseSet) response));
132       responseObserver.onCompleted();
133     } else if (response instanceof Exception) {
134       responseObserver.onError(((Exception) response));
135     } else {
136       responseObserver.onError(
137           new IllegalArgumentException(
138               String.format(
139                   "Unrecognized response type %s for method UpdatePhraseSet, expected %s or %s",
140                   response == null ? "null" : response.getClass().getName(),
141                   PhraseSet.class.getName(),
142                   Exception.class.getName())));
143     }
144   }
145 
146   @Override
deletePhraseSet( DeletePhraseSetRequest request, StreamObserver<Empty> responseObserver)147   public void deletePhraseSet(
148       DeletePhraseSetRequest request, StreamObserver<Empty> responseObserver) {
149     Object response = responses.poll();
150     if (response instanceof Empty) {
151       requests.add(request);
152       responseObserver.onNext(((Empty) response));
153       responseObserver.onCompleted();
154     } else if (response instanceof Exception) {
155       responseObserver.onError(((Exception) response));
156     } else {
157       responseObserver.onError(
158           new IllegalArgumentException(
159               String.format(
160                   "Unrecognized response type %s for method DeletePhraseSet, expected %s or %s",
161                   response == null ? "null" : response.getClass().getName(),
162                   Empty.class.getName(),
163                   Exception.class.getName())));
164     }
165   }
166 
167   @Override
createCustomClass( CreateCustomClassRequest request, StreamObserver<CustomClass> responseObserver)168   public void createCustomClass(
169       CreateCustomClassRequest request, StreamObserver<CustomClass> responseObserver) {
170     Object response = responses.poll();
171     if (response instanceof CustomClass) {
172       requests.add(request);
173       responseObserver.onNext(((CustomClass) response));
174       responseObserver.onCompleted();
175     } else if (response instanceof Exception) {
176       responseObserver.onError(((Exception) response));
177     } else {
178       responseObserver.onError(
179           new IllegalArgumentException(
180               String.format(
181                   "Unrecognized response type %s for method CreateCustomClass, expected %s or %s",
182                   response == null ? "null" : response.getClass().getName(),
183                   CustomClass.class.getName(),
184                   Exception.class.getName())));
185     }
186   }
187 
188   @Override
getCustomClass( GetCustomClassRequest request, StreamObserver<CustomClass> responseObserver)189   public void getCustomClass(
190       GetCustomClassRequest request, StreamObserver<CustomClass> responseObserver) {
191     Object response = responses.poll();
192     if (response instanceof CustomClass) {
193       requests.add(request);
194       responseObserver.onNext(((CustomClass) response));
195       responseObserver.onCompleted();
196     } else if (response instanceof Exception) {
197       responseObserver.onError(((Exception) response));
198     } else {
199       responseObserver.onError(
200           new IllegalArgumentException(
201               String.format(
202                   "Unrecognized response type %s for method GetCustomClass, expected %s or %s",
203                   response == null ? "null" : response.getClass().getName(),
204                   CustomClass.class.getName(),
205                   Exception.class.getName())));
206     }
207   }
208 
209   @Override
listCustomClasses( ListCustomClassesRequest request, StreamObserver<ListCustomClassesResponse> responseObserver)210   public void listCustomClasses(
211       ListCustomClassesRequest request,
212       StreamObserver<ListCustomClassesResponse> responseObserver) {
213     Object response = responses.poll();
214     if (response instanceof ListCustomClassesResponse) {
215       requests.add(request);
216       responseObserver.onNext(((ListCustomClassesResponse) response));
217       responseObserver.onCompleted();
218     } else if (response instanceof Exception) {
219       responseObserver.onError(((Exception) response));
220     } else {
221       responseObserver.onError(
222           new IllegalArgumentException(
223               String.format(
224                   "Unrecognized response type %s for method ListCustomClasses, expected %s or %s",
225                   response == null ? "null" : response.getClass().getName(),
226                   ListCustomClassesResponse.class.getName(),
227                   Exception.class.getName())));
228     }
229   }
230 
231   @Override
updateCustomClass( UpdateCustomClassRequest request, StreamObserver<CustomClass> responseObserver)232   public void updateCustomClass(
233       UpdateCustomClassRequest request, StreamObserver<CustomClass> responseObserver) {
234     Object response = responses.poll();
235     if (response instanceof CustomClass) {
236       requests.add(request);
237       responseObserver.onNext(((CustomClass) response));
238       responseObserver.onCompleted();
239     } else if (response instanceof Exception) {
240       responseObserver.onError(((Exception) response));
241     } else {
242       responseObserver.onError(
243           new IllegalArgumentException(
244               String.format(
245                   "Unrecognized response type %s for method UpdateCustomClass, expected %s or %s",
246                   response == null ? "null" : response.getClass().getName(),
247                   CustomClass.class.getName(),
248                   Exception.class.getName())));
249     }
250   }
251 
252   @Override
deleteCustomClass( DeleteCustomClassRequest request, StreamObserver<Empty> responseObserver)253   public void deleteCustomClass(
254       DeleteCustomClassRequest request, StreamObserver<Empty> responseObserver) {
255     Object response = responses.poll();
256     if (response instanceof Empty) {
257       requests.add(request);
258       responseObserver.onNext(((Empty) response));
259       responseObserver.onCompleted();
260     } else if (response instanceof Exception) {
261       responseObserver.onError(((Exception) response));
262     } else {
263       responseObserver.onError(
264           new IllegalArgumentException(
265               String.format(
266                   "Unrecognized response type %s for method DeleteCustomClass, expected %s or %s",
267                   response == null ? "null" : response.getClass().getName(),
268                   Empty.class.getName(),
269                   Exception.class.getName())));
270     }
271   }
272 }
273