vim to generate code template dynamically

Viewed 590

I have to write test cases which contains repetive code.

  1. The name of the method should be the ClassName delimitted with _ ex: class_name_test
  2. The object name should be classNameObj and the mock method should take ClassName.class
  3. The genericObj.call statement is common for all methods The sayHello should be bound to classNameObj and the remaining result is common
  4. The commonMethods is common for all objects

Instead of copy pasting and changing the ClassName and classNameObj, I am interested in automating this using Vim. Is is possible to do this to which if I pass the Class name, the rest should be generated?

The method template is mentioned below.

@Test
public void stop_video_request_valid_data() throws Throwable {
    ClassName classNameObj = mock(ClassName.class);
    when(genericObj.call()).thenReturn(new Object[]{classNameObj});
    when(classNameObj.sayHello()).thenReturn("Hello");
    commonMethods();
}
1 Answers
Related