@@ -3,6 +3,8 @@ package org.scalasteward.core.data
33import munit .FunSuite
44import org .scalasteward .core .TestSyntax ._
55import org .scalasteward .core .util .Nel
6+ import io .circe .syntax ._
7+ import io .circe .Json
68
79class UpdateTest extends FunSuite {
810 test(" Group.mainArtifactId" ) {
@@ -67,4 +69,135 @@ class UpdateTest extends FunSuite {
6769 (" org.scala-sbt" .g % Nel .of(" sbt-launch" .a, " scripted-plugin" .a) % " 1.2.1" %> " 1.2.4" ).group
6870 assertEquals(update.show, " org.scala-sbt:{sbt-launch, scripted-plugin} : 1.2.1 -> 1.2.4" )
6971 }
72+
73+ test(" ForArtifactId Encoder/Decoder" ) {
74+ val update1 : Update =
75+ (" org.specs2" .g % " specs2-core" .a % " 3.9.4" % " test" %> " 3.9.5" ).single
76+ val update2 : Update .ForArtifactId =
77+ (" org.specs2" .g % " specs2-core" .a % " 3.9.4" % " test" %> " 3.9.5" ).single
78+
79+ val expected = Json .obj(
80+ " ForArtifactId" := Json .obj(
81+ " crossDependency" := Json .arr(
82+ Json .obj(
83+ " groupId" := " org.specs2" ,
84+ " artifactId" := Json .obj(
85+ " name" := " specs2-core" ,
86+ " maybeCrossName" := None
87+ ),
88+ " version" := " 3.9.4" ,
89+ " sbtVersion" := None ,
90+ " scalaVersion" := None ,
91+ " configurations" := " test"
92+ )
93+ ),
94+ " newerVersions" := List (" 3.9.5" ),
95+ " newerGroupId" := None ,
96+ " newerArtifactId" := None
97+ )
98+ )
99+
100+ assertEquals(update1.asJson, expected)
101+ assertEquals(update1.asJson, update2.asJson)
102+ assertEquals(update1.asJson.as[Update ], update2.asJson.as[Update ])
103+ assertEquals(update1.asJson.as[Update .ForArtifactId ], update2.asJson.as[Update .ForArtifactId ])
104+ assertEquals(update1.asJson.as[Update ], update2.asJson.as[Update .ForArtifactId ])
105+ }
106+
107+ test(" ForGroupId Encoder/Decoder" ) {
108+ val update1 : Update =
109+ (" org.scala-sbt" .g % Nel .of(" sbt-launch" .a, " scripted-plugin" .a) % " 1.2.1" %> " 1.2.4" ).group
110+ val update2 : Update .ForGroupId =
111+ (" org.scala-sbt" .g % Nel .of(" sbt-launch" .a, " scripted-plugin" .a) % " 1.2.1" %> " 1.2.4" ).group
112+
113+ val expected = Json .obj(
114+ " ForGroupId" := Json .obj(
115+ " crossDependencies" := Json .arr(
116+ Json .arr(
117+ Json .obj(
118+ " groupId" := " org.scala-sbt" ,
119+ " artifactId" := Json .obj(
120+ " name" := " sbt-launch" ,
121+ " maybeCrossName" := None
122+ ),
123+ " version" := " 1.2.1" ,
124+ " sbtVersion" := None ,
125+ " scalaVersion" := None ,
126+ " configurations" := None
127+ )
128+ ),
129+ Json .arr(
130+ Json .obj(
131+ " groupId" := " org.scala-sbt" ,
132+ " artifactId" := Json .obj(
133+ " name" := " scripted-plugin" ,
134+ " maybeCrossName" := None
135+ ),
136+ " version" := " 1.2.1" ,
137+ " sbtVersion" := None ,
138+ " scalaVersion" := None ,
139+ " configurations" := None
140+ )
141+ )
142+ ),
143+ " newerVersions" := List (" 1.2.4" )
144+ )
145+ )
146+
147+ assertEquals(update1.asJson, expected)
148+ assertEquals(update1.asJson, update2.asJson)
149+ assertEquals(update1.asJson.as[Update ], update2.asJson.as[Update ])
150+ assertEquals(update1.asJson.as[Update .ForGroupId ], update2.asJson.as[Update .ForGroupId ])
151+ assertEquals(update1.asJson.as[Update ], update2.asJson.as[Update .ForGroupId ])
152+ }
153+
154+ test(" Grouped Encoder/Decoder" ) {
155+ val update1 : Update =
156+ Update .Grouped (
157+ name = " all" ,
158+ title = Some (" All" ),
159+ updates = List ((" org.specs2" .g % " specs2-core" .a % " 3.9.4" % " test" %> " 3.9.5" ).single)
160+ )
161+ val update2 : Update .Grouped =
162+ Update .Grouped (
163+ name = " all" ,
164+ title = Some (" All" ),
165+ updates = List ((" org.specs2" .g % " specs2-core" .a % " 3.9.4" % " test" %> " 3.9.5" ).single)
166+ )
167+
168+ val expected = Json .obj(
169+ " Grouped" := Json .obj(
170+ " name" := " all" ,
171+ " title" := " All" ,
172+ " updates" := Json .arr(
173+ Json .obj(
174+ " ForArtifactId" := Json .obj(
175+ " crossDependency" := Json .arr(
176+ Json .obj(
177+ " groupId" := " org.specs2" ,
178+ " artifactId" := Json .obj(
179+ " name" := " specs2-core" ,
180+ " maybeCrossName" := None
181+ ),
182+ " version" := " 3.9.4" ,
183+ " sbtVersion" := None ,
184+ " scalaVersion" := None ,
185+ " configurations" := " test"
186+ )
187+ ),
188+ " newerVersions" := List (" 3.9.5" ),
189+ " newerGroupId" := None ,
190+ " newerArtifactId" := None
191+ )
192+ )
193+ )
194+ )
195+ )
196+
197+ assertEquals(update1.asJson, expected)
198+ assertEquals(update1.asJson, update2.asJson)
199+ assertEquals(update1.asJson.as[Update ], update2.asJson.as[Update ])
200+ assertEquals(update1.asJson.as[Update .Grouped ], update2.asJson.as[Update .Grouped ])
201+ assertEquals(update1.asJson.as[Update ], update2.asJson.as[Update .Grouped ])
202+ }
70203}
0 commit comments