From 6675e813cec84ff95bbf50fc302767c6b22a4d96 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Minh=20Nguy=E1=BB=85n?= Date: Mon, 15 Aug 2016 08:27:59 -0700 Subject: [ios, macos] Replaced testAAALoadPacks with a setUp method (#6007) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit XCTest apparently no longer executes tests in alphabetical order, so naming the test testAAALoadPacks doesn’t ensure it gets run first. Instead, put the pack loading test inside -setUp, but also put it inside a dispatch_once() block to ensure that it only gets run before the first offline storage test that gets run in the current process. --- platform/darwin/test/MGLOfflineStorageTests.m | 28 +++++++++++++++------------ 1 file changed, 16 insertions(+), 12 deletions(-) (limited to 'platform') diff --git a/platform/darwin/test/MGLOfflineStorageTests.m b/platform/darwin/test/MGLOfflineStorageTests.m index e44bd06e3d..0661a58ce3 100644 --- a/platform/darwin/test/MGLOfflineStorageTests.m +++ b/platform/darwin/test/MGLOfflineStorageTests.m @@ -8,20 +8,24 @@ @implementation MGLOfflineStorageTests -- (void)testSharedObject { - XCTAssertEqual([MGLOfflineStorage sharedOfflineStorage], [MGLOfflineStorage sharedOfflineStorage], @"There should only be one shared offline storage object."); +- (void)setUp { + [super setUp]; + + static dispatch_once_t onceToken; + dispatch_once(&onceToken, ^{ + [self keyValueObservingExpectationForObject:[MGLOfflineStorage sharedOfflineStorage] keyPath:@"packs" handler:^BOOL(id _Nonnull observedObject, NSDictionary * _Nonnull change) { + NSKeyValueChange changeKind = [change[NSKeyValueChangeKindKey] unsignedIntegerValue]; + return changeKind = NSKeyValueChangeSetting; + }]; + + [self waitForExpectationsWithTimeout:1 handler:nil]; + + XCTAssertNotNil([MGLOfflineStorage sharedOfflineStorage].packs, @"Shared offline storage object should have a non-nil collection of packs by this point."); + }); } -// This test needs to come first so it can test the initial loading of packs. -- (void)testAAALoadPacks { - [self keyValueObservingExpectationForObject:[MGLOfflineStorage sharedOfflineStorage] keyPath:@"packs" handler:^BOOL(id _Nonnull observedObject, NSDictionary * _Nonnull change) { - NSKeyValueChange changeKind = [change[NSKeyValueChangeKindKey] unsignedIntegerValue]; - return changeKind = NSKeyValueChangeSetting; - }]; - - [self waitForExpectationsWithTimeout:1 handler:nil]; - - XCTAssertNotNil([MGLOfflineStorage sharedOfflineStorage].packs, @"Shared offline storage object should have a non-nil collection of packs by this point."); +- (void)testSharedObject { + XCTAssertEqual([MGLOfflineStorage sharedOfflineStorage], [MGLOfflineStorage sharedOfflineStorage], @"There should only be one shared offline storage object."); } - (void)testAddPack { -- cgit v1.2.1