Browse Source

Unit tests for DateFormatterManager

Cleaning up unused methods..
pull/113/head
Abhishek Banthia 3 years ago
parent
commit
d45834a2ad
  1. 4
      Clocker/Clocker.xcodeproj/project.pbxproj
  2. 11
      Clocker/ClockerUnitTests/ClockerUnitTests.swift
  3. 36
      Clocker/ClockerUnitTests/DateFormatterManagerTests.swift
  4. 25
      Clocker/Overall App/DateFormatterManager.swift

4
Clocker/Clocker.xcodeproj/project.pbxproj

@ -51,6 +51,7 @@
3548C45F26BEEFB400AFB533 /* UpcomingEventsDataSource.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3548C45E26BEEFB400AFB533 /* UpcomingEventsDataSource.swift */; }; 3548C45F26BEEFB400AFB533 /* UpcomingEventsDataSource.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3548C45E26BEEFB400AFB533 /* UpcomingEventsDataSource.swift */; };
3548C46126BEEFE400AFB533 /* UpcomingEventViewItem.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3548C46026BEEFE400AFB533 /* UpcomingEventViewItem.swift */; }; 3548C46126BEEFE400AFB533 /* UpcomingEventViewItem.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3548C46026BEEFE400AFB533 /* UpcomingEventViewItem.swift */; };
35584D1427EF8EB5006E3EAD /* ThemerTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 35584D1327EF8EB5006E3EAD /* ThemerTests.swift */; }; 35584D1427EF8EB5006E3EAD /* ThemerTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 35584D1327EF8EB5006E3EAD /* ThemerTests.swift */; };
35584D1827F0B019006E3EAD /* DateFormatterManagerTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 35584D1727F0B019006E3EAD /* DateFormatterManagerTests.swift */; };
357391872507277500D30819 /* TimeMarkerViewItem.swift in Sources */ = {isa = PBXBuildFile; fileRef = 357391852507277500D30819 /* TimeMarkerViewItem.swift */; }; 357391872507277500D30819 /* TimeMarkerViewItem.swift in Sources */ = {isa = PBXBuildFile; fileRef = 357391852507277500D30819 /* TimeMarkerViewItem.swift */; };
357391882507277500D30819 /* HourMarkerViewItem.xib in Resources */ = {isa = PBXBuildFile; fileRef = 357391862507277500D30819 /* HourMarkerViewItem.xib */; }; 357391882507277500D30819 /* HourMarkerViewItem.xib in Resources */ = {isa = PBXBuildFile; fileRef = 357391862507277500D30819 /* HourMarkerViewItem.xib */; };
3579765E2680208C009DDA6E /* ParentPanelController+ModernSlider.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3579765D2680208C009DDA6E /* ParentPanelController+ModernSlider.swift */; }; 3579765E2680208C009DDA6E /* ParentPanelController+ModernSlider.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3579765D2680208C009DDA6E /* ParentPanelController+ModernSlider.swift */; };
@ -286,6 +287,7 @@
3552066427AF6488000EF08F /* pl */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = pl; path = pl.lproj/InfoPlist.strings; sourceTree = "<group>"; }; 3552066427AF6488000EF08F /* pl */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = pl; path = pl.lproj/InfoPlist.strings; sourceTree = "<group>"; };
3552066527AF6489000EF08F /* pl */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = pl; path = pl.lproj/Localizable.strings; sourceTree = "<group>"; }; 3552066527AF6489000EF08F /* pl */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = pl; path = pl.lproj/Localizable.strings; sourceTree = "<group>"; };
35584D1327EF8EB5006E3EAD /* ThemerTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ThemerTests.swift; sourceTree = "<group>"; }; 35584D1327EF8EB5006E3EAD /* ThemerTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ThemerTests.swift; sourceTree = "<group>"; };
35584D1727F0B019006E3EAD /* DateFormatterManagerTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DateFormatterManagerTests.swift; sourceTree = "<group>"; };
3569A44E25441F320087E254 /* pt-BR */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = "pt-BR"; path = "pt-BR.lproj/Localizable.strings"; sourceTree = "<group>"; }; 3569A44E25441F320087E254 /* pt-BR */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = "pt-BR"; path = "pt-BR.lproj/Localizable.strings"; sourceTree = "<group>"; };
357391852507277500D30819 /* TimeMarkerViewItem.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TimeMarkerViewItem.swift; sourceTree = "<group>"; }; 357391852507277500D30819 /* TimeMarkerViewItem.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TimeMarkerViewItem.swift; sourceTree = "<group>"; };
357391862507277500D30819 /* HourMarkerViewItem.xib */ = {isa = PBXFileReference; lastKnownFileType = file.xib; path = HourMarkerViewItem.xib; sourceTree = "<group>"; }; 357391862507277500D30819 /* HourMarkerViewItem.xib */ = {isa = PBXFileReference; lastKnownFileType = file.xib; path = HourMarkerViewItem.xib; sourceTree = "<group>"; };
@ -881,6 +883,7 @@
C20839CB21515C1F00C86589 /* Info.plist */, C20839CB21515C1F00C86589 /* Info.plist */,
9A0385BA269E3434003B5E72 /* StandardMenubarHandlerTests.swift */, 9A0385BA269E3434003B5E72 /* StandardMenubarHandlerTests.swift */,
35584D1327EF8EB5006E3EAD /* ThemerTests.swift */, 35584D1327EF8EB5006E3EAD /* ThemerTests.swift */,
35584D1727F0B019006E3EAD /* DateFormatterManagerTests.swift */,
); );
path = ClockerUnitTests; path = ClockerUnitTests;
sourceTree = "<group>"; sourceTree = "<group>";
@ -1268,6 +1271,7 @@
files = ( files = (
35584D1427EF8EB5006E3EAD /* ThemerTests.swift in Sources */, 35584D1427EF8EB5006E3EAD /* ThemerTests.swift in Sources */,
9A0385BB269E3434003B5E72 /* StandardMenubarHandlerTests.swift in Sources */, 9A0385BB269E3434003B5E72 /* StandardMenubarHandlerTests.swift in Sources */,
35584D1827F0B019006E3EAD /* DateFormatterManagerTests.swift in Sources */,
C20839CA21515C1E00C86589 /* ClockerUnitTests.swift in Sources */, C20839CA21515C1E00C86589 /* ClockerUnitTests.swift in Sources */,
); );
runOnlyForDeploymentPostprocessing = 0; runOnlyForDeploymentPostprocessing = 0;

