forked from flipperdevices/Flipper-iOS-App
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Tests coverage for ServiceFactory implementations
- Loading branch information
Showing
3 changed files
with
68 additions
and
22 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
// | ||
// ServiceFactoryTests.swift | ||
// FlipperZero | ||
// | ||
// Created by Eugene Berdnikov on 9/3/20. | ||
// | ||
// | ||
|
||
@testable import Core | ||
import XCTest | ||
|
||
class ServiceFactoryTests: XCTestCase { | ||
func testSingletonFactoryDoesNotInvokeBuilderEarly() { | ||
let builderIsInvoked = BoolWrapper() | ||
let target = SingletonFactory { | ||
XCTAssertFalse(builderIsInvoked.value, "Builder is invoked more than once") | ||
builderIsInvoked.value = true | ||
return builderIsInvoked | ||
} | ||
|
||
XCTAssertFalse(builderIsInvoked.value, "Builder is invoked before `create` is called") | ||
_ = target.create() | ||
XCTAssert(builderIsInvoked.value, "Builder invocation was not tracked") | ||
} | ||
|
||
func testSingletonFactoryReturnsTheSameValueOnSubsequentCall() { | ||
let target = SingletonFactory(BoolWrapper.init) | ||
let firstValue = target.create() as AnyObject | ||
let secondValue = target.create() as AnyObject | ||
XCTAssert(firstValue === secondValue) | ||
} | ||
|
||
func testSingleUseFactoryDoesNotInvokeBuilderEarly() { | ||
let builderIsInvoked = BoolWrapper() | ||
let target = SingleUseFactory { | ||
XCTAssertFalse(builderIsInvoked.value, "Builder is invoked more than once") | ||
builderIsInvoked.value = true | ||
return builderIsInvoked | ||
} | ||
|
||
XCTAssertFalse(builderIsInvoked.value, "Builder is invoked before `create` is called") | ||
_ = target.create() | ||
XCTAssert(builderIsInvoked.value, "Builder invocation was not tracked") | ||
} | ||
|
||
func testSingleUseFactoryReturnsDifferentValueOnSubsequentCall() { | ||
let target = SingleUseFactory(BoolWrapper.init) | ||
let firstValue = target.create() as AnyObject | ||
let secondValue = target.create() as AnyObject | ||
XCTAssert(firstValue !== secondValue) | ||
} | ||
} | ||
|
||
private class BoolWrapper { | ||
var value = false | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters