Introduce Paramater Refactor

Issue #1594 duplicate
Justin Julicher created an issue

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)

  1. Scott Wells 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.

  2. Log in to comment