1313import java .util .NoSuchElementException ;
1414import java .util .ServiceLoader ;
1515import java .util .concurrent .CompletableFuture ;
16- import java .util .function .BiFunction ;
1716import java .util .function .Function ;
1817import java .util .stream .Collectors ;
1918import software .amazon .smithy .java .client .core .ClientConfig ;
@@ -64,7 +63,7 @@ public final class MockPlugin implements ClientPlugin {
6463 .map (ServiceLoader .Provider ::get )
6564 .collect (Collectors .toMap (ServerProtocolProvider ::getProtocolId , Function .identity ()));
6665
67- private final List <BiFunction < Context , SerializableStruct , MockedResult >> matchers = new ArrayList <>();
66+ private final List <Function < MatcherRequest , MockedResult >> matchers = new ArrayList <>();
6867 private final List <MockedRequest > requests = Collections .synchronizedList (new ArrayList <>());
6968 private final Service mockService ;
7069
@@ -109,7 +108,7 @@ public void clearRequests() {
109108 * Creates a MockPlugin.
110109 */
111110 public static final class Builder {
112- private final List <BiFunction < Context , SerializableStruct , MockedResult >> matchers = new ArrayList <>();
111+ private final List <Function < MatcherRequest , MockedResult >> matchers = new ArrayList <>();
113112
114113 private Builder () {}
115114
@@ -128,10 +127,10 @@ public MockPlugin build() {
128127 * <p>If null is returned, then subsequent matchers will attempt to match and intercept the request. If no
129128 * matcher intercepts the request, {@link NoSuchElementException} is thrown.
130129 *
131- * @param matcher Matcher that receives the context and input shape, and returns a result or null.
130+ * @param matcher Matcher that returns a result or null based on the request .
132131 * @return the builder.
133132 */
134- public Builder addMatcher (BiFunction < Context , SerializableStruct , MockedResult > matcher ) {
133+ public Builder addMatcher (Function < MatcherRequest , MockedResult > matcher ) {
135134 matchers .add (matcher );
136135 return this ;
137136 }
@@ -147,7 +146,7 @@ public Builder addMatcher(BiFunction<Context, SerializableStruct, MockedResult>
147146 * @return the builder.
148147 */
149148 public Builder addQueue (MockQueue resultQueue ) {
150- matchers .add (( context , input ) -> resultQueue .poll ());
149+ matchers .add (request -> resultQueue .poll ());
151150 return this ;
152151 }
153152 }
@@ -225,8 +224,13 @@ public CompletableFuture<HttpResponse> send(Context context, HttpRequest request
225224 requests .add (currentRequest .request ());
226225
227226 MockedResult result = null ;
227+ var matcherRequest = new MatcherRequest (
228+ context ,
229+ currentRequest .operation ().getApiOperation (),
230+ currentRequest .request ().input ()
231+ );
228232 for (var matcher : matchers ) {
229- result = matcher .apply (context , currentRequest . request (). input () );
233+ result = matcher .apply (matcherRequest );
230234 if (result != null ) {
231235 break ;
232236 }
0 commit comments