- edited description
Introduce Paramater Refactor
Issue #1594
duplicate
Generally in writing tests you will create a method to quickly create objects e.g.
public static void testCode()
{
TestObject__c testObject = createTestObject('Test1');
}
public static TestObject__c createTestObject(String valueA)
{
return new TestObject(
Text_Field__c = valueA,
Text_Field2__c = 'Test2'
);
}
From memory in IntelliJ Idea java would allow you to introduce paramater for Text_Field2__c which would go to all the calling lines and add in the value to the calling parameter.
so the resulting code would be:
public static void testCode()
{
TestObject__c testObject = createTestObject('Test1', 'test2');
}
public static TestObject__c createTestObject(String valueA, String valueB)
{
return new TestObject(
Text_Field__c = valueA,
Text_Field2__c = valueB
);
}
For this refactor I would also recommend an option to override the method so you don’t introduce a variable so the resulting code would be:
public static void testCode()
{
TestObject__c testObject = createTestObject('Test1');
}
public static TestObject__c createTestObject(String valueA)
{
return createTestObject(String valueA, 'Test2');
}
public static TestObject__c createTestObject(String valueA, String valueB)
{
return new TestObject(
Text_Field__c = valueA,
Text_Field2__c = valueB,
);
}
thanks
Comments (4)
-
reporter -
repo owner - changed component to Refactoring
- removed version
- marked as enhancement
-
repo owner This is actually already in the works. After I did the work for change method signature, I started on it, but I shelved it for a bit to work on a few other things. I should be returning to it next week or the week after.
-
repo owner - changed status to duplicate
Duplicate of #1117.
- Log in to comment