@@ -47,6 +47,7 @@ import com.ichi2.libanki.getStockNotetypeLegacy
4747import com.ichi2.libanki.sched.Scheduler
4848import com.ichi2.libanki.utils.set
4949import com.ichi2.testutils.common.assertThrows
50+ import com.ichi2.utils.KotlinCleanup
5051import com.ichi2.utils.emptyStringArray
5152import net.ankiweb.rsdroid.exceptions.BackendNotFoundException
5253import org.hamcrest.MatcherAssert.assertThat
@@ -242,9 +243,9 @@ class ContentProviderTest : InstrumentedTest() {
242243 TEST_NOTE_FIELDS .toMutableList(),
243244 )
244245 assertEquals(" Check that tag was set correctly" , TEST_TAG , addedNote.tags[0 ])
245- val noteType: JSONObject ? = col.notetypes.get(noteTypeId)
246+ val noteType: NotetypeJson ? = col.notetypes.get(noteTypeId)
246247 assertNotNull(" Check note type" , noteType)
247- val expectedNumCards = noteType!! .getJSONArray( " tmpls" ) .length()
248+ val expectedNumCards = noteType!! .tmpls.length()
248249 assertEquals(" Check that correct number of cards generated" , expectedNumCards, addedNote.numberOfCards(col))
249250 // Now delete the note
250251 cr.delete(newNoteUri, null , null )
@@ -287,7 +288,7 @@ class ContentProviderTest : InstrumentedTest() {
287288 val noteTypeUri = ContentUris .withAppendedId(FlashCardsContract .Model .CONTENT_URI , noteTypeId)
288289 val testIndex =
289290 TEST_NOTE_TYPE_CARDS .size - 1 // choose the last one because not the same as the basic note type template
290- val expectedOrd = noteType.getJSONArray( " tmpls" ) .length()
291+ val expectedOrd = noteType.tmpls.length()
291292 val cv =
292293 ContentValues ().apply {
293294 put(FlashCardsContract .CardTemplate .NAME , TEST_NOTE_TYPE_CARDS [testIndex])
@@ -309,21 +310,21 @@ class ContentProviderTest : InstrumentedTest() {
309310 )
310311 noteType = col.notetypes.get(noteTypeId)
311312 assertNotNull(" Check note type" , noteType)
312- val template = noteType!! .getJSONArray( " tmpls" ).getJSONObject( expectedOrd)
313+ val template = noteType!! .tmpls[ expectedOrd]
313314 assertEquals(
314315 " Check template JSONObject ord" ,
315316 expectedOrd,
316- template.getInt( " ord" ) ,
317+ template.ord,
317318 )
318319 assertEquals(
319320 " Check template name" ,
320321 TEST_NOTE_TYPE_CARDS [testIndex],
321- template.getString( " name" ) ,
322+ template.name,
322323 )
323- assertEquals(" Check qfmt" , TEST_NOTE_TYPE_QFMT [testIndex], template.getString( " qfmt" ) )
324- assertEquals(" Check afmt" , TEST_NOTE_TYPE_AFMT [testIndex], template.getString( " afmt" ) )
325- assertEquals(" Check bqfmt" , TEST_NOTE_TYPE_QFMT [testIndex], template.getString( " bqfmt" ) )
326- assertEquals(" Check bafmt" , TEST_NOTE_TYPE_AFMT [testIndex], template.getString( " bafmt" ) )
324+ assertEquals(" Check qfmt" , TEST_NOTE_TYPE_QFMT [testIndex], template.qfmt)
325+ assertEquals(" Check afmt" , TEST_NOTE_TYPE_AFMT [testIndex], template.afmt)
326+ assertEquals(" Check bqfmt" , TEST_NOTE_TYPE_QFMT [testIndex], template.bqfmt)
327+ assertEquals(" Check bafmt" , TEST_NOTE_TYPE_AFMT [testIndex], template.bafmt)
327328 col.notetypes.rem(noteType)
328329 }
329330
@@ -577,7 +578,7 @@ class ContentProviderTest : InstrumentedTest() {
577578 assertEquals(
578579 " Check templates length" ,
579580 TEST_NOTE_TYPE_CARDS .size,
580- noteType.getJSONArray( " tmpls" ) .length(),
581+ noteType.tmpls.length(),
581582 )
582583 assertEquals(
583584 " Check field length" ,
@@ -626,16 +627,16 @@ class ContentProviderTest : InstrumentedTest() {
626627 col = reopenCol()
627628 noteType = col.notetypes.get(mid)
628629 assertNotNull(" Check note type" , noteType)
629- val template = noteType!! .getJSONArray( " tmpls" ).getJSONObject(i)
630+ val template = noteType!! .tmpls[i]
630631 assertEquals(
631632 " Check template name" ,
632633 TEST_NOTE_TYPE_CARDS [i],
633- template.getString( " name" ) ,
634+ template.name,
634635 )
635- assertEquals(" Check qfmt" , TEST_NOTE_TYPE_QFMT [i], template.getString( " qfmt" ) )
636- assertEquals(" Check afmt" , TEST_NOTE_TYPE_AFMT [i], template.getString( " afmt" ) )
637- assertEquals(" Check bqfmt" , TEST_NOTE_TYPE_QFMT [i], template.getString( " bqfmt" ) )
638- assertEquals(" Check bafmt" , TEST_NOTE_TYPE_AFMT [i], template.getString( " bafmt" ) )
636+ assertEquals(" Check qfmt" , TEST_NOTE_TYPE_QFMT [i], template.qfmt)
637+ assertEquals(" Check afmt" , TEST_NOTE_TYPE_AFMT [i], template.afmt)
638+ assertEquals(" Check bqfmt" , TEST_NOTE_TYPE_QFMT [i], template.bqfmt)
639+ assertEquals(" Check bafmt" , TEST_NOTE_TYPE_AFMT [i], template.bafmt)
639640 }
640641 } finally {
641642 // Delete the note type (this will force a full-sync)
@@ -1404,19 +1405,22 @@ class ContentProviderTest : InstrumentedTest() {
14041405 }
14051406 }
14061407
1408+ @KotlinCleanup(" duplicate of TestClass method" )
14071409 fun addNonClozeNoteType (
14081410 name : String ,
14091411 fields : Array <String >,
1410- qfmt : String? ,
1411- afmt : String? ,
1412+ qfmt : String ,
1413+ afmt : String ,
14121414 ): String {
14131415 val noteType = col.notetypes.new(name)
14141416 for (field in fields) {
14151417 col.notetypes.addFieldInNewModel(noteType, col.notetypes.newField(field))
14161418 }
1417- val t = Notetypes .newTemplate(" Card 1" )
1418- t.put(" qfmt" , qfmt)
1419- t.put(" afmt" , afmt)
1419+ val t =
1420+ Notetypes .newTemplate(" Card 1" ).also { t ->
1421+ t.qfmt = qfmt
1422+ t.afmt = afmt
1423+ }
14201424 col.notetypes.addTemplateInNewModel(noteType, t)
14211425 col.notetypes.add(noteType)
14221426 return name
0 commit comments