Skip to content

Commit

Permalink
Migrate to junit5 (PebbleTemplates#490)
Browse files Browse the repository at this point in the history
  • Loading branch information
ebussieres authored Dec 4, 2019
1 parent 8db2ace commit 7ca9159
Show file tree
Hide file tree
Showing 61 changed files with 2,393 additions and 2,328 deletions.
4 changes: 4 additions & 0 deletions pebble-spring/pebble-spring4/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
<properties>
<servlet-api.version>3.0.1</servlet-api.version>
<spring-framework.version>4.3.25.RELEASE</spring-framework.version>
<junit.version>4.12</junit.version>
<mockito.version>2.3.5</mockito.version>
</properties>

<dependencyManagement>
Expand Down Expand Up @@ -55,11 +57,13 @@
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-core</artifactId>
<version>${mockito.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>${junit.version}</version>
<scope>test</scope>
</dependency>
</dependencies>
Expand Down
12 changes: 8 additions & 4 deletions pebble-spring/pebble-spring5/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
<properties>
<servlet-api.version>3.1.0</servlet-api.version>
<spring-framework.version>5.2.1.RELEASE</spring-framework.version>
<mockito-junit-jupiter.version>3.1.0</mockito-junit-jupiter.version>
<junit-jupiter.version>5.5.2</junit-jupiter.version>
</properties>

<dependencyManagement>
Expand Down Expand Up @@ -59,13 +61,15 @@
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-core</artifactId>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter</artifactId>
<version>${junit-jupiter.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<groupId>org.mockito</groupId>
<artifactId>mockito-junit-jupiter</artifactId>
<version>${mockito-junit-jupiter.version}</version>
<scope>test</scope>
</dependency>
</dependencies>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,14 @@

import com.mitchellbosecke.pebble.spring.config.MVCConfig;

import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.mock.web.MockHttpServletRequest;
import org.springframework.mock.web.MockHttpServletResponse;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import org.springframework.test.context.junit.jupiter.SpringExtension;
import org.springframework.test.context.web.WebAppConfiguration;
import org.springframework.validation.BindingResult;
import org.springframework.validation.FieldError;
Expand All @@ -33,7 +33,7 @@
import java.util.Locale;
import java.util.Map;

import static org.junit.Assert.assertEquals;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;

Expand All @@ -42,10 +42,10 @@
*
* @author Eric Bussieres
*/
@RunWith(SpringJUnit4ClassRunner.class)
@ExtendWith(SpringExtension.class)
@WebAppConfiguration
@ContextConfiguration(classes = {MVCConfig.class})
public class PebbleViewResolverTest {
@ContextConfiguration(classes = MVCConfig.class)
class PebbleViewResolverTest {

private static final String CONTEXT_PATH = "/testContextPath";
private static final Locale DEFAULT_LOCALE = Locale.CANADA;
Expand All @@ -59,16 +59,16 @@ public class PebbleViewResolverTest {
@Autowired
private ViewResolver viewResolver;

@Before
public void initRequest() {
@BeforeEach
void initRequest() {
this.mockRequest.setContextPath(CONTEXT_PATH);
this.mockRequest.getSession().setMaxInactiveInterval(600);

RequestContextHolder.setRequestAttributes(new ServletRequestAttributes(this.mockRequest));
}

@Before
public void initBindingResult() {
@BeforeEach
void initBindingResult() {
this.initBindingResultAllErrors();
this.initBindingResultGlobalErrors();
this.initBindingResultFieldErrors();
Expand Down Expand Up @@ -103,14 +103,14 @@ private void initBindingResultFieldErrors() {
}

@Test
public void whenRenderingAPage_givenPageWithBeanVariable_thenRenderingIsOK() throws Exception {
void whenRenderingAPage_givenPageWithBeanVariable_thenRenderingIsOK() throws Exception {
String result = this.render("beansTest", new HashMap<String, Object>());

this.assertOutput(result, EXPECTED_RESPONSE_PATH + "/beansTest.html");
}

@Test
public void whenRenderingAPage_givenPageWithBindingResult_thenRenderingIsOK() throws Exception {
void whenRenderingAPage_givenPageWithBindingResult_thenRenderingIsOK() throws Exception {
Map<String, Object> model = this.givenBindingResult();

String result = this.render("bindingResultTest", model);
Expand All @@ -125,7 +125,7 @@ private Map<String, Object> givenBindingResult() {
}

@Test
public void whenRenderingAPage_givenPageWithBindingResultAndMacro_thenRenderingIsOK() throws Exception {
void whenRenderingAPage_givenPageWithBindingResultAndMacro_thenRenderingIsOK() throws Exception {
Map<String, Object> model = this.givenBindingResult();

String result = this.render("bindingResultWithMacroTest", model);
Expand All @@ -134,22 +134,22 @@ public void whenRenderingAPage_givenPageWithBindingResultAndMacro_thenRenderingI
}

@Test
public void whenRenderingAPage_givenPageWithHrefFunction_thenRenderingIsOK() throws Exception {
void whenRenderingAPage_givenPageWithHrefFunction_thenRenderingIsOK() throws Exception {
String result = this.render("hrefFunctionTest", new HashMap<String, Object>());

this.assertOutput(result, EXPECTED_RESPONSE_PATH + "/hrefFunctionTest.html");
}

@Test
public void whenRenderingAPageInEnglish_givenPageWithResourceBundleMessage_thenRenderingIsOK()
void whenRenderingAPageInEnglish_givenPageWithResourceBundleMessage_thenRenderingIsOK()
throws Exception {
String result = this.render("messageEnTest", new HashMap<String, Object>());

this.assertOutput(result, EXPECTED_RESPONSE_PATH + "/messageEnTest.html");
}

@Test
public void whenRenderingAPageInFrench_givenPageWithResourceBundleMessage_thenRenderingIsOK()
void whenRenderingAPageInFrench_givenPageWithResourceBundleMessage_thenRenderingIsOK()
throws Exception {
this.mockRequest.addPreferredLocale(Locale.CANADA_FRENCH);

Expand All @@ -159,23 +159,23 @@ public void whenRenderingAPageInFrench_givenPageWithResourceBundleMessage_thenRe
}

@Test
public void whenRenderingAPage_givenPageWithHttpRequestVariable_thenRenderingIsOK()
void whenRenderingAPage_givenPageWithHttpRequestVariable_thenRenderingIsOK()
throws Exception {
String result = this.render("requestTest", new HashMap<String, Object>());

this.assertOutput(result, EXPECTED_RESPONSE_PATH + "/requestTest.html");
}

@Test
public void whenRenderingAPage_givenPageWithHttpResponseVariable_thenRenderingIsOK()
void whenRenderingAPage_givenPageWithHttpResponseVariable_thenRenderingIsOK()
throws Exception {
String result = this.render("responseTest", new HashMap<String, Object>());

this.assertOutput(result, EXPECTED_RESPONSE_PATH + "/responseTest.html");
}

@Test
public void whenRenderingAPage_givenPageWithHttpSessionVariable_thenRenderingIsOK()
void whenRenderingAPage_givenPageWithHttpSessionVariable_thenRenderingIsOK()
throws Exception {
String result = this.render("sessionTest", new HashMap<String, Object>());

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
*
* @author Eric Bussieres
*/
@Configuration
@Configuration(proxyBeanMethods = false)
public class MVCConfig {

@Bean
Expand All @@ -41,9 +41,10 @@ public MessageSource messageSource() {
}

@Bean
public PebbleEngine pebbleEngine(SpringExtension springExtension) {
public PebbleEngine pebbleEngine(SpringExtension springExtension,
Loader<?> templateLoader) {
return new PebbleEngine.Builder()
.loader(this.templateLoader())
.loader(templateLoader)
.strictVariables(false)
.extension(springExtension)
.build();
Expand Down
17 changes: 0 additions & 17 deletions pebble-spring/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -21,30 +21,13 @@
<description>Pebble Spring Project</description>
<url>http://pebbletemplates.io</url>

<properties>
<junit.version>4.12</junit.version>
<mockito.version>2.3.5</mockito.version>
</properties>

<dependencyManagement>
<dependencies>
<dependency>
<groupId>io.pebbletemplates</groupId>
<artifactId>pebble</artifactId>
<version>${project.version}</version>
</dependency>

<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-core</artifactId>
<version>${mockito.version}</version>
</dependency>

<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>${junit.version}</version>
</dependency>
</dependencies>
</dependencyManagement>
</project>
Expand Down
59 changes: 34 additions & 25 deletions pebble/pom.xml
Original file line number Diff line number Diff line change
@@ -1,74 +1,83 @@
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<parent>
<groupId>io.pebbletemplates</groupId>
<artifactId>pebble-project</artifactId>
<version>3.1.2-SNAPSHOT</version>
</parent>

<artifactId>pebble</artifactId>
<packaging>jar</packaging>

<packaging>jar</packaging>
<name>Pebble</name>

<description>Templating engine for Java.</description>
<url>http://pebbletemplates.io</url>

<properties>
<unbescape.version>1.1.6.RELEASE</unbescape.version>
<slf4j.version>1.7.25</slf4j.version>
<caffeine.version>2.6.2</caffeine.version>
<servlet-api.version>2.5</servlet-api.version>

<assertj.version>3.13.2</assertj.version>
<commons-io.version>2.6</commons-io.version>
<logback-classic.version>1.2.3</logback-classic.version>
<junit-jupiter.version>5.5.2</junit-jupiter.version>
</properties>

<dependencies>
<!-- required dependencies -->
<dependency>
<groupId>org.unbescape</groupId>
<artifactId>unbescape</artifactId>
<version>1.1.6.RELEASE</version>
<version>${unbescape.version}</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<version>1.7.25</version>
<version>${slf4j.version}</version>
</dependency>

<!-- optional dependencies -->
<dependency>
<groupId>com.github.ben-manes.caffeine</groupId>
<artifactId>caffeine</artifactId>
<version>2.6.2</version>
<version>${caffeine.version}</version>
<optional>true</optional>
</dependency>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>servlet-api</artifactId>
<version>2.5</version>
<version>${servlet-api.version}</version>
<optional>true</optional>
</dependency>

<!-- testing dependencies -->
<dependency>
<groupId>ch.qos.logback</groupId>
<artifactId>logback-classic</artifactId>
<version>1.2.3</version>
<version>${logback-classic.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter</artifactId>
<version>${junit-jupiter.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.assertj</groupId>
<artifactId>assertj-core</artifactId>
<version>${assertj.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.12</version>
<groupId>commons-io</groupId>
<artifactId>commons-io</artifactId>
<version>${commons-io.version}</version>
<scope>test</scope>
</dependency>
<!-- https://mvnrepository.com/artifact/org.assertj/assertj-core -->
<dependency>
<groupId>org.assertj</groupId>
<artifactId>assertj-core</artifactId>
<version>3.13.2</version>
<scope>test</scope>
</dependency>
<!-- https://mvnrepository.com/artifact/commons-io/commons-io -->
<!-- Used for loading template files and expected result files for template tests -->
<dependency>
<groupId>commons-io</groupId>
<artifactId>commons-io</artifactId>
<version>2.6</version>
<scope>test</scope>
</dependency>
</dependencies>

<build>
Expand Down
Loading

0 comments on commit 7ca9159

Please sign in to comment.