Questions tagged [private-methods]
The private-methods tag has no usage guidance.
272
questions
0
votes
1
answer
27
views
Flutter private methods function
How to change it to private method? I dont know how
@override
void initState() {
super.initState();
_initPackageInfo();
}
Future<void> _initPackageInfo() async {
final info = ...
0
votes
0
answers
132
views
How do you access a private static method from a public static method of the same class? [duplicate]
My JavaScript method overloading implementation below can't access my private static method in line 10. It seems the # symbol cannot be embedded into a string.
JavaScript Code
1 'use strict';
2
3 ...
0
votes
2
answers
50
views
Ruby: Can not read an attribute by self.attr
I am learning Ruby basic, and trying to do some tests. I encounter an issue to understand the class method accesss scope.
Here is my code.
class User
attr_accessor :name
def initialize(name)
...
0
votes
0
answers
202
views
How do I test private class methods with Jest?
I have a class with private methods:
class MyClass {
#myMethod () {}
}
Is it possible to test it with Jest?
0
votes
1
answer
112
views
Uncalled private method in an interface
I have an interface with a default method and a private method, where the private method is called from the default method.
When running Spotbugs, it issues an error that the private method is never ...
1
vote
1
answer
99
views
Why can you call a private method on a new instance made inside a method of the same class type, in PHP? [duplicate]
Why can you call a private method on a new instance made inside a public method of the same class type?
class Foo
{
private function thePrivateMethod()
{
echo 'can not be called ...
0
votes
1
answer
31
views
(NoMethodError) Undefined private method in model - Rails
I'm building a simple ecommerce webpage and the functionality I want to create is:
User clicks an "ADD TO CART" button in one of the products --> the ORDER is created with the user_id --&...
0
votes
1
answer
82
views
Obj C codebase and unit test cases in Swift
I have an objective c code base and I am writing snapshot test cases in swift. I have certain functions and variable which are declared in .m class. How I can access those variables from swift test ...
0
votes
0
answers
227
views
SONAR Code coverage not getting reflected for private methods
@RunWith(PowerMockRunner.class)
@PrepareForTest(PowerClassA.class)
public class PowerClassATest {
@Spy
@InjectMocks
private PowerClassA subject = new PowerClassA();
@Test
public void when() {
//...
0
votes
1
answer
627
views
ES6 Private Methods with access to "this" keyword JavaScript idioms
I'm learning JavaScript and NodeJS as I go for a work project and have been making heavy use of ES6 classes over ProtoTypes. I would like to use private methods or something like private methods, but ...
0
votes
1
answer
63
views
How can i get a Value of Variable from a private Method in C# Window Form Application
I'm trying to Get a Value From the variable I Diclear in a private Method and I want to use that value in another private method
First I want to add a picture in the Picture box I create this Button ...
1
vote
0
answers
33
views
is there a way i can use methods whose name start with underscore in python
Refer code for datetime python module
"""Concrete date/time and related types.
See http://www.iana.org/time-zones/repository/tz-link.html for
time zone and DST data sources.
""...
0
votes
2
answers
53
views
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 ...
2
votes
1
answer
514
views
Dart: testing private methods by accessing mock's property
I'm trying to get a mocked object property. During the initialization, 'child' class is getting a reference to a parent's private function. I'd like to catch this reference during testing to check ...
0
votes
1
answer
52
views
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 ...
1
vote
1
answer
101
views
What is the best way to access the outer <this> from the inner nested constructor's prototype in JS classes?
Can we still not use a more elegant way than an archaic variable like that to access the outer this with nested classes and especially when private class fields are involved?
A simplified example to ...
0
votes
1
answer
110
views
Invoke private method using Apache MethodUtils
I am trying to invoke a private method in my unit test to initialize a value. I know I can use java reflections to invoke private methods, but I am wondering if I can use Apache MethodUtils to invoke ...
1
vote
1
answer
34
views
Should stdlib classes with emplace-mechanisms be friendable?
I am wondering if this an stdlib bug, an oversight, my own error or intended by the standards committee.
If a type T's constructor (any of its constructors) is non-public, an unrelated container ...
3
votes
3
answers
1k
views
How to distribute an app for internal use only amongst employees
The company I work for is coming near to completion of app for internal use only amongst employees. There are some things that from my research I am not clear on and would like to hear from people who ...
-1
votes
2
answers
49
views
Accessing public methods in private inner classes
I have the following code, I wanted to know how to access the public method:locationFinder in the private inner class:LocationBasedFormatter of the outer class:LocationFormatter.
Basically I would ...
0
votes
1
answer
223
views
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.
<?php
class Account
{
private $...
2
votes
1
answer
349
views
How to add method and intercept private fields from a different class
I am trying to introduce a Shape class as a parent interface for the classes Circle and Rectangle. I have to implement getName() method that will return Circle for the Circle object and Rectangle for ...
-1
votes
1
answer
54
views
Change the behavior of a function in closure
I have to upgrade a small private function in a 1500 LoC JS module, written in The Revealing Module Pattern.
Simplified task looks like this:
var module = module || function (){
function init(){
...
1
vote
2
answers
109
views
Can I temporarily make all Ruby methods public?
I'm reproducing a bug in my Rails console. I'm interested in what some methods return, but some of them turn out to be private, so in my console I have to write:
> my_object.my_method
...
0
votes
2
answers
374
views
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 ...
0
votes
1
answer
201
views
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 ...
-1
votes
1
answer
71
views
Should private function members be exception safe?
When writing exception-safe code, should all private member functions guarantee at least basic exception safety? What would be best/good practice in this situation? Alternatives?
For example, say I ...
0
votes
1
answer
494
views
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): ...
1
vote
1
answer
1k
views
How to ignore or fix error TS2341: Property 'myFunction' is private and only accessible within class 'MyClass' with Jest 24 and Angular 8
I'm using Jest 24 with my Angular 8 app.
When a try to test a private function on a component, a TS2341 error is thrown.
Something like :
error TS2341: Property 'myFunction' is private and only ...
1
vote
1
answer
122
views
How to get acornjs to properly style check private class fields and methods?
I'm working on a project where I need to use a style check for my code. I want to use acorn js, however it fails when trying to parse private class fields and class methods.
I've tried:
const { ...
0
votes
1
answer
188
views
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 ...
0
votes
1
answer
105
views
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(...
1
vote
2
answers
56
views
Unit tests, private methods and hidden abstraction
I was reading about unit tests, to learn a bit more about that.
It seems that tests private methods shouldn't be the general rule, only some exceptions. I have find this article, in which explains ...
11
votes
2
answers
6k
views
How to configure eslint for ES6 class with private methods correctly?
I was writing ES6 class with private properties/methods in vue project. And using eslint to lint the code. Below is the example class:
class TestClass {
constructor(value) {
this.#...
1
vote
2
answers
5k
views
How to call private functions of a class from outside the class in Kotlin
I want to call a private functions of class SomeClass from outside of this class:
class SomeClass {
private fun somePrivateFunction() {
//...
}
private fun ...
6
votes
5
answers
23k
views
How to define private methods in a JS Class
I'm trying to define a private method for a class to test that such a method can't be called from outside the class. However, I'm coming across an error even when I'm using the syntax as indicated in ...
2
votes
2
answers
1k
views
Unit Testing Private Methods in Unity Test Runner
I'd like to do a unit test for my private methods in C#. Since the methods are private, they are not accessible from the test environment.
0
votes
1
answer
112
views
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 ...
1
vote
0
answers
679
views
Websocket with kraken closes after sending subscription for open position
I am trying to subscribe to the kraken websocket API for the OpenPositions. I have sent a challenge request and receive the challenge , i also have signed it correctly with my secret key but it seems ...
1
vote
0
answers
121
views
Unit testing a private callback factory
I am trying to create unit tests for a private callback factory with an alarm manager class. I don't want to test the private method directly as I think this contravenes TDD good practice but I ...
3
votes
1
answer
183
views
How to get private methods working in TypeScript?
I have some code that looks roughly like:
class A {
#hidden = 0;
method() {
return this.#hidden;
}
}
This works fine when I use JS, but when I convert it to TS I get the error Parsing ...
4
votes
1
answer
295
views
Why can child override and access its parent private method?
I'm used to put method as protected in my PHP classes. But playing with private I'm starting to have doubts.
I know that it might be a duplicate but I can't find clarity from the SO-answers I've ...
1
vote
1
answer
77
views
Should private methods check if object is properly initialized
Should the private methods of a class check if the object is properly initialized even if it's already done by the public methods?
I have an class/object that represents real hardware. What the ...
0
votes
2
answers
320
views
How to make an inherited method private in extended class
I want to make an inherited method private outside of the extended class in Typescript
Let's say I have two classes like this:
class BaseClass{
constructor(){}
sayHello(){
console....
0
votes
3
answers
1k
views
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 ...
1
vote
1
answer
739
views
access private class method from trait in PHP
I want to call a private class method from trait. If I do $this->privateMethod(); the call is made.
Since I want to only call that method if exists, I've implemented a isCallable() function; but ...
0
votes
2
answers
579
views
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 ...
2
votes
2
answers
117
views
How to avoid overtesting of a private method's behavior?
Given that:
Testing private methods is not a good practice.
An interface with many public methods is not a good practice either.
Suppose I have the following code:
module RedisHelper
private
...
0
votes
2
answers
799
views
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.
...
0
votes
2
answers
49
views
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 }...