-
Notifications
You must be signed in to change notification settings - Fork 24.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
migrate ReactCookieJarContainerTest to Kotlin (#37809)
Summary: This PR migrates ReactCookieJarContainerTest.java to Kotlin as a part of the issue #37708 ## Changelog: [INTERNAL] [CHANGED] - Migrate ReactCookieJarContainerTest.java to Kotlin <!-- Help reviewers and the release process by writing your own changelog entry. Pick one each for the category and type tags: [ANDROID|GENERAL|IOS|INTERNAL] [BREAKING|ADDED|CHANGED|DEPRECATED|REMOVED|FIXED|SECURITY] - Message For more details, see: https://reactnative.dev/contributing/changelogs-in-pull-requests Pull Request resolved: #37809 Test Plan: 1. Run ./gradlew :packages:react-native:ReactAndroid:test. 2. All tests should pass. Reviewed By: javache Differential Revision: D46779169 Pulled By: rshest fbshipit-source-id: b5caa9397ac1b852fc73d9c58afc4a21caeb8727
- Loading branch information
1 parent
d097408
commit f1901d4
Showing
2 changed files
with
65 additions
and
71 deletions.
There are no files selected for viewing
71 changes: 0 additions & 71 deletions
71
...Android/src/test/java/com/facebook/react/modules/network/ReactCookieJarContainerTest.java
This file was deleted.
Oops, something went wrong.
65 changes: 65 additions & 0 deletions
65
...ctAndroid/src/test/java/com/facebook/react/modules/network/ReactCookieJarContainerTest.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
/* | ||
* Copyright (c) Meta Platforms, Inc. and affiliates. | ||
* | ||
* This source code is licensed under the MIT license found in the | ||
* LICENSE file in the root directory of this source tree. | ||
*/ | ||
|
||
package com.facebook.react.modules.network | ||
|
||
import okhttp3.Cookie | ||
import okhttp3.CookieJar | ||
import okhttp3.HttpUrl | ||
import org.assertj.core.api.Assertions.assertThat | ||
import org.junit.Test | ||
import org.junit.runner.RunWith | ||
import org.mockito.Mockito.any | ||
import org.mockito.Mockito.mock | ||
import org.mockito.Mockito.`when` as whenever | ||
import org.powermock.core.classloader.annotations.PowerMockIgnore | ||
import org.powermock.core.classloader.annotations.PrepareForTest | ||
import org.robolectric.RobolectricTestRunner | ||
|
||
/** Tests for {@link NetworkingModule}. */ | ||
@RunWith(RobolectricTestRunner::class) | ||
@PrepareForTest(ReactCookieJarContainer::class) | ||
@PowerMockIgnore("org.mockito.*", "org.robolectric.*", "androidx.*", "android.*") | ||
class ReactCookieJarContainerTest { | ||
private val httpUrl: HttpUrl = HttpUrl.parse("http://example.com") | ||
|
||
@Test | ||
fun testMissingJar() { | ||
val jarContainer: ReactCookieJarContainer = mock(ReactCookieJarContainer::class.java) | ||
assertThat(jarContainer.loadForRequest(httpUrl).size).isEqualTo(0) | ||
} | ||
|
||
@Test | ||
fun testEmptyCookies() { | ||
val jarContainer: ReactCookieJarContainer = mock(ReactCookieJarContainer::class.java) | ||
val cookies: List<Cookie> = emptyList() | ||
whenever(jarContainer.loadForRequest(any(HttpUrl::class.java))).thenReturn(cookies) | ||
assertThat(jarContainer.loadForRequest(httpUrl).size).isEqualTo(0) | ||
} | ||
|
||
@Test | ||
fun testValidCookies() { | ||
val jarContainer = ReactCookieJarContainer() | ||
val cookieJar: CookieJar = mock(CookieJar::class.java) | ||
jarContainer.setCookieJar(cookieJar) | ||
val cookies: MutableList<Cookie> = mutableListOf() | ||
cookies.add(Cookie.Builder().name("valid").value("valid value").domain("domain").build()) | ||
whenever(cookieJar.loadForRequest(httpUrl)).thenReturn(cookies) | ||
assertThat(jarContainer.loadForRequest(httpUrl).size).isEqualTo(1) | ||
} | ||
|
||
@Test | ||
fun testInvalidCookies() { | ||
val jarContainer = ReactCookieJarContainer() | ||
val cookieJar: CookieJar = mock(CookieJar::class.java) | ||
jarContainer.setCookieJar(cookieJar) | ||
val cookies: MutableList<Cookie> = mutableListOf() | ||
cookies.add(Cookie.Builder().name("valid").value("înválíd välūė").domain("domain").build()) | ||
whenever(cookieJar.loadForRequest(httpUrl)).thenReturn(cookies) | ||
assertThat(jarContainer.loadForRequest(httpUrl).size).isEqualTo(0) | ||
} | ||
} |