Skip to content

Commit

Permalink
build: junit 5
Browse files Browse the repository at this point in the history
- migrate tests to use junit 5 platform
  • Loading branch information
edgar-espina-wpp committed Mar 3, 2024
1 parent 5ba0ea0 commit b7b999a
Show file tree
Hide file tree
Showing 271 changed files with 1,220 additions and 1,286 deletions.
9 changes: 0 additions & 9 deletions .travis.yml

This file was deleted.

4 changes: 2 additions & 2 deletions handlebars-caffeine/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,8 @@
</dependency>

<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-engine</artifactId>
<scope>test</scope>
</dependency>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
*/
package com.github.jknack.handlebars.cache;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.fail;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.fail;
import static org.mockito.ArgumentMatchers.eq;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.verify;
Expand All @@ -15,7 +15,7 @@
import java.io.IOException;
import java.util.function.Function;

import org.junit.Test;
import org.junit.jupiter.api.Test;
import org.mockito.ArgumentCaptor;

import com.github.benmanes.caffeine.cache.Cache;
Expand Down
4 changes: 2 additions & 2 deletions handlebars-guava-cache/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,8 @@
</dependency>

<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-engine</artifactId>
<scope>test</scope>
</dependency>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
*/
package com.github.jknack.handlebars.cache;

import static org.junit.Assert.assertEquals;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.eq;
import static org.mockito.ArgumentMatchers.same;
Expand All @@ -17,7 +17,8 @@
import java.util.concurrent.Callable;
import java.util.concurrent.ExecutionException;

import org.junit.Test;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;

import com.github.jknack.handlebars.HandlebarsException;
import com.github.jknack.handlebars.Parser;
Expand Down Expand Up @@ -108,50 +109,63 @@ public void clear() throws IOException {
}

@SuppressWarnings("unchecked")
@Test(expected = IllegalStateException.class)
@Test
public void executionExceptionWithRuntimeException() throws IOException, ExecutionException {
TemplateSource source = mock(TemplateSource.class);
Assertions.assertThrows(
IllegalStateException.class,
() -> {
TemplateSource source = mock(TemplateSource.class);

Parser parser = mock(Parser.class);
Parser parser = mock(Parser.class);

Cache<TemplateSource, Template> cache = mock(Cache.class);
when(cache.get(eq(source), any(Callable.class)))
.thenThrow(new ExecutionException(new IllegalStateException()));
Cache<TemplateSource, Template> cache = mock(Cache.class);
when(cache.get(eq(source), any(Callable.class)))
.thenThrow(new ExecutionException(new IllegalStateException()));

new GuavaTemplateCache(cache).get(source, parser);
new GuavaTemplateCache(cache).get(source, parser);

verify(cache).get(eq(source), any(Callable.class));
verify(cache).get(eq(source), any(Callable.class));
});
}

@SuppressWarnings("unchecked")
@Test(expected = Error.class)
@Test
public void executionExceptionWithError() throws IOException, ExecutionException {
TemplateSource source = mock(TemplateSource.class);
Assertions.assertThrows(
Error.class,
() -> {
TemplateSource source = mock(TemplateSource.class);

Parser parser = mock(Parser.class);
Parser parser = mock(Parser.class);

Cache<TemplateSource, Template> cache = mock(Cache.class);
when(cache.get(eq(source), any(Callable.class))).thenThrow(new ExecutionException(new Error()));
Cache<TemplateSource, Template> cache = mock(Cache.class);
when(cache.get(eq(source), any(Callable.class)))
.thenThrow(new ExecutionException(new Error()));

new GuavaTemplateCache(cache).get(source, parser);
new GuavaTemplateCache(cache).get(source, parser);

verify(cache).get(eq(source), any(Callable.class));
verify(cache).get(eq(source), any(Callable.class));
});
}

@SuppressWarnings("unchecked")
@Test(expected = HandlebarsException.class)
@Test
public void executionExceptionWithCheckedException() throws IOException, ExecutionException {
TemplateSource source = mock(TemplateSource.class);
Assertions.assertThrows(
HandlebarsException.class,
() -> {
TemplateSource source = mock(TemplateSource.class);

Parser parser = mock(Parser.class);
Parser parser = mock(Parser.class);

Cache<TemplateSource, Template> cache = mock(Cache.class);
when(cache.get(eq(source), any(Callable.class)))
.thenThrow(new ExecutionException(new IOException()));
Cache<TemplateSource, Template> cache = mock(Cache.class);
when(cache.get(eq(source), any(Callable.class)))
.thenThrow(new ExecutionException(new IOException()));

new GuavaTemplateCache(cache).get(source, parser);
new GuavaTemplateCache(cache).get(source, parser);

verify(cache).get(eq(source), any(Callable.class));
verify(cache).get(eq(source), any(Callable.class));
});
}

