• 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.billing.v1;
18 
19 import com.google.api.core.BetaApi;
20 import com.google.cloud.billing.v1.CloudCatalogGrpc.CloudCatalogImplBase;
21 import com.google.protobuf.AbstractMessage;
22 import io.grpc.stub.StreamObserver;
23 import java.util.ArrayList;
24 import java.util.LinkedList;
25 import java.util.List;
26 import java.util.Queue;
27 import javax.annotation.Generated;
28 
29 @BetaApi
30 @Generated("by gapic-generator-java")
31 public class MockCloudCatalogImpl extends CloudCatalogImplBase {
32   private List<AbstractMessage> requests;
33   private Queue<Object> responses;
34 
MockCloudCatalogImpl()35   public MockCloudCatalogImpl() {
36     requests = new ArrayList<>();
37     responses = new LinkedList<>();
38   }
39 
getRequests()40   public List<AbstractMessage> getRequests() {
41     return requests;
42   }
43 
addResponse(AbstractMessage response)44   public void addResponse(AbstractMessage response) {
45     responses.add(response);
46   }
47 
setResponses(List<AbstractMessage> responses)48   public void setResponses(List<AbstractMessage> responses) {
49     this.responses = new LinkedList<Object>(responses);
50   }
51 
addException(Exception exception)52   public void addException(Exception exception) {
53     responses.add(exception);
54   }
55 
reset()56   public void reset() {
57     requests = new ArrayList<>();
58     responses = new LinkedList<>();
59   }
60 
61   @Override
listServices( ListServicesRequest request, StreamObserver<ListServicesResponse> responseObserver)62   public void listServices(
63       ListServicesRequest request, StreamObserver<ListServicesResponse> responseObserver) {
64     Object response = responses.poll();
65     if (response instanceof ListServicesResponse) {
66       requests.add(request);
67       responseObserver.onNext(((ListServicesResponse) response));
68       responseObserver.onCompleted();
69     } else if (response instanceof Exception) {
70       responseObserver.onError(((Exception) response));
71     } else {
72       responseObserver.onError(
73           new IllegalArgumentException(
74               String.format(
75                   "Unrecognized response type %s for method ListServices, expected %s or %s",
76                   response == null ? "null" : response.getClass().getName(),
77                   ListServicesResponse.class.getName(),
78                   Exception.class.getName())));
79     }
80   }
81 
82   @Override
listSkus(ListSkusRequest request, StreamObserver<ListSkusResponse> responseObserver)83   public void listSkus(ListSkusRequest request, StreamObserver<ListSkusResponse> responseObserver) {
84     Object response = responses.poll();
85     if (response instanceof ListSkusResponse) {
86       requests.add(request);
87       responseObserver.onNext(((ListSkusResponse) response));
88       responseObserver.onCompleted();
89     } else if (response instanceof Exception) {
90       responseObserver.onError(((Exception) response));
91     } else {
92       responseObserver.onError(
93           new IllegalArgumentException(
94               String.format(
95                   "Unrecognized response type %s for method ListSkus, expected %s or %s",
96                   response == null ? "null" : response.getClass().getName(),
97                   ListSkusResponse.class.getName(),
98                   Exception.class.getName())));
99     }
100   }
101 }
102