How to use testArrayMatching_anyContainingValues_requiresAllElements method of CollectionArgumentMatchingTests class

Best Mockingbird code snippet using CollectionArgumentMatchingTests.testArrayMatching_anyContainingValues_requiresAllElements

Run Mockingbird automation tests on LambdaTest cloud grid

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

CollectionArgumentMatchingTests.swift

Source: CollectionArgumentMatchingTests.swift Github

copy
1//
2//  CollectionArgumentMatchingTests.swift
3//  MockingbirdTests
4//
5//  Created by Andrew Chang on 9/6/19.
6//
7
8import XCTest
9import Mockingbird
10@testable import MockingbirdTestsHost
11
12class CollectionArgumentMatchingTests: XCTestCase {
13  
14  var array: ArrayCollectionMock!
15  var dictionary: DictionaryCollectionMock!
16  
17  override func setUp() {
18    array = mock(ArrayCollection.self)
19    dictionary = mock(DictionaryCollection.self)
20  }
21  
22  // MARK: - Array
23  
24  func callArray(_ array: ArrayCollection, objects: [String]) -> Bool {
25    return array.method(objects: objects)
26  }
27  
28  func testArrayMatching_anyContainingValues_matchesIncludedElements() {
29    given(array.method(objects: any())) ~> false
30    given(array.method(objects: any(containing: "a", "b", "c"))) ~> true
31    XCTAssertTrue(callArray(array, objects: ["a", "b", "c"]))
32    verify(array.method(objects: any(containing: "a", "b", "c"))).wasCalled()
33  }
34  
35  func testArrayMatching_anyContainingValues_requiresAllElements() {
36    given(array.method(objects: any())) ~> false
37    given(array.method(objects: any(containing: "a", "b", "c"))) ~> true
38    XCTAssertFalse(callArray(array, objects: ["a", "b"]))
39    verify(array.method(objects: any(containing: "a", "b", "c"))).wasNeverCalled()
40  }
41  
42  func testArrayMatching_anyContainingValues_ignoresNonIncludedElements() {
43    given(array.method(objects: any())) ~> false
44    given(array.method(objects: any(containing: "a", "b", "c"))) ~> true
45    XCTAssertFalse(callArray(array, objects: ["d"]))
46    verify(array.method(objects: any(containing: "a", "b", "c"))).wasNeverCalled()
47  }
48  
49  func testArrayMatching_anyCount_matchesCountMatcher() {
50    given(array.method(objects: any())) ~> false
51    given(array.method(objects: any(count: atMost(4)))) ~> true
52    XCTAssertTrue(callArray(array, objects: ["the", "quick", "brown", "fox"]))
53    verify(array.method(objects: any(count: atMost(4)))).wasCalled()
54  }
55  
56  func testArrayMatching_anyCount_ignoresCountMatcher() {
57    given(array.method(objects: any())) ~> false
58    given(array.method(objects: any(count: atLeast(10)))) ~> true
59    XCTAssertFalse(callArray(array, objects: ["the", "quick", "brown", "fox"]))
60    verify(array.method(objects: any(count: atLeast(10)))).wasNeverCalled()
61  }
62  
63  func testArrayMatching_notEmpty_matchesCountMatcher() {
64    given(array.method(objects: any())) ~> false
65    given(array.method(objects: notEmpty())) ~> true
66    XCTAssertTrue(callArray(array, objects: ["the", "quick", "brown", "fox"]))
67    verify(array.method(objects: notEmpty())).wasCalled()
68  }
69  
70  func testArrayMatching_notEmpty_ignoresCountMatcher() {
71    given(array.method(objects: any())) ~> false
72    given(array.method(objects: notEmpty())) ~> true
73    XCTAssertFalse(callArray(array, objects: []))
74    verify(array.method(objects: notEmpty())).wasNeverCalled()
75  }
76  
77  // MARK: - Dictionary
78  
79  func callDictionary(_ dictionary: DictionaryCollection, objects: [String: String]) -> Bool {
80    return dictionary.method(objects: objects)
81  }
82  
83  // MARK: Values
84  
85  func testDictionaryMatching_anyContainingValues_matchesIncludedElements() {
86    given(dictionary.method(objects: any())) ~> false
87    given(dictionary.method(objects: any(containing: "A", "B"))) ~> true
88    XCTAssertTrue(callDictionary(dictionary, objects: ["a": "A", "b": "B"]))
89    verify(dictionary.method(objects: any(containing: "A", "B"))).wasCalled()
90  }
91  
92  func testDictionaryMatching_anyContainingValues_requiresAllElements() {
93    given(dictionary.method(objects: any())) ~> false
94    given(dictionary.method(objects: any(containing: "A", "B"))) ~> true
95    XCTAssertFalse(callDictionary(dictionary, objects: ["a": "A"]))
96    verify(dictionary.method(objects: any(containing: "A", "B"))).wasNeverCalled()
97  }
98  
99  func testDictionaryMatching_anyContainingValues_ignoresNonIncludedElements() {
100    given(dictionary.method(objects: any())) ~> false
101    given(dictionary.method(objects: any(containing: "A", "B"))) ~> true
102    XCTAssertFalse(callDictionary(dictionary, objects: ["c": "C"]))
103    verify(dictionary.method(objects: any(containing: "A", "B"))).wasNeverCalled()
104  }
105  
106  // MARK: Keys
107  
108  func testDictionaryMatching_anyKeys_matchesIncludedElements() {
109    given(dictionary.method(objects: any())) ~> false
110    given(dictionary.method(objects: any(keys: "a", "b"))) ~> true
111    XCTAssertTrue(callDictionary(dictionary, objects: ["a": "A", "b": "B"]))
112    verify(dictionary.method(objects: any(keys: "a", "b"))).wasCalled()
113  }
114  
115  func testDictionaryMatching_anyKeys_requiresAllElements() {
116    given(dictionary.method(objects: any())) ~> false
117    given(dictionary.method(objects: any(keys: "a", "b"))) ~> true
118    XCTAssertFalse(callDictionary(dictionary, objects: ["a": "A"]))
119    verify(dictionary.method(objects: any(keys: "a", "b"))).wasNeverCalled()
120  }
121  
122  func testDictionaryMatching_anyKeys_ignoresNonIncludedElements() {
123    given(dictionary.method(objects: any())) ~> false
124    given(dictionary.method(objects: any(keys: "a", "b"))) ~> true
125    XCTAssertFalse(callDictionary(dictionary, objects: ["c": "C"]))
126    verify(dictionary.method(objects: any(keys: "a", "b"))).wasNeverCalled()
127  }
128  
129  func testDictionaryMatching_anyCount_matchesCountMatcher() {
130    given(dictionary.method(objects: any())) ~> false
131    given(dictionary.method(objects: any(count: atMost(2)))) ~> true
132    XCTAssertTrue(callDictionary(dictionary, objects: ["the": "THE", "brown": "BROWN"]))
133    verify(dictionary.method(objects: any(count: atMost(2)))).wasCalled()
134  }
135  
136  func testDictionaryMatching_anyCount_ignoresCountMatcher() {
137    given(dictionary.method(objects: any())) ~> false
138    given(dictionary.method(objects: any(count: atLeast(10)))) ~> true
139    XCTAssertFalse(callDictionary(dictionary, objects: ["the": "THE", "brown": "BROWN"]))
140    verify(dictionary.method(objects: any(count: atLeast(10)))).wasNeverCalled()
141  }
142  
143  func testDictionaryMatching_notEmpty_matchesCountMatcher() {
144    given(dictionary.method(objects: any())) ~> false
145    given(dictionary.method(objects: notEmpty())) ~> true
146    XCTAssertTrue(callDictionary(dictionary, objects: ["the": "THE", "brown": "BROWN"]))
147    verify(dictionary.method(objects: notEmpty())).wasCalled()
148  }
149  
150  func testDictionaryMatching_notEmpty_ignoresCountMatcher() {
151    given(dictionary.method(objects: any())) ~> false
152    given(dictionary.method(objects: notEmpty())) ~> true
153    XCTAssertFalse(callDictionary(dictionary, objects: [:]))
154    verify(dictionary.method(objects: notEmpty())).wasNeverCalled()
155  }
156}
157
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
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)