@@ -9,33 +9,60 @@ import JsonFormats._ // Your encoders
99
1010class UnitedWeStandAppTest extends AnyFunSuite {
1111
12- test(" UnitedWeStandApp.runCycles output should be valid JSON and contain non-empty participants array" ) {
12+ test(
13+ " UnitedWeStandApp.runCycles output should be valid JSON and contain non-empty participants array"
14+ ) {
1315 // Directly call runCycles and serialize, to avoid capturing stdout
1416 val society = UnitedWeStandApp .runCycles(cycleCount = 5 ) // Use a small cycle count for testing
1517 val jsonString = society.asJson.noSpaces
1618
1719 // 1. Check if the string is valid JSON
1820 val parsedJsonResult = parse(jsonString)
19- assert(parsedJsonResult.isRight, s " Output should be valid JSON. Parsing error: ${parsedJsonResult.left.getOrElse(" " )}" )
21+ assert(
22+ parsedJsonResult.isRight,
23+ s " Output should be valid JSON. Parsing error: ${parsedJsonResult.left.getOrElse(" " )}"
24+ )
2025
2126 // 2. Perform checks on the parsed JSON structure
22- val json = parsedJsonResult.getOrElse(throw new RuntimeException (" JSON parsing failed in test, this should not happen due to the assert above." ))
27+ val json = parsedJsonResult.getOrElse(
28+ throw new RuntimeException (
29+ " JSON parsing failed in test, this should not happen due to the assert above."
30+ )
31+ )
2332
2433 // Check for the presence of the 'participants' array
2534 val participantsCursor = json.hcursor.downField(" participants" )
26- assert(participantsCursor.succeeded, " JSON should contain a 'participants' field." )
35+ assert(
36+ participantsCursor.succeeded,
37+ " JSON should contain a 'participants' field."
38+ )
2739
2840 // Check if 'participants' is an array and is non-empty
2941 val participantsArray = participantsCursor.as[List [Json ]]
30- assert(participantsArray.isRight, " 'participants' field should be an array." )
31- assert(participantsArray.getOrElse(Nil ).nonEmpty, " Participants array should not be empty." )
42+ assert(
43+ participantsArray.isRight,
44+ " 'participants' field should be an array."
45+ )
46+ assert(
47+ participantsArray.getOrElse(Nil ).nonEmpty,
48+ " Participants array should not be empty."
49+ )
3250
3351 // 3. Optionally, check structure of a participant (if needed, more detailed)
3452 val firstParticipantOpt = participantsArray.getOrElse(Nil ).headOption
35- assert(firstParticipantOpt.isDefined, " Participant array should have at least one participant." )
53+ assert(
54+ firstParticipantOpt.isDefined,
55+ " Participant array should have at least one participant."
56+ )
3657
3758 val firstParticipantJson = firstParticipantOpt.get
38- assert(firstParticipantJson.hcursor.downField(" uuid" ).as[String ].isRight, " Participant should have a 'uuid' string field." )
39- assert(firstParticipantJson.hcursor.downField(" opinion" ).as[Boolean ].isRight, " Participant should have an 'opinion' boolean field." )
59+ assert(
60+ firstParticipantJson.hcursor.downField(" uuid" ).as[String ].isRight,
61+ " Participant should have a 'uuid' string field."
62+ )
63+ assert(
64+ firstParticipantJson.hcursor.downField(" opinion" ).as[Boolean ].isRight,
65+ " Participant should have an 'opinion' boolean field."
66+ )
4067 }
4168}
0 commit comments