private TemplateSource source(final String filename) throws IOException {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

import java.io.IOException;

import org.junit.Test;
import org.junit.jupiter.api.Test;

import com.github.jknack.handlebars.AbstractTest;
import com.google.common.collect.ImmutableList;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,12 @@
package com.github.jknack.handlebars.io;

import static java.lang.System.out;
import static org.junit.Assert.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertNotNull;

import java.io.File;
import java.util.concurrent.TimeUnit;

import org.junit.Test;
import org.junit.jupiter.api.Test;

import com.google.common.base.Stopwatch;

Expand Down
4 changes: 2 additions & 2 deletions handlebars-helpers/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,8 @@
</dependency>

<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-engine</artifactId>
<scope>test</scope>
</dependency>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@
*/
package com.github.jknack.handlebars.helper;

import static org.junit.Assert.assertEquals;
import static org.junit.jupiter.api.Assertions.assertEquals;

import java.io.IOException;

import org.junit.Test;
import org.junit.jupiter.api.Test;

import com.github.jknack.handlebars.AbstractTest;
import com.github.jknack.handlebars.Context;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

import java.io.IOException;

import org.junit.Test;
import org.junit.jupiter.api.Test;

import com.github.jknack.handlebars.AbstractTest;
import com.github.jknack.handlebars.Handlebars;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,14 @@
*/
package com.github.jknack.handlebars.helper;

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.fail;

import java.io.IOException;

import org.joda.time.DateTime;
import org.joda.time.DateTimeZone;
import org.junit.Assert;
import org.junit.Test;
import org.junit.jupiter.api.Test;

import com.github.jknack.handlebars.AbstractTest;
import com.github.jknack.handlebars.Handlebars;
Expand Down Expand Up @@ -44,10 +46,10 @@ public void testBadPattern() throws IOException {
DateTime dateTime = new DateTime().withDate(1995, 7, 4).withTime(14, 32, 12, 0);
try {
shouldCompileTo("{{jodaPatternHelper this \"qwerty\"}}", dateTime, "1995-Jul-4 14:32:12");
Assert.fail("Exception should have thrown!");
fail("Exception should have thrown!");
} catch (HandlebarsException e) {
Throwable t = e.getCause();
Assert.assertEquals("Illegal pattern component: q", t.getMessage());
assertEquals("Illegal pattern component: q", t.getMessage());
}
}

Expand All @@ -69,7 +71,7 @@ public void testBadStyle() throws IOException {
shouldCompileTo("{{jodaStyleHelper this \"QS\"}}", dateTime, "");
} catch (HandlebarsException e) {
Throwable t = e.getCause();
Assert.assertEquals("Invalid style character: Q", t.getMessage());
assertEquals("Invalid style character: Q", t.getMessage());
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

import java.io.IOException;

import org.junit.Test;
import org.junit.jupiter.api.Test;

import com.github.jknack.handlebars.AbstractTest;
import com.github.jknack.handlebars.Handlebars;
Expand Down
11 changes: 9 additions & 2 deletions handlebars-jackson2/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,8 @@
</dependency>

<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-engine</artifactId>
<scope>test</scope>
</dependency>

Expand All @@ -59,6 +59,13 @@
<artifactId>mockito-core</artifactId>
<scope>test</scope>
</dependency>

<dependency>
<groupId>org.hamcrest</groupId>
<artifactId>hamcrest</artifactId>
<version>2.2</version>
<scope>test</scope>
</dependency>
</dependencies>

</project>
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

import java.io.IOException;

import org.junit.Test;
import org.junit.jupiter.api.Test;

import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

import java.io.IOException;

import org.junit.Test;
import org.junit.jupiter.api.Test;

import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

import java.io.IOException;

import org.junit.Test;
import org.junit.jupiter.api.Test;

import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@
import java.util.HashMap;
import java.util.Map;

import org.junit.Test;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;

import com.fasterxml.jackson.databind.MapperFeature;
import com.fasterxml.jackson.databind.ObjectMapper;
Expand Down Expand Up @@ -107,20 +108,24 @@ public void toJSONAliasViewExclusive() throws IOException {
equalsToStringIgnoringWindowsNewLine("{\"title\":\"First Post\"}"));
}

@Test(expected = HandlebarsException.class)
@Test
public void jsonViewNotFound() throws IOException {
Handlebars handlebars = new Handlebars();
Assertions.assertThrows(
HandlebarsException.class,
() -> {
Handlebars handlebars = new Handlebars();

ObjectMapper mapper = new ObjectMapper();
mapper.configure(MapperFeature.DEFAULT_VIEW_INCLUSION, false);
ObjectMapper mapper = new ObjectMapper();
mapper.configure(MapperFeature.DEFAULT_VIEW_INCLUSION, false);

handlebars.registerHelper("@json", new Jackson2Helper(mapper));
handlebars.registerHelper("@json", new Jackson2Helper(mapper));

Template template = handlebars.compileInline("{{@json this view=\"missing.ViewClass\"}}");
Template template = handlebars.compileInline("{{@json this view=\"missing.ViewClass\"}}");

assertThat(
template.apply(new Blog("First Post", "...")),
equalsToStringIgnoringWindowsNewLine("{\"title\":\"First Post\"}"));
assertThat(
template.apply(new Blog("First Post", "...")),
equalsToStringIgnoringWindowsNewLine("{\"title\":\"First Post\"}"));
});
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
*/
package com.github.jknack.handlebars;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
Expand All @@ -20,7 +20,7 @@
import java.util.Map.Entry;
import java.util.Set;

import org.junit.Test;
import org.junit.jupiter.api.Test;

import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
*/
package com.github.jknack.handlebars.i280;

import org.junit.Test;
import org.junit.jupiter.api.Test;

import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

import java.io.IOException;

import org.junit.Test;
import org.junit.jupiter.api.Test;

import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;
Expand Down
Loading

0 comments on commit b7b999a

Please sign in to comment.