Skip to content

Commit

Permalink
Remove extraneous geo json source existence check (#1446)
Browse files Browse the repository at this point in the history
* Remove unnecessary check before updating a geo json source

* Update changelog
  • Loading branch information
evil159 committed Mar 29, 2023
1 parent 2db1066 commit 2fc58ce
Show file tree
Hide file tree
Showing 3 changed files with 1 addition and 41 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ Mapbox welcomes participation and contributions from everyone.

## main

* Remove unnecessary check before updating a geo json source.
* Remove deprecated `LocationManager.updateHeadingForCurrentDeviceOrientation()` method.
* Remove deprecated `MapEvents.EventKind`.
* Make NSNumber extension internal.
Expand Down
5 changes: 0 additions & 5 deletions Sources/MapboxMaps/Style/StyleSourceManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -91,11 +91,6 @@ internal final class StyleSourceManager: StyleSourceManagerProtocol {
}

internal func updateGeoJSONSource(withId id: String, geoJSON: GeoJSONObject, dataId: String? = nil) throws {
guard let sourceInfo = allSourceIdentifiers.first(where: { $0.id == id }),
sourceInfo.type == .geoJson else {
throw StyleError(message: "Source with id '\(id)' is not found or not a GeoJSONSource.")
}

applyGeoJSON(data: geoJSON.sourceData, sourceId: id, dataId: dataId)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,42 +100,6 @@ final class StyleSourceManagerTests: XCTestCase {
XCTAssertEqual(styleManager.styleSourceExistsStub.invocations.count, 2)
}

func testUpdateGeoJSONSourceThrowsForNotFoundSource() {
let id = String.randomASCII(withLength: 10)
let geoJSONObject = GeoJSONObject.featureCollection(FeatureCollection(features: []))

XCTAssertThrowsError(try sourceManager.updateGeoJSONSource(withId: id, geoJSON: geoJSONObject))
}

func testUpdateGeoJSONSourceWithDataIDThrowsForNotFoundSource() {
let id = "TestSourceID"
let geoJSONObject = GeoJSONObject.featureCollection(FeatureCollection(features: []))
let dataId = "TestdataId"

XCTAssertThrowsError(try sourceManager.updateGeoJSONSource(withId: id, geoJSON: geoJSONObject, dataId: dataId))
}

func testUpdateGeoJSONSourceThrowsForNotGeoJSONSource() {
let id = String.randomASCII(withLength: 10)
let geoJSONObject = GeoJSONObject.featureCollection(FeatureCollection(features: []))
let type = SourceType.raster
let info = StyleObjectInfo(id: id, type: type.rawValue)
styleManager.getStyleSourcesStub.defaultReturnValue = [info]

XCTAssertThrowsError(try sourceManager.updateGeoJSONSource(withId: id, geoJSON: geoJSONObject))
}

func testUpdateGeoJSONSourceWithDataIDThrowsForNotGeoJSONSource() {
let id = "TestSourceID"
let geoJSONObject = GeoJSONObject.featureCollection(FeatureCollection(features: []))
let dataId = "TestdataId"
let type = SourceType.raster
let info = StyleObjectInfo(id: id, type: type.rawValue)
styleManager.getStyleSourcesStub.defaultReturnValue = [info]

XCTAssertThrowsError(try sourceManager.updateGeoJSONSource(withId: id, geoJSON: geoJSONObject, dataId: dataId))
}

func testUpdateGeoJSONSourceDispatchesParsingOnABackgroundThread() throws {
let id = String.randomASCII(withLength: 10)
let geoJSONObject = GeoJSONObject.featureCollection(FeatureCollection(features: []))
Expand Down

0 comments on commit 2fc58ce

Please sign in to comment.