Skip to content

Instantly share code, notes, and snippets.

@ufuk
Last active March 12, 2022 17:59
Show Gist options
  • Select an option

  • Save ufuk/47f12a6c054e7786c2c4 to your computer and use it in GitHub Desktop.

Select an option

Save ufuk/47f12a6c054e7786c2c4 to your computer and use it in GitHub Desktop.
IntelliJ Code Template for Service and DAO Tests
#set ($IS_SERVICE_TEST = ${NAME.endsWith("ServiceTest")})
#set ($IS_VIEW_TEST = ${NAME.endsWith("ViewTest")})
#set ($IS_CONTROLLER_TEST = ${NAME.endsWith("ControllerTest")})
#set ($IS_MOCK_TEST = ${IS_SERVICE_TEST} or ${IS_VIEW_TEST} or ${IS_CONTROLLER_TEST})
#set ($IS_DAO_TEST = ${NAME.endsWith("DaoTest")})
#set ($IS_MOCK_OR_DAO_TEST = ${IS_MOCK_TEST} or ${IS_DAO_TEST})
#set ($TESTING_CLASS_NAME = ${NAME.split("Test")[0]})
import org.junit.Test;
#if ($IS_MOCK_TEST)
import org.junit.runner.RunWith;
import org.mockito.InjectMocks;
import org.mockito.runners.MockitoJUnitRunner;
@RunWith(MockitoJUnitRunner.class)
#elseif (${IS_DAO_TEST})
import org.springframework.beans.factory.annotation.Autowired;#end
public class ${NAME} #if (${IS_DAO_TEST}) extends BaseIntegration#end {
#if ($IS_MOCK_TEST) @InjectMocks
#elseif (${IS_DAO_TEST}) @Autowired
#end
#if ($IS_MOCK_OR_DAO_TEST) private ${TESTING_CLASS_NAME} #end
#if ($IS_SERVICE_TEST) service;
#elseif (${IS_DAO_TEST}) dao;
#elseif (${IS_CONTROLLER_TEST}) controller;
#elseif (${IS_VIEW_TEST}) view;
#end
@Test
public void should() {
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment