File tree Expand file tree Collapse file tree 2 files changed +31
-0
lines changed
src/test/java/dgca/verifier/app/decoder Expand file tree Collapse file tree 2 files changed +31
-0
lines changed Original file line number Diff line number Diff line change @@ -58,5 +58,9 @@ dependencies {
5858 testImplementation " org.junit.jupiter:junit-jupiter-api:5.7.1"
5959 testImplementation " org.junit.jupiter:junit-jupiter-params:5.7.1"
6060 testImplementation " org.hamcrest:hamcrest:2.2"
61+ testImplementation " org.mockito:mockito-core:3.9.0"
62+ testImplementation " org.mockito.kotlin:mockito-kotlin:3.2.0"
63+ testImplementation " org.mockito:mockito-inline:2.7.21"
64+
6165 testRuntimeOnly " org.junit.jupiter:junit-jupiter-engine:5.7.1"
6266}
Original file line number Diff line number Diff line change @@ -20,18 +20,45 @@ import dgca.verifier.app.decoder.prefixvalidation.PrefixValidationService
2020import dgca.verifier.app.decoder.schema.DefaultSchemaValidator
2121import dgca.verifier.app.decoder.schema.SchemaValidator
2222import dgca.verifier.app.decoder.services.X509
23+ import org.junit.After
2324import org.junit.Assert
2425import org.junit.Assert.assertTrue
26+ import org.junit.Before
2527import org.junit.Test
28+ import org.mockito.MockedStatic
29+ import org.mockito.Mockito.*
2630import java.io.ByteArrayInputStream
2731import java.io.IOException
2832import java.io.InputStream
2933import java.security.cert.CertificateException
3034import java.security.cert.CertificateFactory
3135import java.security.cert.X509Certificate
36+ import java.time.Clock
37+ import java.time.Instant
3238import java.util.*
3339
40+
3441class QrCodeTests {
42+
43+ private var clockMock: MockedStatic <Clock >? = null
44+
45+ @Before
46+ fun setup () {
47+ mockInstant(1640000000 ) // set desired return value 2021-12-20T11:33:20Z
48+ }
49+
50+ @After
51+ fun destroy () {
52+ clockMock!! .close()
53+ }
54+
55+ private fun mockInstant (expected : Long ) {
56+ val spyClock: Clock = spy(Clock ::class .java)
57+ clockMock = mockStatic(Clock ::class .java)
58+ clockMock!! .`when `<Any > { Clock .systemUTC() }.thenReturn(spyClock)
59+ `when `(spyClock.instant()).thenReturn(Instant .ofEpochSecond(expected))
60+ }
61+
3562 @Throws(CertificateException ::class )
3663 fun toCertificate (pubKey : String? ): X509Certificate {
3764 val `in ` = Base64 .getDecoder().decode(pubKey)
You can’t perform that action at this time.
0 commit comments