1+ package org .finos .vuu .core .table .util
2+
3+ import org .finos .vuu .core .table .RowWithData
4+ import org .scalatest .featurespec .AnyFeatureSpec
5+ import org .scalatest .matchers .should .Matchers
6+
7+ class RowDataUtilsTest extends AnyFeatureSpec with Matchers {
8+ private val rowData = RowWithData (" myKey" , Map (
9+ " key" -> " myKey" ,
10+ " id" -> 123L ,
11+ " someId" -> Some (123L ),
12+ " name" -> " user1" ,
13+ " someName" -> Some (" user1" ),
14+ " noneCol" -> None
15+ ))
16+
17+ Feature (" getRequiredLong" ) {
18+
19+ Scenario (" getRequiredLong should throw when rowData is null" ) {
20+ an[RowDataUtils .RowDataException ] should be thrownBy {
21+ RowDataUtils .getRequiredLong(null , " any" )
22+ }
23+ }
24+
25+ Scenario (" getRequiredLong should throw when columnName is null" ) {
26+ an[RowDataUtils .RowDataException ] should be thrownBy {
27+ RowDataUtils .getRequiredLong(rowData, null )
28+ }
29+ }
30+
31+ Scenario (" getRequiredLong should return a Long" ) {
32+ RowDataUtils .getRequiredLong(rowData, " id" ) shouldBe 123L
33+ }
34+
35+ Scenario (" getRequiredLong should unwrap Some(Long)" ) {
36+ RowDataUtils .getRequiredLong(rowData, " someId" ) shouldBe 123L
37+ }
38+
39+ Scenario (" getRequiredLong should throw when column is not in RowData" ) {
40+ an[RowDataUtils .RowDataException ] should be thrownBy {
41+ RowDataUtils .getRequiredLong(rowData, " dummy" )
42+ }
43+ }
44+
45+ Scenario (" getRequiredLong should throw when value is None" ) {
46+ an[RowDataUtils .RowDataException ] should be thrownBy {
47+ RowDataUtils .getRequiredLong(rowData, " noneCol" )
48+ }
49+ }
50+
51+ Scenario (" getRequiredLong should throw when value is not a Long" ) {
52+ an[RowDataUtils .RowDataException ] should be thrownBy {
53+ RowDataUtils .getRequiredLong(rowData, " name" )
54+ }
55+ }
56+ }
57+
58+ Feature (" getRequiredString" ) {
59+
60+ Scenario (" getRequiredString should throw when rowData is null" ) {
61+ an[RowDataUtils .RowDataException ] should be thrownBy {
62+ RowDataUtils .getRequiredString(null , " any" )
63+ }
64+ }
65+
66+ Scenario (" getRequiredString should throw when columnName is null" ) {
67+ an[RowDataUtils .RowDataException ] should be thrownBy {
68+ RowDataUtils .getRequiredString(rowData, null )
69+ }
70+ }
71+
72+ Scenario (" getRequiredString should return a String" ) {
73+ RowDataUtils .getRequiredString(rowData, " name" ) shouldBe " user1"
74+ }
75+
76+ Scenario (" getRequiredString should unwrap Some(String)" ) {
77+ RowDataUtils .getRequiredString(rowData, " someName" ) shouldBe " user1"
78+ }
79+
80+ Scenario (" getRequiredString should throw when column is not in RowData" ) {
81+ an[RowDataUtils .RowDataException ] should be thrownBy {
82+ RowDataUtils .getRequiredString(rowData, " dummy" )
83+ }
84+ }
85+
86+ Scenario (" getRequiredString should throw when value is None" ) {
87+ an[RowDataUtils .RowDataException ] should be thrownBy {
88+ RowDataUtils .getRequiredString(rowData, " noneCol" )
89+ }
90+ }
91+
92+ Scenario (" getRequiredString should throw when value is not a String" ) {
93+ an[RowDataUtils .RowDataException ] should be thrownBy {
94+ RowDataUtils .getRequiredString(rowData, " id" )
95+ }
96+ }
97+ }
98+
99+ Feature (" getString" ) {
100+
101+ Scenario (" getString should return null when rowData is null" ) {
102+ RowDataUtils .getString(null , " any" ) shouldBe null
103+ }
104+
105+ Scenario (" getString should return null when columnName is null" ) {
106+ RowDataUtils .getString(rowData, null ) shouldBe null
107+ }
108+
109+ Scenario (" getString should return a String" ) {
110+ RowDataUtils .getString(rowData, " name" ) shouldBe " user1"
111+ }
112+
113+ Scenario (" getString should unwrap Some(String)" ) {
114+ RowDataUtils .getString(rowData, " someName" ) shouldBe " user1"
115+ }
116+
117+ Scenario (" getString should return null when column is not in RowData" ) {
118+ RowDataUtils .getString(rowData, " dummy" ) shouldBe null
119+ }
120+
121+ Scenario (" getString should return null when value is None" ) {
122+ RowDataUtils .getString(rowData, " noneCol" ) shouldBe null
123+ }
124+
125+ Scenario (" getString should return null when value is not a String" ) {
126+ RowDataUtils .getString(rowData, " id" ) shouldBe null
127+ }
128+ }
129+ }
0 commit comments