11
Clocker/ClockerUnitTests/ClockerUnitTests.swift

@ -392,4 +392,15 @@ class ClockerUnitTests: XCTestCase {
XCTAssertNotNil(convertedDate) XCTAssertNotNil(convertedDate)
} }
} }
func testStringFiltering() {
let stringWithComma = "Mumbai, Maharashtra"
let stringWithoutComma = "Mumbai"
let emptyString = ""
XCTAssertEqual(stringWithComma.filteredName(), "Mumbai")
XCTAssertEqual(stringWithoutComma.filteredName(), "Mumbai")
XCTAssertEqual(emptyString.filteredName(), "")
}
} }

36
Clocker/ClockerUnitTests/DateFormatterManagerTests.swift

@ -0,0 +1,36 @@
// Copyright © 2015 Abhishek Banthia
import XCTest
@testable import Clocker;
class DateFormatterManagerTests: XCTestCase {
func testRegularDateFormatter() throws {
let subject = DateFormatterManager.dateFormatter(with: .medium, for: "UTC")
XCTAssertEqual(subject.dateStyle, .medium)
XCTAssertEqual(subject.timeStyle, .medium)
XCTAssertEqual(subject.locale.identifier, "en_US")
XCTAssertEqual(subject.timeZone.identifier, "GMT")
}
func testDateFormatterWithFormat() throws {
let subject = DateFormatterManager.dateFormatterWithFormat(with: .none, format: "hh:mm a", timezoneIdentifier: "Asia/Calcutta")
XCTAssertEqual(subject.dateStyle, .none)
XCTAssertEqual(subject.timeStyle, .none)
XCTAssertEqual(subject.locale.identifier, "en_US")
XCTAssertEqual(subject.timeZone.identifier, "Asia/Calcutta")
XCTAssertEqual(subject.locale.identifier, "en_US")
XCTAssertEqual(subject.dateFormat, "hh:mm a")
}
func testLocalizedDateFormatter() throws {
let subject = DateFormatterManager.localizedFormatter(with: "hh:mm:ss", for: "America/Los_Angeles")
XCTAssertEqual(subject.dateStyle, .none)
XCTAssertEqual(subject.timeStyle, .none)
XCTAssertEqual(subject.locale.identifier, Locale.autoupdatingCurrent.identifier)
XCTAssertEqual(subject.timeZone.identifier, "America/Los_Angeles")
XCTAssertEqual(subject.dateFormat, "hh:mm:ss")
}
}

25
Clocker/Overall App/DateFormatterManager.swift

@ -3,7 +3,6 @@
import Cocoa import Cocoa
class DateFormatterManager: NSObject { class DateFormatterManager: NSObject {
public static let sharedInstance = DateFormatterManager()
private static var dateFormatter = DateFormatter() private static var dateFormatter = DateFormatter()
private static var calendarDateFormatter = DateFormatter() private static var calendarDateFormatter = DateFormatter()
@ -22,21 +21,6 @@ class DateFormatterManager: NSObject {
return dateFormatter return dateFormatter
} }
class func dateFormatterWithCalendar(with style: DateFormatter.Style) -> DateFormatter {
calendarDateFormatter.dateStyle = style
calendarDateFormatter.timeStyle = style
calendarDateFormatter.locale = USLocale
calendarDateFormatter.calendar = gregorianCalendar
return calendarDateFormatter
}
class func simpleFormatter(with style: DateFormatter.Style) -> DateFormatter {
simpleFormatter.dateStyle = style
simpleFormatter.timeStyle = style
simpleFormatter.locale = USLocale
return simpleFormatter
}
class func dateFormatterWithFormat(with style: DateFormatter.Style, format: String, timezoneIdentifier: String, locale: Locale = Locale(identifier: "en_US")) -> DateFormatter { class func dateFormatterWithFormat(with style: DateFormatter.Style, format: String, timezoneIdentifier: String, locale: Locale = Locale(identifier: "en_US")) -> DateFormatter {
specializedFormatter.dateStyle = style specializedFormatter.dateStyle = style
specializedFormatter.timeStyle = style specializedFormatter.timeStyle = style
@ -55,15 +39,6 @@ class DateFormatterManager: NSObject {
return dateFormatter return dateFormatter
} }
class func localizedCalendaricalDateFormatter(with format: String) -> DateFormatter {
calendarDateFormatter.dateStyle = .none
calendarDateFormatter.timeStyle = .none
calendarDateFormatter.locale = Locale.autoupdatingCurrent
calendarDateFormatter.dateFormat = format
calendarDateFormatter.calendar = gregorianCalendar
return calendarDateFormatter
}
class func localizedSimpleFormatter(_ format: String) -> DateFormatter { class func localizedSimpleFormatter(_ format: String) -> DateFormatter {
localizedSimpleFormatter.dateStyle = .none localizedSimpleFormatter.dateStyle = .none
localizedSimpleFormatter.timeStyle = .none localizedSimpleFormatter.timeStyle = .none

Loading…
Cancel
Save