How to use testArgumentMatching_optionalProtocolType_usingNotNilWildcardMatching method of ArgumentMatchingTests class

Best Mockingbird code snippet using ArgumentMatchingTests.testArgumentMatching_optionalProtocolType_usingNotNilWildcardMatching

Run Mockingbird automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

ArgumentMatchingTests.swift

Source: ArgumentMatchingTests.swift Github

copy
1//
2//  ArgumentMatchingTests.swift
3//  MockingbirdTests
4//
5//  Created by Andrew Chang on 8/21/19.
6//  Copyright © 2019 Bird Rides, Inc. All rights reserved.
7//
8
9import Foundation
10
11import XCTest
12import Mockingbird
13@testable import MockingbirdTestsHost
14
15class ArgumentMatchingTests: XCTestCase {
16  
17  var concreteMock: ArgumentMatchingProtocolMock!
18  var concreteInstance: ArgumentMatchingProtocol { return concreteMock }
19  
20  override func setUp() {
21    concreteMock = mock(ArgumentMatchingProtocol.self)
22  }
23  
24  // MARK: - Non-optional arguments
25  
26  func testArgumentMatching_structType() {
27    given(concreteMock.method(structType: StructType())) ~> true
28    XCTAssertTrue(concreteInstance.method(structType: StructType()))
29    verify(concreteMock.method(structType: StructType())).wasCalled()
30  }
31  
32  func testArgumentMatching_classType() {
33    let classTypeReference = ClassType()
34    given(concreteMock.method(classType: classTypeReference)) ~> true
35    XCTAssertTrue(concreteInstance.method(classType: classTypeReference))
36    verify(concreteMock.method(classType: classTypeReference)).wasCalled()
37  }
38  
39  func testArgumentMatching_enumType() {
40    given(concreteMock.method(enumType: .failure)) ~> true
41    XCTAssertTrue(concreteInstance.method(enumType: .failure))
42    verify(concreteMock.method(enumType: .failure)).wasCalled()
43  }
44  
45  func testArgumentMatching_stringType() {
46    given(concreteMock.method(stringType: "hello-world")) ~> true
47    XCTAssertTrue(concreteInstance.method(stringType: "hello-world"))
48    verify(concreteMock.method(stringType: "hello-world")).wasCalled()
49  }
50  
51  func testArgumentMatching_boolType() {
52    given(concreteMock.method(boolType: false)) ~> true
53    XCTAssertTrue(concreteInstance.method(boolType: false))
54    verify(concreteMock.method(boolType: false)).wasCalled()
55  }
56  
57  func testArgumentMatching_protocolType_classImplementation() {
58    let classTypeReference = ClassType()
59    given(concreteMock.method(protocolType: classTypeReference)) ~> true
60    XCTAssertTrue(concreteInstance.method(protocolType: classTypeReference))
61    verify(concreteMock.method(protocolType: classTypeReference)).wasCalled()
62  }
63  
64  func testArgumentMatching_protocolType_structImplementation() {
65    given(concreteMock.method(protocolType: StructType())) ~> true
66    XCTAssertTrue(concreteInstance.method(protocolType: StructType()))
67    verify(concreteMock.method(protocolType: StructType())).wasCalled()
68  }
69  
70  func testArgumentMatching_protocolType_mixedImplementation() {
71    given(concreteMock.method(protocolType: StructType())) ~> true
72    XCTAssertTrue(concreteInstance.method(protocolType: StructType()))
73    verify(concreteMock.method(protocolType: ClassType())).wasNeverCalled()
74  }
75  
76  func testArgumentMatching_metaType() {
77    given(concreteMock.method(metaType: ClassType.self)) ~> true
78    XCTAssertTrue(concreteInstance.method(metaType: ClassType.self))
79    verify(concreteMock.method(metaType: ClassType.self)).wasCalled()
80  }
81  
82  func testArgumentMatching_anyType() {
83    given(concreteMock.method(anyType: any(of: 1))) ~> true
84    XCTAssertTrue(concreteInstance.method(anyType: 1))
85    verify(concreteMock.method(anyType: any(of: 1))).wasCalled()
86  }
87  
88  func testArgumentMatching_anyTypeStruct() {
89    struct ConcreteAnyType: Equatable {}
90    given(concreteMock.method(anyType: any(ConcreteAnyType.self))) ~> true
91    XCTAssertTrue(concreteInstance.method(anyType: ConcreteAnyType()))
92    verify(concreteMock.method(anyType: any(ConcreteAnyType.self))).wasCalled()
93  }
94  
95  func testArgumentMatching_anyObjectType() {
96    given(concreteMock.method(anyType: any(ClassType.self))) ~> true
97    XCTAssertTrue(concreteInstance.method(anyType: ClassType()))
98    verify(concreteMock.method(anyType: any(ClassType.self))).wasCalled()
99  }
100  
101  // MARK: - Optional arguments + strict matching
102  
103  func testArgumentMatching_optionalStructType_usingStrictMatching() {
104    given(concreteMock.method(optionalStructType: nil)) ~> true
105    XCTAssertTrue(concreteInstance.method(optionalStructType: nil))
106    verify(concreteMock.method(optionalStructType: nil)).wasCalled()
107  }
108  
109  func testArgumentMatching_optionalClassType_usingStrictMatching() {
110    given(concreteMock.method(optionalClassType: nil)) ~> true
111    XCTAssertTrue(concreteInstance.method(optionalClassType: nil))
112    verify(concreteMock.method(optionalClassType: nil)).wasCalled()
113  }
114  
115  func testArgumentMatching_optionalEnumType_usingStrictMatching() {
116    given(concreteMock.method(optionalEnumType: nil)) ~> true
117    XCTAssertTrue(concreteInstance.method(optionalEnumType: nil))
118    verify(concreteMock.method(optionalEnumType: nil)).wasCalled()
119  }
120  
121  func testArgumentMatching_optionalStringType_usingStrictMatching() {
122    given(concreteMock.method(optionalStringType: nil)) ~> true
123    XCTAssertTrue(concreteInstance.method(optionalStringType: nil))
124    verify(concreteMock.method(optionalStringType: nil)).wasCalled()
125  }
126  
127  func testArgumentMatching_optionalBoolType_usingStrictMatching() {
128    given(concreteMock.method(optionalBoolType: nil)) ~> true
129    XCTAssertTrue(concreteInstance.method(optionalBoolType: nil))
130    verify(concreteMock.method(optionalBoolType: nil)).wasCalled()
131  }
132  
133  func testArgumentMatching_optionalProtocolType_usingStrictMatching() {
134    given(concreteMock.method(optionalProtocolType: Optional<ClassType>(nil))) ~> true
135    XCTAssertTrue(concreteInstance.method(optionalProtocolType: Optional<ClassType>(nil)))
136    verify(concreteMock.method(optionalProtocolType: Optional<ClassType>(nil))).wasCalled()
137  }
138  
139  func testArgumentMatching_optionalMetaType_usingStrictMatching() {
140    given(concreteMock.method(optionalMetaType: nil)) ~> true
141    XCTAssertTrue(concreteInstance.method(optionalMetaType: nil))
142    verify(concreteMock.method(optionalMetaType: nil)).wasCalled()
143  }
144  
145  func testArgumentMatching_optionalAnyType_usingStrictMatching() {
146    given(concreteMock.method(optionalAnyType: nil)) ~> true
147    XCTAssertTrue(concreteInstance.method(optionalAnyType: nil))
148    verify(concreteMock.method(optionalAnyType: nil)).wasCalled()
149  }
150  
151  func testArgumentMatching_optionalAnyObjectType_usingStrictMatching() {
152    given(concreteMock.method(optionalAnyObjectType: nil)) ~> true
153    XCTAssertTrue(concreteInstance.method(optionalAnyObjectType: nil))
154    verify(concreteMock.method(optionalAnyObjectType: nil)).wasCalled()
155  }
156  
157  // MARK: - Optional arguments + notNil wildcard matching
158  
159  func testArgumentMatching_optionalStructType_usingNotNilWildcardMatching() {
160    given(concreteMock.method(optionalStructType: notNil())) ~> true
161    XCTAssertTrue(concreteInstance.method(optionalStructType: StructType()))
162    verify(concreteMock.method(optionalStructType: notNil())).wasCalled()
163  }
164  
165  func testArgumentMatching_optionalClassType_usingNotNilWildcardMatching() {
166    given(concreteMock.method(optionalClassType: notNil())) ~> true
167    XCTAssertTrue(concreteInstance.method(optionalClassType: ClassType()))
168    verify(concreteMock.method(optionalClassType: notNil())).wasCalled()
169  }
170  
171  func testArgumentMatching_optionalEnumType_usingNotNilWildcardMatching() {
172    given(concreteMock.method(optionalEnumType: notNil())) ~> true
173    XCTAssertTrue(concreteInstance.method(optionalEnumType: .failure))
174    verify(concreteMock.method(optionalEnumType: notNil())).wasCalled()
175  }
176  
177  func testArgumentMatching_optionalStringType_usingNotNilWildcardMatching() {
178    given(concreteMock.method(optionalStringType: notNil())) ~> true
179    XCTAssertTrue(concreteInstance.method(optionalStringType: "hello-world"))
180    verify(concreteMock.method(optionalStringType: notNil())).wasCalled()
181  }
182  
183  func testArgumentMatching_optionalBoolType_usingNotNilWildcardMatching() {
184    given(concreteMock.method(optionalBoolType: notNil())) ~> true
185    XCTAssertTrue(concreteInstance.method(optionalBoolType: false))
186    verify(concreteMock.method(optionalBoolType: notNil())).wasCalled()
187  }
188  
189  func testArgumentMatching_optionalProtocolType_usingNotNilWildcardMatching() {
190    given(concreteMock.method(optionalProtocolType: notNil(Optional<ClassType>.self))) ~> true
191    XCTAssertTrue(concreteInstance.method(optionalProtocolType: ClassType()))
192    verify(concreteMock.method(optionalProtocolType: notNil(Optional<ClassType>.self))).wasCalled()
193  }
194  
195  func testArgumentMatching_optionalMetaType_usingNotNilWildcardMatching() {
196    given(concreteMock.method(optionalMetaType: notNil())) ~> true
197    XCTAssertTrue(concreteInstance.method(optionalMetaType: ClassType.self))
198    verify(concreteMock.method(optionalMetaType: notNil())).wasCalled()
199  }
200  
201  func testArgumentMatching_optionalAnyType_usingNotNilWildcardMatching() {
202    given(concreteMock.method(optionalAnyType: notNil())) ~> true
203    XCTAssertTrue(concreteInstance.method(optionalAnyType: 1))
204    verify(concreteMock.method(optionalAnyType: notNil())).wasCalled()
205  }
206  
207  func testArgumentMatching_optionalAnyObjectType_usingNotNilWildcardMatching() {
208    given(concreteMock.method(optionalAnyObjectType: notNil())) ~> true
209    XCTAssertTrue(concreteInstance.method(optionalAnyObjectType: ClassType()))
210    verify(concreteMock.method(optionalAnyObjectType: notNil())).wasCalled()
211  }
212  
213  // MARK: - Optional arguments + any wildcard matching
214  
215  func testArgumentMatching_optionalStructType_usingWildcardMatching() {
216    given(concreteMock.method(optionalStructType: any())) ~> true
217    XCTAssertTrue(concreteInstance.method(optionalStructType: nil))
218    verify(concreteMock.method(optionalStructType: any())).wasCalled()
219  }
220  
221  func testArgumentMatching_optionalClassType_usingWildcardMatching() {
222    given(concreteMock.method(optionalClassType: any())) ~> true
223    XCTAssertTrue(concreteInstance.method(optionalClassType: nil))
224    verify(concreteMock.method(optionalClassType: any())).wasCalled()
225  }
226  
227  func testArgumentMatching_optionalEnumType_usingWildcardMatching() {
228    given(concreteMock.method(optionalEnumType: any())) ~> true
229    XCTAssertTrue(concreteInstance.method(optionalEnumType: nil))
230    verify(concreteMock.method(optionalEnumType: any())).wasCalled()
231  }
232  
233  func testArgumentMatching_optionalStringType_usingWildcardMatching() {
234    given(concreteMock.method(optionalStringType: any())) ~> true
235    XCTAssertTrue(concreteInstance.method(optionalStringType: nil))
236    verify(concreteMock.method(optionalStringType: any())).wasCalled()
237  }
238  
239  func testArgumentMatching_optionalBoolType_usingWildcardMatching() {
240    given(concreteMock.method(optionalBoolType: any())) ~> true
241    XCTAssertTrue(concreteInstance.method(optionalBoolType: nil))
242    verify(concreteMock.method(optionalBoolType: any())).wasCalled()
243  }
244  
245  func testArgumentMatching_optionalProtocolType_usingWildcardMatching() {
246    given(concreteMock.method(optionalProtocolType: any(Optional<ClassType>.self))) ~> true
247    XCTAssertTrue(concreteInstance.method(optionalProtocolType: Optional<ClassType>(nil)))
248    verify(concreteMock.method(optionalProtocolType: any(Optional<ClassType>.self))).wasCalled()
249  }
250  
251  func testArgumentMatching_optionalMetaType_usingWildcardMatching() {
252    given(concreteMock.method(optionalMetaType: any())) ~> true
253    XCTAssertTrue(concreteInstance.method(optionalMetaType: nil))
254    verify(concreteMock.method(optionalMetaType: any())).wasCalled()
255  }
256  
257  func testArgumentMatching_optionalAnyType_usingWildcardMatching() {
258    given(concreteMock.method(optionalAnyType: any())) ~> true
259    XCTAssertTrue(concreteInstance.method(optionalAnyType: nil))
260    verify(concreteMock.method(optionalAnyType: any())).wasCalled()
261  }
262  
263  func testArgumentMatching_optionalAnyTypeStruct_usingWildcardMatching() {
264    struct ConcreteAnyType: Equatable {}
265    given(concreteMock.method(optionalAnyType: any(ConcreteAnyType.self))) ~> true
266    XCTAssertTrue(concreteInstance.method(optionalAnyType: ConcreteAnyType()))
267    verify(concreteMock.method(optionalAnyType: any(ConcreteAnyType.self))).wasCalled()
268  }
269  
270  func testArgumentMatching_optionalAnyObjectType_usingWildcardMatching() {
271    given(concreteMock.method(optionalAnyObjectType: any())) ~> true
272    XCTAssertTrue(concreteInstance.method(optionalAnyObjectType: nil))
273    verify(concreteMock.method(optionalAnyObjectType: any())).wasCalled()
274  }
275  
276  // MARK: - Multiple argument matching
277  
278  func testArgumentMatching_structType_multipleValueMatching() {
279    given(concreteMock.method(structType: any(of: StructType(value: 0), StructType(value: 1)))) ~> true
280    XCTAssertTrue(concreteInstance.method(structType: StructType(value: 1)))
281    verify(concreteMock.method(structType: any(of: StructType(value: 0), StructType(value: 1)))).wasCalled()
282  }
283  
284  func testArgumentMatching_classType_multipleValueMatching() {
285    let classType = ClassType()
286    let otherClassType = ClassType()
287    given(concreteMock.method(classType: any(of: otherClassType, classType))) ~> true
288    XCTAssertTrue(concreteInstance.method(classType: classType))
289    verify(concreteMock.method(classType: any(of: otherClassType, classType))).wasCalled()
290  }
291  
292  func testArgumentMatching_enumType_multipleValueMatching() {
293    given(concreteMock.method(enumType: any(of: .success, .failure))) ~> true
294    XCTAssertTrue(concreteInstance.method(enumType: .failure))
295    verify(concreteMock.method(enumType: any(of: .success, .failure))).wasCalled()
296  }
297  
298  func testArgumentMatching_stringType_multipleValueMatching() {
299    given(concreteMock.method(stringType: any(of: "foo", "bar", "hello-world"))) ~> true
300    XCTAssertTrue(concreteInstance.method(stringType: "hello-world"))
301    verify(concreteMock.method(stringType: any(of: "foo", "bar", "hello-world"))).wasCalled()
302  }
303  
304  func testArgumentMatching_boolType_multipleValueMatching() {
305    given(concreteMock.method(boolType: any(of: true, false))) ~> true
306    XCTAssertTrue(concreteInstance.method(boolType: false))
307    verify(concreteMock.method(boolType: any(of: true, false))).wasCalled()
308  }
309  
310  func testArgumentMatching_anyObjectType_multipleValueMatching() {
311    let classTypeReference = ClassType()
312    given(concreteMock.method(anyObjectType: any(of: ClassType(), classTypeReference))) ~> true
313    XCTAssertTrue(concreteInstance.method(anyObjectType: classTypeReference))
314    verify(concreteMock.method(anyObjectType: any(of: ClassType(), classTypeReference))).wasCalled()
315  }
316  
317  // MARK: - Conditional matching
318  
319  func testArgumentMatching_structType_conditionalMatching() {
320    given(concreteMock.method(structType: any(where: { $0.value > 99 }))) ~> true
321    XCTAssertTrue(concreteInstance.method(structType: StructType(value: 100)))
322    verify(concreteMock.method(structType: any(where: { $0.value > 99 }))).wasCalled()
323  }
324  
325  func testArgumentMatching_structType_didNotMatchConditionalMatching() {
326    given(concreteMock.method(structType: any())) ~> true
327    given(concreteMock.method(structType: any(where: { $0.value > 99 }))) ~> false
328    XCTAssertTrue(concreteInstance.method(structType: StructType(value: 1)))
329    verify(concreteMock.method(structType: any(where: { $0.value > 99 }))).wasNeverCalled()
330  }
331}
332
Full Screen

Accelerate Your Automation Test Cycles With LambdaTest

Leverage LambdaTest’s cloud-based platform to execute your automation tests in parallel and trim down your test execution time significantly. Your first 100 automation testing minutes are on us.

Try LambdaTest

Most used method in ArgumentMatchingTests

Trigger testArgumentMatching_optionalProtocolType_usingNotNilWildcardMatching code on LambdaTest Cloud Grid

Execute automation tests with testArgumentMatching_optionalProtocolType_usingNotNilWildcardMatching on a cloud-based Grid of 3000+ real browsers and operating systems for both web and mobile applications.

Test now for Free
LambdaTestX

We use cookies to give you the best experience. Cookies help to provide a more personalized experience and relevant advertising for you, and web analytics for us. Learn More in our Cookies policy, Privacy & Terms of service

Allow Cookie
Sarah

I hope you find the best code examples for your project.

If you want to accelerate automated browser testing, try LambdaTest. Your first 100 automation testing minutes are FREE.

Sarah Elson (Product & Growth Lead)