How to use OverloadedMethodsClass class

Best Mockingbird code snippet using .OverloadedMethodsClass

Run Mockingbird automation tests on LambdaTest cloud grid

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

OverloadedMethods.swift

Source: OverloadedMethods.swift Github

copy
1//
2//  OverloadedMethods.swift
3//  MockingbirdTestsHost
4//
5//  Created by Andrew Chang on 8/25/19.
6//
7
8import Foundation
9
10protocol OverloadedMethodsProtocol {
11  func overloadedParameters(param1: Bool, param2: Bool) -> Bool
12  func overloadedParameters(param1: Int, param2: Int) -> Bool
13  func overloadedParameters<T>(param1: T, param2: T) -> T
14  
15  func overloadedReturnType() -> Bool
16  func overloadedReturnType() -> Int
17  func overloadedGenericReturnType<T>() -> T
18}
19
20class OverloadedMethodsClass {
21  func overloadedParameters(param1: Bool, param2: Bool) -> Bool { return true }
22  func overloadedParameters(param1: Int, param2: Int) -> Bool { return true }
23  func overloadedParameters<T>(param1: T, param2: T) -> T { fatalError() }
24  
25  func overloadedReturnType() -> Bool { return true }
26  func overloadedReturnType() -> Int { return 1 }
27  func overloadedGenericReturnType<T>() -> T { fatalError() }
28}
29
Full Screen

OverloadedMethodTests.swift

Source: OverloadedMethodTests.swift Github

