Questions tagged [private-methods]
285 questions
2
votes
2 answers
PowerMockito execption for doNothing for a private method
I have a class which has two private methods I am writing JUnit for one method test() and want the other method test1 to do nothing. It's like this..the method I want to call is test() and i want when it is called the test1() which is called it does…

Rahul Goswami
- 29
- 3
2
votes
5 answers
Is there a way to call private functions of a form or class through Type.InvokeMember or messages in C#?
What I have is a bunch of forms in my main application that have both private and public functions. I have a plugin architecture in place that accesses each form when it is created and loaded and holds a reference to it for updating it, adding…

Mike Webb
- 8,855
- 18
- 78
- 111
2
votes
2 answers
How to stay DRY using private methods?
I'm on Rails 5.0.
Creating new controllers and adding more and more code there I've discovered that I have quite a lot of identical methods in private sections of each class like
private
def find_post
@post = Posts.find(params[:id])
end
def…

Alexander Gorg
- 1,049
- 16
- 32
2
votes
1 answer
How to unit test a public method that calls private method and that in turn calls a web service method
Here's the setup:
public class ClassToTest{
public void doSomething(ObjectToWorkOn[] objects){
doPrivateStuff(objects);
}
private void doPrivateStuff(ObjectToWorkOn[] objects){
List validObjects=new…

Mikayil Abdullayev
- 12,117
- 26
- 122
- 206
2
votes
1 answer
How to verify number of call of private method in public method in Junit?
public void publicMethod() {
for (i=1;i<10;i++)
privateMethod();
}
private privateMethod() {
something...
}
I need to write a JUnit testcase to verify the number of times the privateMethod() is called.

Avi
- 29
- 2
2
votes
1 answer
How can I call a inner function from the Python shell?
I have some code (that I can't easily modify), of the following form:
def foo(x):
do_other_stuff_that_I_do_not_want_to_do()
def bar():
"do something"
str(x)
bar()
I would like to call bar(), directly, from the Python shell. I…

JesseW
- 1,255
- 11
- 19
2
votes
2 answers
Instantiating a subclass python
Just a simple class definition withh subclasses to show inheritance
import datetime
class LibaryItem: #The base class definition
def __init__(self, t, a, i): # initialiser method
self.__Title = t
self.__Author_Artist =…

Christopher Moskovitz
- 47
- 1
- 6
2
votes
0 answers
when to use a private static method?
I know that you should make a public method static if you need to access it without creating an Object of that class.
But what is the use of a priavte static method since you are not able to access it outside of the class?

Harout Tatarian
- 431
- 4
- 14
2
votes
1 answer
Jmockit- mock Private Medhod to return complex object, and then use that for Expectations()
I have this situation that I need to test where re-factoring code is not possible (due to organizational reasons :( ).
class ClassToTest {
private ComplexObject createComplexObject() throws SomeException{
//create the complex object
…

Gaurav Upadhyay
- 23
- 1
- 3
2
votes
2 answers
Using a private method with Single Table Inheritance
I am working on a rails app where I have 2 different types of Users (MasterClientUser and AccountManager). I am using single table inheritance to differentiate the users. I have a update_last_seen_at private method that will need to be called on…

Steve_D
- 545
- 2
- 11
- 20
2
votes
2 answers
How to avoid accidental invocation on UIKit's private classes?
I have just encountered very weird problem. In my current project i am working with complex views and doing some modifications on the fly.
e.g. If view responds to setTextColor then was setting new color by using following code
if ([view…

kodeshpa
- 549
- 5
- 14
2
votes
2 answers
Whether to use private or public methods
As I continue to further enhance my hangman game in C# to help me learn the language and think like a programmer, there are methods in it that, I think, should be in separate classes. Right now, all the code is on the Form class (Windows Form). This…

flimflam57
- 1,334
- 4
- 16
- 31
2
votes
1 answer
Getting "public variable" in a "private method" using CoffeeScript
I have the following code:
class Example
@text = 'Hello world! ;)'
getText = ->
@text
constructor: ->
alert(getText())
### Instance ###
example = new Example
This will return 'undefined', Is there any way to make it return the…

Caio Tarifa
- 5,973
- 11
- 46
- 73
2
votes
1 answer
Partial Mock Private Method with PowerMock-Mockito
I am new to Mockito and PowerMock. I need to test some legacy code which has a private method I have to mock. I am considering using the private partial mocking feature from PowerMock, I tried to mimic the example from the link, but it failed. I…

wlhee
- 2,334
- 4
- 18
- 19
2
votes
1 answer
Check and Toggle Airplane Mode with Private APIs on iPhone
Does anyone know how to check and toggle Airplane mode using the Private APIs? (No, SCNetworkReachability is not good enough, and yes, I'm happy to use private APIs that will potentially break in the future.)

Russ McBride
- 51
- 3