Skip to content

Commit 24d439f

Browse files
committed
Added ObjectMetaSpec.
1 parent d0752a4 commit 24d439f

File tree

1 file changed

+47
-0
lines changed

1 file changed

+47
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
/*
2+
* Copyright 2001-2016 Artima, Inc.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
package org.scalactic.source
17+
18+
import org.scalatest._
19+
20+
class ObjectMetaSpec extends FunSpec with Matchers {
21+
22+
case class Person(name: String, age: Int) {
23+
val otherField = "test other field"
24+
}
25+
26+
describe("ObjectMeta") {
27+
28+
it("should extract case class attribute names correctly") {
29+
ObjectMeta(Person("test", 33)).fieldNames should contain theSameElementsAs Set("name", "age", "otherField")
30+
}
31+
32+
it("should extract dynamically field value correctly") {
33+
val meta = ObjectMeta(Person("test", 33))
34+
meta.value("name") shouldBe "test"
35+
meta.value("age") shouldBe 33
36+
meta.value("otherField") shouldBe "test other field"
37+
}
38+
39+
it("should throw IllegalArgumentException when invalid attribute name is used to retrieve value") {
40+
val meta = ObjectMeta(Person("test", 33))
41+
val e = intercept[IllegalArgumentException] {
42+
meta.value("invalid")
43+
}
44+
e.getMessage shouldBe "'invalid' is not attribute for this instance."
45+
}
46+
}
47+
}

0 commit comments

Comments
 (0)