copy
1//
2//  OverloadedMethodTests.swift
3//  MockingbirdTests
4//
5//  Created by Andrew Chang on 8/25/19.
6//
7
8import XCTest
9import Mockingbird
10@testable import MockingbirdTestsHost
11
12class OverloadedMethodTests: XCTestCase {
13  
14  var classMock: OverloadedMethodsClassMock!
15  var classInstance: OverloadedMethodsClass { return classMock }
16  var protocolMock: OverloadedMethodsProtocolMock!
17  var protocolInstance: OverloadedMethodsProtocol { return protocolMock }
18  
19  override func setUp() {
20    classMock = mock(OverloadedMethodsClass.self)
21    protocolMock = mock(OverloadedMethodsProtocol.self)
22  }
23  
24  func testOverloadedMethod_classMock_overloadedParameters() {
25    given(classMock.overloadedParameters(param1: any(Bool.self), param2: any())) ~> true
26    given(classMock.overloadedParameters(param1: any(Int.self), param2: any())) ~> false
27    XCTAssertTrue(classInstance.overloadedParameters(param1: true, param2: false))
28    XCTAssertFalse(classInstance.overloadedParameters(param1: 1, param2: 2))
29    verify(classMock.overloadedParameters(param1: any(Bool.self), param2: any())).wasCalled()
30    verify(classMock.overloadedParameters(param1: any(Int.self), param2: any())).wasCalled()
31  }
32  func testOverloadedMethod_protocolMock_overloadedParameters() {
33    given(protocolMock.overloadedParameters(param1: any(Bool.self), param2: any())) ~> true
34    given(protocolMock.overloadedParameters(param1: any(Int.self), param2: any())) ~> false
35    XCTAssertTrue(protocolInstance.overloadedParameters(param1: true, param2: false))
36    XCTAssertFalse(protocolInstance.overloadedParameters(param1: 1, param2: 2))
37    verify(protocolMock.overloadedParameters(param1: any(Bool.self), param2: any())).wasCalled()
38    verify(protocolMock.overloadedParameters(param1: any(Int.self), param2: any())).wasCalled()
39  }
40  
41  func testOverloadedMethod_classMock_overloadedReturnType() {
42    given(classMock.overloadedReturnType()) ~> true
43    given(classMock.overloadedReturnType()) ~> 1
44    XCTAssert(classInstance.overloadedReturnType() == true)
45    XCTAssert(classInstance.overloadedReturnType() == 1)
46    verify(classMock.overloadedReturnType()).returning(Bool.self).wasCalled()
47    verify(classMock.overloadedReturnType()).returning(Int.self).wasCalled()
48  }
49  func testOverloadedMethod_protocolMock_overloadedReturnType() {
50    given(protocolMock.overloadedReturnType()) ~> true
51    given(protocolMock.overloadedReturnType()) ~> 1
52    XCTAssert(protocolInstance.overloadedReturnType() == true)
53    XCTAssert(protocolInstance.overloadedReturnType() == 1)
54    verify(protocolMock.overloadedReturnType()).returning(Bool.self).wasCalled()
55    verify(protocolMock.overloadedReturnType()).returning(Int.self).wasCalled()
56  }
57  
58  func testOverloadedMethod_classMock_overloadedParameters_separateInvocationCounts() {
59    given(classMock.overloadedParameters(param1: any(Bool.self), param2: any())) ~> true
60    given(classMock.overloadedParameters(param1: any(Int.self), param2: any())) ~> false
61    XCTAssertTrue(classInstance.overloadedParameters(param1: true, param2: false))
62    verify(classMock.overloadedParameters(param1: any(Bool.self), param2: any())).wasCalled()
63    verify(classMock.overloadedParameters(param1: any(Int.self), param2: any())).wasNeverCalled()
64  }
65  func testOverloadedMethod_protocolMock_overloadedParameters_separateInvocationCounts() {
66    given(protocolMock.overloadedParameters(param1: any(Bool.self), param2: any())) ~> true
67    given(protocolMock.overloadedParameters(param1: any(Int.self), param2: any())) ~> false
68    XCTAssertTrue(protocolInstance.overloadedParameters(param1: true, param2: false))
69    verify(protocolMock.overloadedParameters(param1: any(Bool.self), param2: any())).wasCalled()
70    verify(protocolMock.overloadedParameters(param1: any(Int.self), param2: any())).wasNeverCalled()
71  }
72  
73  func testOverloadedMethod_classMock_overloadedReturnType_separateInvocationCounts() {
74    given(classMock.overloadedReturnType()) ~> true
75    given(classMock.overloadedReturnType()) ~> 1
76    XCTAssert(classInstance.overloadedReturnType() == true)
77    verify(classMock.overloadedReturnType()).returning(Bool.self).wasCalled()
78    verify(classMock.overloadedReturnType()).returning(Int.self).wasNeverCalled()
79  }
80  func testOverloadedMethod_protocolMock_overloadedReturnType_separateInvocationCounts() {
81    given(protocolMock.overloadedReturnType()) ~> true
82    given(protocolMock.overloadedReturnType()) ~> 1
83    XCTAssert(protocolInstance.overloadedReturnType() == true)
84    verify(protocolMock.overloadedReturnType()).returning(Bool.self).wasCalled()
85    verify(protocolMock.overloadedReturnType()).returning(Int.self).wasNeverCalled()
86  }
87  
88  func testOverloadedMethod_classMock_overloadedGenericReturnType_separateInvocationCounts() {
89    given(classMock.overloadedGenericReturnType()) ~> true
90    given(classMock.overloadedGenericReturnType()) ~> 1
91    XCTAssert(classInstance.overloadedGenericReturnType() == true)
92    verify(classMock.overloadedGenericReturnType()).returning(Bool.self).wasCalled()
93    verify(classMock.overloadedReturnType()).returning(Int.self).wasNeverCalled()
94  }
95  func testOverloadedMethod_protocolMock_overloadedGenericReturnType_separateInvocationCounts() {
96    given(protocolMock.overloadedGenericReturnType()) ~> true
97    given(protocolMock.overloadedGenericReturnType()) ~> 1
98    XCTAssert(protocolInstance.overloadedGenericReturnType() == true)
99    verify(protocolMock.overloadedGenericReturnType()).returning(Bool.self).wasCalled()
100    verify(protocolMock.overloadedGenericReturnType()).returning(Int.self).wasNeverCalled()
101  }
102}
103
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 methods in OverloadedMethodsClass

Run Selenium Automation Tests on LambdaTest Cloud Grid

Trigger Selenium automation tests on a cloud-based Grid of 3000+ real browsers and operating systems.

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)