@@ -75,8 +75,8 @@ final class BSTextContentStorageTests: XCTestCase {
7575 }
7676
7777 func testTextStorageDelegation( ) {
78- contentStorage . string = " Test Text "
79- XCTAssertEqual ( contentStorage . string, " Test Text " )
78+ let storage = NSTextStorage ( string : " Test Text " )
79+ XCTAssertEqual ( storage . string, " Test Text " )
8080 }
8181}
8282
@@ -86,10 +86,11 @@ final class BSTextCacheTests: XCTestCase {
8686
8787 override func setUp( ) {
8888 super. setUp ( )
89- cache = BSTextCache ( )
89+ cache = BSTextCache . shared
9090 }
9191
9292 override func tearDown( ) {
93+ cache. removeAll ( )
9394 cache = nil
9495 super. tearDown ( )
9596 }
@@ -98,31 +99,32 @@ final class BSTextCacheTests: XCTestCase {
9899 XCTAssertNotNil ( cache)
99100 }
100101
101- func testCacheSetAndGet ( ) {
102- let key = " testKey "
103- let value = " testValue "
102+ func testImageCache ( ) {
103+ let key = " testImageKey "
104+ let image = UIImage ( )
104105
105- cache. setObject ( value as AnyObject , forKey: key)
106+ cache. cacheImage ( image, forKey: key, cost: 1000 )
107+ let retrievedImage = cache. image ( forKey: key)
106108
107- let retrievedValue = cache. object ( forKey: key) as? String
108- XCTAssertEqual ( retrievedValue, value)
109+ XCTAssertNotNil ( retrievedImage)
109110 }
110111
111- func testCacheRemove( ) {
112- let key = " testKey "
113- cache. setObject ( " value " as AnyObject , forKey: key)
114- cache. removeObject ( forKey: key)
112+ func testCacheRemoveAll( ) {
113+ let image1 = UIImage ( )
114+ let image2 = UIImage ( )
115+ cache. cacheImage ( image1, forKey: " key1 " , cost: 1000 )
116+ cache. cacheImage ( image2, forKey: " key2 " , cost: 1000 )
117+ cache. removeAll ( )
115118
116- let retrievedValue = cache. object ( forKey: key )
117- XCTAssertNil ( retrievedValue )
119+ XCTAssertNil ( cache. image ( forKey: " key1 " ) )
120+ XCTAssertNil ( cache . image ( forKey : " key2 " ) )
118121 }
119122
120- func testCacheRemoveAll( ) {
121- cache. setObject ( " value1 " as AnyObject , forKey: " key1 " )
122- cache. setObject ( " value2 " as AnyObject , forKey: " key2 " )
123- cache. removeAllObjects ( )
124-
125- XCTAssertNil ( cache. object ( forKey: " key1 " ) )
126- XCTAssertNil ( cache. object ( forKey: " key2 " ) )
123+ func testCacheMaxCost( ) {
124+ XCTAssertEqual ( cache. maxImageCacheCost, 100 * 1024 * 1024 )
127125 }
128- }
126+
127+ func testCacheMaxFragmentCount( ) {
128+ XCTAssertEqual ( cache. maxFragmentCount, 100 )
129+ }
130+ }
0 commit comments