Skip to content

Commit

Permalink
added Test
Browse files Browse the repository at this point in the history
  • Loading branch information
Peter Schumacher authored and Peter Schumacher committed Jun 7, 2016
1 parent 19794e5 commit c1724ed
Showing 1 changed file with 44 additions and 0 deletions.
44 changes: 44 additions & 0 deletions Tests/UnboxTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -907,6 +907,50 @@ class UnboxTests: XCTestCase {
XCTFail("Unexpected error thrown: \(error)")
}
}

func testFlattenedCustomUnboxingFromArrayWithMultipleClasses() {
struct ModelA {
let int: Int
}

struct ModelB {
let string: String
}

let array: [UnboxableDictionary] = [
[
"type" : "A",
"int" : 22
],
[
"type" : "B",
"WrongKey" : "hello"
]
]

do {
let unboxed: [Any] = try Unboxer.performFlattenedCustomUnboxingWithArray(array, closure: {
let unboxer = $0
let type = unboxer.unbox("type") as String

switch type {
case "A":
return ModelA(int: unboxer.unbox("int"))
case "B":
return ModelB(string: unboxer.unbox("string"))
default:
XCTFail()
}

return nil
})

XCTAssertEqual((unboxed.first as! ModelA).int, 22)
XCTAssertTrue(unboxed.count == 1)
} catch {
XCTFail("Unexpected error thrown: \(error)")
}
}
}

private func UnboxTestDictionaryWithAllRequiredKeysWithValidValues(nested: Bool) -> UnboxableDictionary {
Expand Down

0 comments on commit c1724ed

Please sign in to comment.