How do I declare field variable of tested class using apache velocity?

195 views Asked by At

I'm trying to setup intellij idea code template for JUnit4 Test Class so that when I create the test it will also generate a field variable in the test. Example :

public class FooTest {
    private Foo foo;
    ...
}

The problem I'm having is using the $CLASS_NAME variable to set the field name with lower camel case.

1

There are 1 answers

1
Bajal On BEST ANSWER

You can do a toLowerCase() of first character. Sample below for reference.

import static org.junit.Assert.*;
#parse("File Header.java")
public class ${NAME} {
  ${BODY}
  #set($var_name = ${NAME})
  #set($var_name = $var_name.substring(0,1).toLowerCase() + $var_name.substring(1))

  private ${CLASS_NAME} $var_name;
}