Skip to content

Commit

Permalink
Add object instance identity assertions
Browse files Browse the repository at this point in the history
  • Loading branch information
Gregor Billing committed May 13, 2020
1 parent 4204fcb commit cdd5f8a
Showing 1 changed file with 12 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package org.worldcubeassociation.tnoodle.server.webscrambles.wcif

import io.mockk.spyk
import io.mockk.verify
import org.junit.jupiter.api.Assertions
import org.junit.jupiter.api.Test
import org.worldcubeassociation.tnoodle.server.model.EventData
import org.worldcubeassociation.tnoodle.server.webscrambles.wcif.WCIFDataBuilder.getCachedPdf
Expand All @@ -18,10 +19,12 @@ object WcifDataBuilderTest {
fun testPDFCachingCaches() {
val scrToDraw = spyk(randomScrambleSet(EventData.THREE))

scrToDraw.getCachedDummyPdf()
scrToDraw.getCachedDummyPdf()
val first = scrToDraw.getCachedDummyPdf()
val second = scrToDraw.getCachedDummyPdf()

verify(atMost = 1) { scrToDraw.createPdf(any(), any(), any(), any()) }

Assertions.assertSame(first, second)
}

@Test
Expand All @@ -38,17 +41,20 @@ object WcifDataBuilderTest {
val deepUpdatedScramble = scrToDraw.copy(scrambleSet = scrToDraw.scrambleSet.copy(scrambles = randomScrambleDrawing.scrambleSet.scrambles))
val deepScrToDraw = spyk(deepUpdatedScramble)

scrToDraw.getCachedDummyPdf()
shallowScrToDraw.getCachedDummyPdf()
deepScrToDraw.getCachedDummyPdf()
val firstBase = scrToDraw.getCachedDummyPdf()
val shallowPdf = shallowScrToDraw.getCachedDummyPdf()
val deepPdf = deepScrToDraw.getCachedDummyPdf()

verify(exactly = 1) { scrToDraw.createPdf(any(), any(), any(), any()) }
verify(exactly = 1) { shallowScrToDraw.createPdf(any(), any(), any(), any()) }
verify(exactly = 1) { deepScrToDraw.createPdf(any(), any(), any(), any()) }

scrToDraw.getCachedDummyPdf()
val secondBase = scrToDraw.getCachedDummyPdf()

verify(exactly = 1) { scrToDraw.createPdf(any(), any(), any(), any()) }

Assertions.assertSame(firstBase, secondBase)
Assertions.assertNotSame(shallowPdf, deepPdf)
}

private fun randomScrambleSet(event: EventData): ScrambleDrawingData {
Expand Down

0 comments on commit cdd5f8a

Please sign in to comment.