Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issue in powermock-api-mockito2 #1144

Open
hafiz013 opened this issue Jan 10, 2023 · 0 comments
Open

Issue in powermock-api-mockito2 #1144

hafiz013 opened this issue Jan 10, 2023 · 0 comments

Comments

@hafiz013
Copy link

Hey there and thank you for using PowerMock

Please read the following tips before filing an issue:

Is this something you can debug and fix?

Can you see anything in the logs? Can you debug why this happens? Send a pull request! Bug fixes and documentation fixes are very welcome.

Is this question about PowerMock usage?

The better way to ask question:

  • The PowerMock mailing-list
  • Stackoverflow with the tag 'powermock'. (Make sure you include a short code snippet to demonstrate the problem and if you have an exception then make sure include stack trace.)

None of the above, want to create a GitHub issue

Issues should always have a Short, Self Contained, Correct (Compilable), Example (same as any question on stackoverflow.com)

In order to help us to clarify issue can you answer the following question:

What steps will reproduce the problem?
-Hi i try to mock use simplecache exoplayer but i get this error but still can run the code:
WARNING: An illegal reflective access operation has occurred
WARNING: Illegal reflective access by org.powermock.reflect.internal.WhiteboxImpl (file:/Users/mohdhafiz/.gradle/caches/transforms-2/files-2.1/b881769387f8f0472cf9cb77d1671e6e/jetified-powermock-reflect-2.0.9.jar) to method java.io.File.readObject(java.io.ObjectInputStream)
WARNING: Please consider reporting this to the maintainers of org.powermock.reflect.internal.WhiteboxImpl
WARNING: Use --illegal-access=warn to enable warnings of further illegal reflective access operations
WARNING: All illegal access operations will be denied in a future release
java.lang.NullPointerException
at com.google.android.exoplayer2.upstream.cache.CachedContentIndex$DatabaseStorage.load(CachedContentIndex.java:822)
at com.google.android.exoplayer2.upstream.cache.CachedContentIndex.initialize(CachedContentIndex.java:207)
at com.google.android.exoplayer2.upstream.cache.SimpleCache.initialize(SimpleCache.java:582)
at com.google.android.exoplayer2.upstream.cache.SimpleCache.access$000(SimpleCache.java:49)
at com.google.android.exoplayer2.upstream.cache.SimpleCache$1.run(SimpleCache.java:268)
What is the expected output?

  • no error display
    What do you see instead?
  • run unit test as usual
    What version of the product are you using?
    -testImplementation "org.powermock:powermock-module-junit4:2.0.9"
    -testImplementation "org.powermock:powermock-api-mockito2:2.0.9"

Sample code as below :
`@RunWith(PowerMockRunner::class)
@PrepareForTest(VideoCache::class, SimpleCache::class)
class VideoCacheTest {
private lateinit var simpleCache: SimpleCache
private val videoCache = PowerMockito.mockStatic(VideoCache::class.java)
private val context = PowerMockito.mock(Context::class.java)

@Before
fun setup(){
    simpleCache = VideoCache.getInstance(context)
    //PowerMockito.`when`(VideoCache.getInstance(context)).thenReturn(simpleCache)
}

@Test
fun testGetInstanceVideoCache() {
    assertEquals("",simpleCache, VideoCache.getInstance(context))
}

}`

`object VideoCache {
private var downloadCache: SimpleCache? = null
private var downloadContentDirectory:File? = null
private var databaseProvider:StandaloneDatabaseProvider? = null
private const val dirName: String = "Sample"

@Synchronized
fun getInstance(context : Context): SimpleCache {
    if (downloadCache == null) {
        downloadContentDirectory = File(context.cacheDir, dirName)
        databaseProvider = StandaloneDatabaseProvider(context)
        downloadCache = SimpleCache(downloadContentDirectory!!, NoOpCacheEvictor(), databaseProvider!!)
    }
    return downloadCache as SimpleCache
}

fun clearCache() {
    if(downloadContentDirectory != null && databaseProvider != null) {
        try {
            downloadCache?.release()
            SimpleCache.delete(downloadContentDirectory!!, databaseProvider!!)
            downloadContentDirectory = null
            databaseProvider = null
            downloadCache = null
        }catch (e:Exception){

        }
    }
}

}`

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant