<commit_before>package com.openlattice.auth0

import com.auth0.client.auth.AuthAPI
import com.auth0.json.auth.TokenHolder
import com.auth0.net.AuthRequest
import com.openlattice.authentication.Auth0Configuration
import org.apache.commons.lang3.RandomStringUtils
import org.junit.Assert
import org.junit.Test
import org.mockito.Mockito
import java.util.*

/**
 *
 * @author <NAME> &lt;<EMAIL>&gt;
 */
class AwsAuth0TokenProviderTest {
    @Test
    fun testMemoization() {
        val managementApiUrl =  RandomStringUtils.random(10)
        val audience = RandomStringUtils.random(10)
        val auth0Api = Mockito.mock(AuthAPI::class.java)
        val authRequest = Mockito.mock(AuthRequest::class.java)
        val tokenHolder = Mockito.mock(TokenHolder::class.java)

        Mockito.`when`(tokenHolder.accessToken).then { RandomStringUtils.random(10) }
        Mockito.`when`(tokenHolder.expiresIn).thenReturn(1 )
        Mockito.`when`(authRequest.execute()).thenReturn(tokenHolder)
        Mockito.`when`(auth0Api.requestToken(managementApiUrl)).thenReturn(authRequest)

        val tokenProvider = AwsAuth0TokenProvider(auth0Api, Auth0Configuration(
                audience,
                RandomStringUtils.random(10),
                RandomStringUtils.random(10),
                setOf(),
                Optional.empty(),
                managementApiUrl
        ))

        val v1 = tokenProvider.token
        val v2 = tokenProvider.token
        Thread.sleep(800)
        val v3 = tokenProvider.token

        Assert.assertTrue( v1==v2 )
        Assert.assertTrue( v1!=v3 )
    }


}<commit_msg>add unit test<commit_after>package com.openlattice.auth0

import com.auth0.client.auth.AuthAPI
import com.auth0.json.auth.TokenHolder
import com.auth0.net.AuthRequest
import com.openlattice.authentication.Auth0Configuration
import org.apache.commons.lang3.RandomStringUtils
import org.junit.Assert
import org.junit.Test
import org.mockito.Mockito
import java.util.*
import java.util.concurrent.Callable
import java.util.concurrent.Executors

/**
 *
 * @author <NAME> &lt;<EMAIL>&gt;
 */
class AwsAuth0TokenProviderTest {
    @Test(timeout = 2000)
    // timeout means deadlock in something
    fun testMemoization() {
        val managementApiUrl =  RandomStringUtils.random(10)
        val audience = RandomStringUtils.random(10)
        val auth0Api = Mockito.mock(AuthAPI::class.java)
        val authRequest = Mockito.mock(AuthRequest::class.java)
        val tokenHolder = Mockito.mock(TokenHolder::class.java)

        Mockito.`when`(tokenHolder.accessToken).then { RandomStringUtils.random(10) }
        Mockito.`when`(tokenHolder.expiresIn).thenReturn(1 )
        Mockito.`when`(authRequest.execute()).thenReturn(tokenHolder)
        Mockito.`when`(auth0Api.requestToken(managementApiUrl)).thenReturn(authRequest)
        val exec = Executors.newCachedThreadPool()
        // construct the token provider on another thread in case there's a bug.
        val tokenProvider = exec.submit(Callable<AwsAuth0TokenProvider> {
            AwsAuth0TokenProvider(auth0Api, Auth0Configuration(
                    audience,
                    RandomStringUtils.random(10),
                    RandomStringUtils.random(10),
                    setOf(),
                    Optional.empty(),
                    managementApiUrl
            ))
        }).get()
        exec.shutdownNow()

        val v1 = tokenProvider.token
        val v2 = tokenProvider.token
        Thread.sleep(800)
        val v3 = tokenProvider.token

        Assert.assertTrue( v1==v2 )
        Assert.assertTrue( v1!=v3 )
    }
}
{'fraction_non_alphanumeric': 0.10185441461389427, 'fraction_numerical': 0.019651259341267643, 'mean_word_length': 2.8283898305084745, 'pattern_counts': {'":': 0, '<': 8, '<?xml version=': 0, '>': 8, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '829180', 'n_tokens_mistral': 1070, 'n_tokens_neox': 1033, 'n_words': 174}