Skip to main content

Posts

Showing posts from April, 2016

How to write the test cases for private methods?

How to write the test cases for private methods? Most of us struck while writing the test cases with the private methods and thinks about the how to write test cases for private methods. To test these methods some of the possible methods are shown below, The following are the methods for writing the test cases, 1. Test these methods using the public methods. The public method that access the private methods has to be tested. In this method the problem is that some times the scenario can be like we could not have a public method that returns some value. At that case even though we are able to invoke the private methods its waste to invoke as it cannot be tested properly. 2. Using the reflection concept to invoke the private methods. This works very well. I will show you an example here for your understanding of how to use the reflection in testing the private methods. Consider the private methods inside the target.class as shown below, class Target {        private

How to access the each view of item by position in Recycler View in android ?

How to access the each view of item by position in Recycler View in android ? There are some methods to access the view of each item view to change or update the view during the run time. To access the view of the item view , consider the Recycler view as below, RecyclerView mainRecyclerView = (RecyclerView)view.findViewById(R.id.main_recycler_view); RecyclerAdapter adapter = new RecyclerAdapter(mContext); mainRecyclerView.setAdapter(adapter); main.setLayoutManager(new LinearLayoutManager(mContext));  To access the itemView of each position the following functions can be used,  1. View itemView = mainRecyclerView.getChildAt(positionOfItem);  2. View itemView = mainRecyclerView.findViewHolderForAdapterPosition(Position).itemView;  3. View itemView = mainRecyclerView.findViewHolderForPosition(Position).itemView;  4. Long itemId = mainRecyclerView.getAdapter().getItemId(position);       View itemView = mainRecyclerView.findViewHolderForItemId(itemId);  5. View