is there a way to get inside protected value and access it on kotlin unit test, below are my doPost protected method, i tried with reflection but its not working, following this sample https://stackoverflow.com/a/41695398/6377156
@Mock
internal lateinit var jobServlet:myHttpServlet
private val mockContext = mockk<Context>(relaxed = true)
private val mockHttpRequest = mockk<HttpServletRequest>(relaxed = true)
private val mockHttpResponse = mockk<HttpServletResponse>(relaxed = true)
class JobDescriptorServletsTest {
@Before
fun setup(){
mockkStatic(Context::class)
jobServlet = myHttpServlet(mockContext)
}
@Test
fun verify_Instance(){
assertNotNull(jobServlet)
}
@Test
fun doPostTest(){
val protectedMethod = myHttpServlet::class.java.getDeclaredMethod("doPost")
protectedMethod.isAccessible = true
protectedMethod.invoke(jobServlet.doPost(mockHttpRequest, mockHttpResponse))
}
}
You can use Kotlin's reflection instead of Java