This repository has been archived by the owner on Aug 4, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathEphemeralLifetimeTests.swift
59 lines (46 loc) · 1.66 KB
/
EphemeralLifetimeTests.swift
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
//
// EphemeralLifetimeTests.swift
// InjectableTests
//
// Created by Nicholas Cross on 19/1/19.
// Copyright © 2019 Nicholas Cross. All rights reserved.
//
import Foundation
@testable import Injectable
import XCTest
private class JavaScriptWebFramework: Injectable {
static func create(inContainer _: Container, variant _: String?) -> JavaScriptWebFramework {
return JavaScriptWebFramework()
}
}
private class StaticSiteGenerator: Injectable, LifetimeProviding {
static let lifetime: Lifetime = .ephemeral
static func create(inContainer _: Container, variant _: String?) -> StaticSiteGenerator {
return StaticSiteGenerator()
}
}
class EphemeralLifetimeTests: XCTestCase {
var container: DependencyContainer!
override func setUp() {
container = DependencyContainer()
}
override func tearDown() {
container = nil
}
func testEphemeralLifetimeWhenDefault() {
let webFramework1: JavaScriptWebFramework = container.resolve()
let webFramework2: JavaScriptWebFramework = container.resolve()
XCTAssert(webFramework1 !== webFramework2)
}
func testEphemeralLifetimeWhenSpecified() {
let webFramework1: StaticSiteGenerator = container.resolve()
let webFramework2: StaticSiteGenerator = container.resolve()
XCTAssert(webFramework1 !== webFramework2)
}
func testNoopStoreWhenLifetimeEphemeral() {
let webFramework1: JavaScriptWebFramework = container.resolve()
container.storeObject(object: webFramework1)
let webFramework2: JavaScriptWebFramework = container.resolve()
XCTAssert(webFramework1 !== webFramework2)
}
}