Skip to content

Commit

Permalink
Convert ReactPropForShadowNodeSpecTest to Kotlin (#39284)
Browse files Browse the repository at this point in the history
Summary:
This PR converts ReactPropForShadowNodeSpecTest to Kotlin. #38825

## Changelog:

[INTERNAL] [CHANGED] - Kotlinify ReactPropForShadowNodeSpecTest.java

For more details, see:
https://reactnative.dev/contributing/changelogs-in-pull-requests

Pull Request resolved: #39284

Test Plan: `./gradlew :packages:react-native:ReactAndroid:test` must pass

Reviewed By: javache

Differential Revision: D48960815

Pulled By: rshest

fbshipit-source-id: d66ab64373e300c5fff6fa2013faac473890804c
  • Loading branch information
IzuEneh authored and facebook-github-bot committed Sep 6, 2023
1 parent 1e2af65 commit 8973978
Show file tree
Hide file tree
Showing 2 changed files with 105 additions and 118 deletions.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
/*
* 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.uimanager

import android.view.View
import com.facebook.react.uimanager.annotations.ReactProp
import com.facebook.react.uimanager.annotations.ReactPropGroup
import org.junit.Ignore
import org.junit.Test
import org.junit.runner.RunWith
import org.robolectric.RobolectricTestRunner

/**
* Test that verifies that spec of methods annotated with @ReactProp in {@link ReactShadowNode} is
* correct
*/
@RunWith(RobolectricTestRunner::class)
@Ignore
class ReactPropForShadowNodeSpecTest {
@Test(expected = RuntimeException::class)
fun testMethodWithWrongNumberOfParams() {
BaseViewManager(
object : ReactShadowNodeImpl() {
@ReactProp(name = "prop")
fun setterWithIncorrectNumberOfArgs(value: Boolean, anotherValue: Int) {}
}
.javaClass)
.nativeProps
}

@Test(expected = RuntimeException::class)
fun testMethodWithTooFewParams() {
BaseViewManager(
object : ReactShadowNodeImpl() {
@ReactProp(name = "prop") fun setterWithNoArgs() {}
}
.javaClass)
.nativeProps
}

@Test(expected = RuntimeException::class)
fun testUnsupportedValueType() {
BaseViewManager(
object : ReactShadowNodeImpl() {
@ReactProp(name = "prop") fun setterWithMap(value: Map<*, *>) {}
}
.javaClass)
.nativeProps
}

@Test(expected = RuntimeException::class)
fun testGroupInvalidNumberOfParams() {
BaseViewManager(
object : ReactShadowNodeImpl() {
@ReactPropGroup(names = ["prop1", "prop2"])
fun setterWithTooManyParams(index: Int, value: Float, boolean: Boolean) {}
}
.javaClass)
.nativeProps
}

@Test(expected = RuntimeException::class)
fun testGroupTooFewParams() {
BaseViewManager(
object : ReactShadowNodeImpl() {
@ReactPropGroup(names = ["props1", "prop2"])
fun setterWithTooFewParams(index: Int) {}
}
.javaClass)
.nativeProps
}

@Test(expected = RuntimeException::class)
fun testGroupNoIndexParam() {
BaseViewManager(
object : ReactShadowNodeImpl() {
@ReactPropGroup(names = ["prop1", "prop2"])
fun setterWithNoIndexParam(value: Float, boolean: Boolean) {}
}
.javaClass)
.nativeProps
}

companion object {
private class BaseViewManager(
private val shadowNodeClass: Class<out ReactShadowNode<ReactShadowNodeImpl>>
) : ViewManager<View, ReactShadowNode<*>>() {
override fun getName(): String = "IgnoredName"

override fun createShadowNodeInstance(): ReactShadowNode<*>? = null

override fun getShadowNodeClass(): Class<out ReactShadowNode<ReactShadowNodeImpl>> =
shadowNodeClass

override fun createViewInstance(reactContext: ThemedReactContext): View = View(null)

override fun updateExtraData(root: View, extraData: Any?) {}
}
}
}

0 comments on commit 8973978

Please sign in to comment.