Java Magazine, Mar/Apr 2018
ORACLE COM JAVAMAGAZINE MARCH APRIL 2018 70 jvm languages @ CompileStatic trait ControllerUnitTest T implements ParameterizedGrailsUnitTest T GrailsWebUnitTest static String FORM_ CONTENT_ TYPE MimeType FORM name static String XML_ CONTENT_ TYPE MimeType XML name static String JSON_ CONTENT_ TYPE MimeType JSON name static String HAL_ JSON_ CONTENT_ TYPE MimeType HAL_ JSON name static String HAL_ XML_ CONTENT_ TYPE MimeType HAL_ XML name other constants private T _ proxyInstance instance attribute It then has various methods such as @ CompileStatic TypeCheckingMode SKIP Map getModel request getAttribute GrailsApplicationAttributes CONTROLLER modelAndView model Note the use of the @ CompileStatic AST transformation which triggers the corresponding AST transformation and uses compile time checks in the style of Java to perform static compilation thus bypassing the Groovy meta object protocol The getModel method uses Groovys safe navigation operator and the so called Elvis operator Other methods in the trait let you retrieve the view the controller and more By using traits the test class includes many powerful capabilities at compile time In Groovy 30 default methods in Java interfaces are implemented using traits
You must have JavaScript enabled to view digital editions.