Questions tagged [private-methods]

285 questions
0
votes
2 answers

Is this Dynamic polymorphism or not?

The output of the program is A isn't it suppose to be B. If I change the modifier of method in Class A to public then the output is B. Can somebody explain what is going on here? Code: public class HelloWorld { public static void main(String[]…
0
votes
1 answer

Accessing a variable in a private method from another private method. C#

I have a private method named RentingOrBuying(); that gathers information about the property price and interest rate. I want to create another private method that calculates the monthly home loan repayment but I need the information in…
JazzaWild
  • 13
  • 3
0
votes
1 answer

Cannot set private variable through constructor php

I am trying to set private properties of Account class using _construct method. I tried using this-> keyword but it gives me the same error. Here is my code.
0
votes
2 answers

How to access private member of impl class from original class using PIMPL approach

I am using the PIMPL approach and would like to access a private member of the implementation class from the regular class. Is there any legitimate way to do this? In the below code, there are two private members I would like to access. One of these…
didjek
  • 393
  • 5
  • 16
0
votes
1 answer

Can we mock private method with multiple arguments using PowerMockito?

Team, I want to moclbelow method using Powermock private void methodToMock(int param1,String param2,int param3) { } I tried below which is not working SampleClass spyObject = PowerMockito.spy(new…
anuja
  • 1
0
votes
1 answer

Testing a private method with access modifier in Scalatest

I have the following issue. Suppose I have the following class (example from here: Link ): package com.example.people class Person(val age: Int) object Person { private def transform(p: Person): Person = new Person(p.age + 1) } So I have a…
finite_diffidence
  • 893
  • 2
  • 11
  • 20
0
votes
1 answer

Issues with JustMock and Large Test Runs

Ok so I have an issue with JustMock that I am hoping that someone here can help me with. I have a class with several test methods(something like 80). Each of these methods when run independently will pass with flying colors. However I have some…
Chris
  • 21
  • 7
0
votes
1 answer

Issue in writing junit test case for NullPointerException for private methods

The function template is private static void processTextFile(String iFile, String tmpDirLoc, String tmpDrive, String iMode) I want to test for NullPointerException in case when iFile is null. Since the original method processTextFile is Private in…
0
votes
1 answer

Mock a return value for a private method that has been marked as accessible

My unit test: @Test public void testDoSomething() { Method m = MyClass.class.getDeclaredMethod("methodToBeMocked"); m.setAccessible(true); MyClass myClass = spy(new MyClass()); //m.invoke(myClass); // Calling this invokes the private method…
bobbyrne01
  • 6,295
  • 19
  • 80
  • 150
0
votes
1 answer

Private method invoking from outside the class in Java

I have one class with private method now i want to access that private method outside the class, which is possible using reflection package in java. But what if we make class constructor as private, then how to access that method. In below code…
0
votes
3 answers

private method call another private method, doing correct?

I am designing an OOP application, it's my first application. I have class (similar to one mentioned below) class Temp { private function a() { } private function b() { // To call method 'a',…
I-M-JM
  • 15,732
  • 26
  • 77
  • 103
0
votes
3 answers

Is there a way to test private methods?

I have a React component 'A'. One method 'foo' inside it is passed as a prop to component 'B'. foo is triggered on click of component B. Question - How to test this foo method? I can circumvent this problem by making the method foo as public and…
0
votes
2 answers

Private method defined in `Sub` and `Super`, both methods can be invoked on Object of Sub , then why private method said not being inherited?

As per Oracle Tutorials A subclass does not inherit the private members of its parent class. However, if the superclass has public or protected methods for accessing its private fields, these can also be used by the subclass. [Question] For a…
nits.kk
  • 5,204
  • 4
  • 33
  • 55
0
votes
2 answers

How to mock a private method for different results in the flow of code

I have a private method in my java code which needs to be invoked twice. I am writing junits using Powermock. While mocking the said method I need two different results for two different invokations. //I have…
0
votes
2 answers

Reflection of data

How do I get any object and its private field read and then returned public class Person { private string _password; } public string Name { get; set } public Gender man { get; set } public int Age { get; set } } Here is the…
jayy91
  • 11
  • 3