21
21
#import " Firebase/InstanceID/FIRInstanceIDBackupExcludedPlist.h"
22
22
#import " Firebase/InstanceID/FIRInstanceIDStore.h"
23
23
24
- static NSString *const kApplicationSupportSubDirectoryName = @" FirebaseInstanceIDBackupPlistTest" ;
24
+ static NSString *const kSubDirectoryName = @" FirebaseInstanceIDBackupPlistTest" ;
25
25
static NSString *const kTestPlistFileName = @" com.google.test.IIDBackupExcludedPlist" ;
26
26
27
27
@interface FIRInstanceIDBackupExcludedPlist ()
@@ -38,15 +38,14 @@ @implementation FIRInstanceIDBackupExcludedPlistTest
38
38
39
39
- (void )setUp {
40
40
[super setUp ];
41
- [FIRInstanceIDStore createSubDirectory: kApplicationSupportSubDirectoryName ];
42
- self.plist = [[FIRInstanceIDBackupExcludedPlist alloc ]
43
- initWithFileName: kTestPlistFileName
44
- subDirectory: kApplicationSupportSubDirectoryName ];
41
+ [FIRInstanceIDStore createSubDirectory: kSubDirectoryName ];
42
+ self.plist = [[FIRInstanceIDBackupExcludedPlist alloc ] initWithFileName: kTestPlistFileName
43
+ subDirectory: kSubDirectoryName ];
45
44
}
46
45
47
46
- (void )tearDown {
48
47
[self .plist deleteFile: nil ];
49
- [FIRInstanceIDStore removeSubDirectory: kApplicationSupportSubDirectoryName error: nil ];
48
+ [FIRInstanceIDStore removeSubDirectory: kSubDirectoryName error: nil ];
50
49
[super tearDown ];
51
50
}
52
51
@@ -77,14 +76,14 @@ - (void)testWriteToPlistInApplicationSupportFolder {
77
76
XCTAssertTrue ([self .plist doesFileExist ]);
78
77
XCTAssertEqualObjects (plistContents, [self .plist contentAsDictionary ]);
79
78
80
- XCTAssertTrue ([self isPlistInApplicationSupportDirectory ]);
79
+ XCTAssertTrue ([self doesPlistFileExist ]);
81
80
}
82
81
83
82
- (void )testMovePlistToApplicationSupportDirectorySuccess {
84
83
NSDictionary *plistContents = @{@" hello" : @" world" , @" id" : @123 };
85
84
[self .plist writeDictionary: plistContents error: nil ];
86
- [self .plist moveToApplicationSupportSubDirectory: kApplicationSupportSubDirectoryName ];
87
- XCTAssertTrue ([self isPlistInApplicationSupportDirectory ]);
85
+ [self .plist moveToApplicationSupportSubDirectory: kSubDirectoryName ];
86
+ XCTAssertTrue ([self doesPlistFileExist ]);
88
87
XCTAssertFalse ([self isPlistInDocumentsDirectory ]);
89
88
90
89
NSDictionary *newPlistContents = @{@" world" : @" hello" };
@@ -97,19 +96,18 @@ - (void)testMovePlistToApplicationSupportDirectoryFailure {
97
96
// which should only apply to iOS.
98
97
#if TARGET_OS_IOS
99
98
// Delete the subdirectory
100
- [FIRInstanceIDStore removeSubDirectory: kApplicationSupportSubDirectoryName error: nil ];
99
+ [FIRInstanceIDStore removeSubDirectory: kSubDirectoryName error: nil ];
101
100
102
101
// Create a new plistl This would try to move or write to the ApplicationSupport directory
103
102
// but since the subdirectory is not there anymore it will fail and rather write to the
104
103
// Documents folder.
105
- self.plist = [[FIRInstanceIDBackupExcludedPlist alloc ]
106
- initWithFileName: kTestPlistFileName
107
- subDirectory: kApplicationSupportSubDirectoryName ];
104
+ self.plist = [[FIRInstanceIDBackupExcludedPlist alloc ] initWithFileName: kTestPlistFileName
105
+ subDirectory: kSubDirectoryName ];
108
106
109
107
NSDictionary *plistContents = @{@" hello" : @" world" , @" id" : @123 };
110
108
[self .plist writeDictionary: plistContents error: nil ];
111
109
112
- XCTAssertFalse ([self isPlistInApplicationSupportDirectory ]);
110
+ XCTAssertFalse ([self doesPlistFileExist ]);
113
111
XCTAssertTrue ([self isPlistInDocumentsDirectory ]);
114
112
115
113
NSDictionary *newPlistContents = @{@" world" : @" hello" };
@@ -118,36 +116,34 @@ - (void)testMovePlistToApplicationSupportDirectoryFailure {
118
116
XCTAssertEqualObjects (newPlistContents, [self .plist contentAsDictionary ]);
119
117
120
118
// The new file should still be written to the Documents folder.
121
- XCTAssertFalse ([self isPlistInApplicationSupportDirectory ]);
119
+ XCTAssertFalse ([self doesPlistFileExist ]);
122
120
XCTAssertTrue ([self isPlistInDocumentsDirectory ]);
123
121
#endif
124
122
}
125
123
126
124
#pragma mark - Private Helpers
127
125
128
- - (BOOL )isPlistInApplicationSupportDirectory {
126
+ - (BOOL )doesPlistFileExist {
129
127
#if TARGET_OS_TV
130
128
NSArray *directoryPaths =
131
129
NSSearchPathForDirectoriesInDomains (NSCachesDirectory, NSUserDomainMask, YES );
132
130
#else
133
131
NSArray *directoryPaths =
134
132
NSSearchPathForDirectoriesInDomains (NSApplicationSupportDirectory, NSUserDomainMask, YES );
135
133
#endif
136
- NSString *applicationSupportDirPath = directoryPaths.lastObject ;
137
- NSArray *components = @[
138
- applicationSupportDirPath, kApplicationSupportSubDirectoryName ,
139
- [NSString stringWithFormat: @" %@ .plist" , kTestPlistFileName ]
140
- ];
134
+ NSString *dirPath = directoryPaths.lastObject ;
135
+ NSArray *components =
136
+ @[ dirPath, kSubDirectoryName , [NSString stringWithFormat: @" %@ .plist" , kTestPlistFileName ] ];
141
137
NSString *plistPath = [NSString pathWithComponents: components];
142
138
return [[NSFileManager defaultManager ] fileExistsAtPath: plistPath];
143
139
}
144
140
145
141
- (BOOL )isPlistInDocumentsDirectory {
146
142
NSArray *directoryPaths =
147
143
NSSearchPathForDirectoriesInDomains (NSDocumentDirectory, NSUserDomainMask, YES );
148
- NSString *applicationSupportDirPath = directoryPaths.lastObject ;
144
+ NSString *documentsSupportDirPath = directoryPaths.lastObject ;
149
145
NSArray *components =
150
- @[ applicationSupportDirPath , [NSString stringWithFormat: @" %@ .plist" , kTestPlistFileName ] ];
146
+ @[ documentsSupportDirPath , [NSString stringWithFormat: @" %@ .plist" , kTestPlistFileName ] ];
151
147
NSString *plistPath = [NSString pathWithComponents: components];
152
148
return [[NSFileManager defaultManager ] fileExistsAtPath: plistPath];
153
149
}
0 commit comments