Much better test for attachment persisting

This commit is contained in:
Lukas Spieß 2014-04-25 16:23:39 +02:00
parent 535537aa73
commit 82b217f19d
3 changed files with 17 additions and 5 deletions

View File

@ -65,7 +65,6 @@ NSString *const kBITCrashManagerStatus = @"BITCrashManagerStatus";
@interface BITCrashManager ()
@property (nonatomic, strong) NSFileManager *fileManager;
@property (nonatomic, copy, setter = setAlertViewHandler:) CustomAlertViewHandler alertViewHandler;
@end

View File

@ -36,6 +36,8 @@
@property (nonatomic) NSUncaughtExceptionHandler *exceptionHandler;
@property (nonatomic, strong) NSFileManager *fileManager;
@property (nonatomic, strong) BITPLCrashReporter *plCrashReporter;
@property (nonatomic) NSString *lastCrashFilename;
@ -66,6 +68,8 @@
- (void)persistUserProvidedCrashDescription:(NSString *)userProvidedCrashDescription;
- (void)persistAttachment:(BITCrashAttachment *)attachment withFilename:(NSString *)filename;
- (BITCrashAttachment *)attachmentForCrashReport:(NSString *)filename;
- (void)invokeDelayedProcessing;
- (void)sendCrashReports;

View File

@ -23,6 +23,7 @@
#import "BITTestHelper.h"
#define kBITCrashMetaAttachment @"BITCrashMetaAttachment"
@interface BITCrashManagerTests : SenTestCase
@ -91,12 +92,20 @@
}
- (void)testPersistAttachment {
BITCrashAttachment *attachment = mock([BITCrashAttachment class]);
NSString *filename = @"testAttachment";
NSString *filename = @"TestAttachment";
NSData *data = [[NSData alloc] initWithBase64Encoding:@"TestData"];
NSString* type = @"text/plain";
[_sut persistAttachment:attachment withFilename:filename];
BITCrashAttachment *originalAttachment = [[BITCrashAttachment alloc] initWithFilename:filename attachmentData:data contentType:type];
NSString *attachmentFilename = [_sut.getCrashesDir stringByAppendingPathComponent:@"testAttachment"];
[given([NSData dataWithContentsOfFile:[filename stringByAppendingString:@".data"]]) willReturn:[NSMutableDictionary class]];
[_sut persistAttachment:originalAttachment withFilename:attachmentFilename];
BITCrashAttachment *decodedAttachment = [_sut attachmentForCrashReport:attachmentFilename];
assertThat(decodedAttachment.filename, equalTo(filename));
assertThat(decodedAttachment.attachmentData, equalTo(data));
assertThat(decodedAttachment.contentType, equalTo(type));
}
#pragma mark - Helper