Skip to content

Commit

Permalink
Updating tests
Browse files Browse the repository at this point in the history
JIRA Issues: PUBPL-1897
  • Loading branch information
Julius Lundang authored and Rajul Arora committed Jul 13, 2018
1 parent b111622 commit b559fe1
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -57,42 +57,58 @@ - (void)testApiParsingFormatter_hasLocale

- (void)testCurrentYearDateFormatter
{
NSString *formattedDate = [[TWTRDateFormatters dayAndMonthDateFormatter] stringFromDate:self.apiDate];
XCTAssertTrue([formattedDate isEqualToString:@"Mar 05"]);
NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
dateFormatter.dateFormat = @"MMM dd";
NSString *desired = [dateFormatter stringFromDate:self.apiDate];
NSString *actual = [[TWTRDateFormatters dayAndMonthDateFormatter] stringFromDate:self.apiDate];
XCTAssertTrue([desired isEqualToString:actual]);
}

- (void)testCurrentYearDateFormatter_handlesLocale
{
[TWTRDateFormatters setLocale:self.spanishLocale];
NSString *formattedDate = [[TWTRDateFormatters dayAndMonthDateFormatter] stringFromDate:self.apiDate];
NSString *expectedDate;
NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
dateFormatter.dateFormat = [NSDateFormatter dateFormatFromTemplate:@"MMM dd" options:0 locale:self.spanishLocale];

NSProcessInfo *processInfo = [NSProcessInfo processInfo];
if ([processInfo respondsToSelector:@selector(operatingSystemVersion)] && processInfo.operatingSystemVersion.majorVersion >= 9) {
expectedDate = @"05 Mar";
expectedDate = [dateFormatter stringFromDate:self.apiDate];
} else {
expectedDate = @"05-Mar";
expectedDate = [dateFormatter stringFromDate:self.apiDate];
}
XCTAssertEqualObjects(formattedDate, expectedDate);
}

- (void)testSystemLongDateFormatter
{
NSString *formattedDate = [[TWTRDateFormatters systemLongDateFormatter] stringFromDate:self.apiDate];
XCTAssert([formattedDate isEqualToString:@"March 5, 2007"]);
NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
dateFormatter.dateStyle = NSDateFormatterLongStyle;
NSString *desired = [dateFormatter stringFromDate:self.apiDate];
NSString *actual = [[TWTRDateFormatters systemLongDateFormatter] stringFromDate:self.apiDate];
XCTAssert([actual isEqualToString:desired]);
}

- (void)testSystemLongDateFormatter_handlesLocale
{
[TWTRDateFormatters setLocale:self.spanishLocale];
NSString *formattedDate = [[TWTRDateFormatters systemLongDateFormatter] stringFromDate:self.apiDate];
NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
dateFormatter.dateStyle = NSDateFormatterLongStyle;
dateFormatter.locale = self.spanishLocale;
NSString *desired = [dateFormatter stringFromDate:self.apiDate];
NSString *actual = [[TWTRDateFormatters systemLongDateFormatter] stringFromDate:self.apiDate];

XCTAssert([formattedDate isEqualToString:@"5 de marzo de 2007"]);
XCTAssert([actual isEqualToString:desired]);
}

- (void)testShortHistoricalDateFormatter
{
NSString *formattedDate = [[TWTRDateFormatters shortHistoricalDateFormatter] stringFromDate:self.apiDate];
XCTAssertTrue([formattedDate isEqualToString:@"3/5/07"]);
NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
dateFormatter.dateStyle = NSDateFormatterShortStyle;
NSString *desired = [dateFormatter stringFromDate:self.apiDate];
NSString *actual = [[TWTRDateFormatters shortHistoricalDateFormatter] stringFromDate:self.apiDate];
XCTAssert([desired isEqualToString:actual]);
}

- (void)testHTTPDateHeaderParsingFormatter
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,10 @@ - (void)testIsDateInCurrentYearTrue

- (void)testAccessibilityText
{
NSString *desired = @"March 5, 2007";
NSDateFormatter *formatter = [[NSDateFormatter alloc] init];
formatter.dateStyle = NSDateFormatterLongStyle;

NSString *desired = [formatter stringFromDate:self.apiDate];
NSString *actual = [TWTRDateUtil accessibilityTextForDate:self.apiDate];
XCTAssert([desired isEqualToString:actual]);
}
Expand Down

0 comments on commit b559fe1

Please sign in to comment.