|
| 1 | +package org.zalando.jsonapi.model.implicits |
| 2 | + |
| 3 | +import org.scalatest.{Matchers, WordSpec} |
| 4 | +import org.zalando.jsonapi.model.Attribute |
| 5 | +import org.zalando.jsonapi.model.JsonApiObject._ |
| 6 | +import org.zalando.jsonapi.model.implicits.AttributeConversions._ |
| 7 | + |
| 8 | +class AttributeConversionsSpec extends WordSpec with Matchers { |
| 9 | + "scala tuples" should { |
| 10 | + "be converted to string attributes" in { |
| 11 | + convertToStringAttribute("name" -> "string") should be(Attribute("name", StringValue("string"))) |
| 12 | + } |
| 13 | + "be converted to number attributes" in { |
| 14 | + convertToIntAttribute("name" -> 42) should be(Attribute("name", NumberValue(42))) |
| 15 | + convertToLongAttribute("name" -> 42l) should be(Attribute("name", NumberValue(42))) |
| 16 | + convertToFloatAttribute("name" -> 42f) should be(Attribute("name", NumberValue(42))) |
| 17 | + convertToDoubleAttribute("name" -> 42d) should be(Attribute("name", NumberValue(42))) |
| 18 | + } |
| 19 | + "be converted to boolean attributes" in { |
| 20 | + convertToBooleanAttribute("name" -> true) should be(Attribute("name", BooleanValue(true))) |
| 21 | + convertToBooleanAttribute("name" -> false) should be(Attribute("name", BooleanValue(false))) |
| 22 | + } |
| 23 | + |
| 24 | + "be converted to optional string attributes" in { |
| 25 | + convertToOptionalStringAttribute("name" -> Option("string")) should be(Option(Attribute("name", StringValue("string")))) |
| 26 | + } |
| 27 | + "be converted to optional number attributes" in { |
| 28 | + convertToOptionalIntAttribute("name" -> Option(42)) should be(Option(Attribute("name", NumberValue(42)))) |
| 29 | + convertToOptionalLongAttribute("name" -> Option(42l)) should be(Option(Attribute("name", NumberValue(42)))) |
| 30 | + convertToOptionalFloatAttribute("name" -> Option(42f)) should be(Option(Attribute("name", NumberValue(42)))) |
| 31 | + convertToOptionalDoubleAttribute("name" -> Option(42d)) should be(Option(Attribute("name", NumberValue(42)))) |
| 32 | + } |
| 33 | + "be converted to optional boolean attributes" in { |
| 34 | + convertToOptionalBooleanAttribute("name" -> Option(true)) should be(Option(Attribute("name", BooleanValue(true)))) |
| 35 | + convertToOptionalBooleanAttribute("name" -> Option(false)) should be(Option(Attribute("name", BooleanValue(false)))) |
| 36 | + } |
| 37 | + } |
| 38 | +} |
0 commit comments