Skip to content

Commit 73e9f11

Browse files
bithazardjknack
bithazard
authored andcommitted
WIP: upgrade Java 11 or higher
- Fix some locale specific issues on modern JVM - Add nashorn dependency - Replaced the mocking frameworks (easymock/powermock) with mockito which seems to have no problems with the Java 9 module system
1 parent 0021d5f commit 73e9f11

File tree

33 files changed

+601
-1097
lines changed

33 files changed

+601
-1097
lines changed

.github/workflows/build-matrix.yml

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
name: Build Matrix
1+
name: Build
22

33
on: [push]
44

@@ -8,7 +8,7 @@ jobs:
88
strategy:
99
fail-fast: false
1010
matrix:
11-
java_version: [1.8]
11+
java_version: [1.8, 11]
1212
os: [ubuntu-latest, windows-latest, macOS-latest]
1313

1414
steps:

.gitignore

+3-1
Original file line numberDiff line numberDiff line change
@@ -21,4 +21,6 @@ dependency-reduced-pom.xml
2121
*.versionsBackup
2222
pom.xml.versionsBackup
2323

24-
jacoco.exec
24+
jacoco.exec
25+
26+
out

handlebars-guava-cache/pom.xml

+2-3
Original file line numberDiff line numberDiff line change
@@ -57,11 +57,10 @@
5757
</dependency>
5858

5959
<dependency>
60-
<groupId>org.easymock</groupId>
61-
<artifactId>easymock</artifactId>
60+
<groupId>org.mockito</groupId>
61+
<artifactId>mockito-core</artifactId>
6262
<scope>test</scope>
6363
</dependency>
64-
6564
</dependencies>
6665

6766
</project>

handlebars-guava-cache/src/test/java/com/github/jknack/handlebars/cache/GuavaTemplateCacheTest.java

+35-52
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
package com.github.jknack.handlebars.cache;
22

3-
import static org.easymock.EasyMock.createMock;
4-
import static org.easymock.EasyMock.eq;
5-
import static org.easymock.EasyMock.expect;
6-
import static org.easymock.EasyMock.isA;
7-
import static org.easymock.EasyMock.replay;
8-
import static org.easymock.EasyMock.verify;
93
import static org.junit.Assert.assertEquals;
4+
import static org.mockito.ArgumentMatchers.any;
5+
import static org.mockito.ArgumentMatchers.eq;
6+
import static org.mockito.ArgumentMatchers.same;
7+
import static org.mockito.Mockito.mock;
8+
import static org.mockito.Mockito.verify;
9+
import static org.mockito.Mockito.when;
1010

1111
import java.io.IOException;
1212
import java.util.concurrent.Callable;
@@ -33,20 +33,18 @@ public void get() throws IOException {
3333
TemplateSource source = new URLTemplateSource("/template.hbs", getClass().getResource(
3434
"/template.hbs"));
3535

36-
Template template = createMock(Template.class);
36+
Template template = mock(Template.class);
3737

38-
Parser parser = createMock(Parser.class);
39-
expect(parser.parse(source)).andReturn(template);
40-
41-
replay(parser, template);
38+
Parser parser = mock(Parser.class);
39+
when(parser.parse(source)).thenReturn(template);
4240

4341
// 1st call, parse must be call it
4442
assertEquals(template, new GuavaTemplateCache(cache).get(source, parser));
4543

4644
// 2nd call, should return from cache
4745
assertEquals(template, new GuavaTemplateCache(cache).get(source, parser));
4846

49-
verify(parser, template);
47+
verify(parser).parse(source);
5048
}
5149

5250
@Test
@@ -56,22 +54,20 @@ public void getAndReload() throws IOException, InterruptedException {
5654

5755
TemplateSource source = source("/template.hbs");
5856

59-
Template template = createMock(Template.class);
57+
Template template = mock(Template.class);
6058

61-
Template reloadTemplate = createMock(Template.class);
59+
Template reloadTemplate = mock(Template.class);
6260

63-
Parser parser = createMock(Parser.class);
64-
expect(parser.parse(source)).andReturn(template);
61+
Parser parser = mock(Parser.class);
62+
when(parser.parse(same(source))).thenReturn(template);
6563

6664
TemplateSource reloadSource = new ForwardingTemplateSource(source) {
6765
@Override
6866
public long lastModified() {
6967
return System.currentTimeMillis() * 7;
7068
}
7169
};
72-
expect(parser.parse(reloadSource)).andReturn(reloadTemplate);
73-
74-
replay(parser, template, reloadTemplate);
70+
when(parser.parse(same(reloadSource))).thenReturn(reloadTemplate);
7571

7672
// 1st call, parse must be call it
7773
assertEquals(template, new GuavaTemplateCache(cache).setReload(true).get(source, parser));
@@ -83,89 +79,76 @@ public long lastModified() {
8379
assertEquals(reloadTemplate,
8480
new GuavaTemplateCache(cache).setReload(true).get(reloadSource, parser));
8581

86-
verify(parser, template, reloadTemplate);
82+
verify(parser).parse(same(source));
83+
verify(parser).parse(same(reloadSource));
8784
}
8885

8986
@Test
9087
public void evict() throws IOException {
91-
TemplateSource source = createMock(TemplateSource.class);
88+
TemplateSource source = mock(TemplateSource.class);
9289

9390
@SuppressWarnings("unchecked")
94-
Cache<TemplateSource, Template> cache = createMock(Cache.class);
91+
Cache<TemplateSource, Template> cache = mock(Cache.class);
9592
cache.invalidate(source);
9693

97-
replay(cache, source);
98-
9994
new GuavaTemplateCache(cache).evict(source);
100-
101-
verify(cache, source);
10295
}
10396

10497
@Test
10598
public void clear() throws IOException {
10699
@SuppressWarnings("unchecked")
107-
Cache<TemplateSource, Template> cache = createMock(Cache.class);
100+
Cache<TemplateSource, Template> cache = mock(Cache.class);
108101
cache.invalidateAll();
109102

110-
replay(cache);
111-
112103
new GuavaTemplateCache(cache).clear();
113-
114-
verify(cache);
115104
}
116105

117106
@SuppressWarnings("unchecked")
118107
@Test(expected = IllegalStateException.class)
119108
public void executionExceptionWithRuntimeException() throws IOException, ExecutionException {
120-
TemplateSource source = createMock(TemplateSource.class);
109+
TemplateSource source = mock(TemplateSource.class);
121110

122-
Parser parser = createMock(Parser.class);
111+
Parser parser = mock(Parser.class);
123112

124-
Cache<TemplateSource, Template> cache = createMock(Cache.class);
125-
expect(cache.get(eq(source), isA(Callable.class))).andThrow(
113+
Cache<TemplateSource, Template> cache = mock(Cache.class);
114+
when(cache.get(eq(source), any(Callable.class))).thenThrow(
126115
new ExecutionException(new IllegalStateException()));
127116

128-
replay(cache, source, parser);
129-
130117
new GuavaTemplateCache(cache).get(source, parser);
131118

132-
verify(cache, source, parser);
119+
verify(cache).get(eq(source), any(Callable.class));
133120
}
134121

135122
@SuppressWarnings("unchecked")
136123
@Test(expected = Error.class)
137124
public void executionExceptionWithError() throws IOException, ExecutionException {
138-
TemplateSource source = createMock(TemplateSource.class);
125+
TemplateSource source = mock(TemplateSource.class);
139126

140-
Parser parser = createMock(Parser.class);
127+
Parser parser = mock(Parser.class);
141128

142-
Cache<TemplateSource, Template> cache = createMock(Cache.class);
143-
expect(cache.get(eq(source), isA(Callable.class))).andThrow(
129+
Cache<TemplateSource, Template> cache = mock(Cache.class);
130+
when(cache.get(eq(source), any(Callable.class))).thenThrow(
144131
new ExecutionException(new Error()));
145132

146-
replay(cache, source, parser);
147-
148133
new GuavaTemplateCache(cache).get(source, parser);
149134

150-
verify(cache, source, parser);
135+
verify(cache).get(eq(source), any(Callable.class));
151136
}
152137

153138
@SuppressWarnings("unchecked")
154139
@Test(expected = HandlebarsException.class)
155140
public void executionExceptionWithCheckedException() throws IOException, ExecutionException {
156-
TemplateSource source = createMock(TemplateSource.class);
141+
TemplateSource source = mock(TemplateSource.class);
157142

158-
Parser parser = createMock(Parser.class);
143+
Parser parser = mock(Parser.class);
159144

160-
Cache<TemplateSource, Template> cache = createMock(Cache.class);
161-
expect(cache.get(eq(source), isA(Callable.class))).andThrow(
145+
Cache<TemplateSource, Template> cache = mock(Cache.class);
146+
when(cache.get(eq(source), any(Callable.class))).thenThrow(
162147
new ExecutionException(new IOException()));
163148

164-
replay(cache, source, parser);
165-
166149
new GuavaTemplateCache(cache).get(source, parser);
167150

168-
verify(cache, source, parser);
151+
verify(cache).get(eq(source), any(Callable.class));
169152
}
170153

171154
private TemplateSource source(final String filename) throws IOException {

handlebars-helpers/pom.xml

+1-7
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
<groupId>org.apache.commons</groupId>
2727
<artifactId>commons-lang3</artifactId>
2828
</dependency>
29-
29+
3030
<dependency>
3131
<groupId>joda-time</groupId>
3232
<artifactId>joda-time</artifactId>
@@ -62,12 +62,6 @@
6262
<scope>test</scope>
6363
</dependency>
6464

65-
<dependency>
66-
<groupId>org.easymock</groupId>
67-
<artifactId>easymock</artifactId>
68-
<scope>test</scope>
69-
</dependency>
70-
7165
<dependency>
7266
<groupId>org.yaml</groupId>
7367
<artifactId>snakeyaml</artifactId>

handlebars-helpers/src/test/java/com/github/jknack/handlebars/helper/JodaHelperTest.java

+8-3
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,8 @@ protected Handlebars newHandlebars() {
4848
@Test
4949
public void testPattern() throws IOException {
5050
DateTime dateTime = new DateTime().withDate(1995, 7, 4).withTime(14, 32, 12, 0);
51-
shouldCompileTo("{{jodaPatternHelper this \"y-MMM-d H:m:s\"}}", dateTime, "1995-Jul-4 14:32:12");
51+
shouldCompileTo("{{jodaPatternHelper this \"y-MMM-d H:m:s\"}}", dateTime,
52+
"1995-Jul-4 14:32:12");
5253
}
5354

5455
@Test
@@ -66,7 +67,10 @@ public void testBadPattern() throws IOException {
6667
@Test
6768
public void testStyle() throws IOException {
6869
DateTime dateTime = new DateTime().withDate(1995, 7, 4).withTime(14, 32, 12, 0);
69-
shouldCompileTo("{{jodaStyleHelper this \"SS\"}}", dateTime, "7/4/95 2:32 PM");
70+
withJava(version -> version <= 8,
71+
() -> shouldCompileTo("{{jodaStyleHelper this \"SS\"}}", dateTime, "7/4/95 2:32 PM"));
72+
withJava(version -> version >= 9,
73+
() -> shouldCompileTo("{{jodaStyleHelper this \"SS\"}}", dateTime, "7/4/95, 2:32 PM"));
7074
}
7175

7276
@Test
@@ -82,7 +86,8 @@ public void testBadStyle() throws IOException {
8286

8387
@Test
8488
public void testISO() throws IOException {
85-
DateTime dateTime = new DateTime().withDate(1995, 7, 4).withTime(14, 32, 12, 0).withZoneRetainFields(DateTimeZone.UTC);
89+
DateTime dateTime = new DateTime().withDate(1995, 7, 4).withTime(14, 32, 12, 0)
90+
.withZoneRetainFields(DateTimeZone.UTC);
8691
shouldCompileTo("{{jodaISOHelper this}}", dateTime, "1995-07-04T14:32:12Z");
8792
}
8893
}

handlebars-humanize/pom.xml

+33
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,39 @@
4545
<scope>test</scope>
4646
</dependency>
4747

48+
<dependency>
49+
<groupId>org.apache.commons</groupId>
50+
<artifactId>commons-lang3</artifactId>
51+
<scope>test</scope>
52+
</dependency>
53+
54+
<dependency>
55+
<groupId>org.antlr</groupId>
56+
<artifactId>antlr4-runtime</artifactId>
57+
<version>4.9.2</version>
58+
<exclusions>
59+
<exclusion>
60+
<groupId>org.abego.treelayout</groupId>
61+
<artifactId>org.abego.treelayout.core</artifactId>
62+
</exclusion>
63+
</exclusions>
64+
<scope>test</scope>
65+
</dependency>
66+
67+
<dependency>
68+
<groupId>org.apache.commons</groupId>
69+
<artifactId>commons-text</artifactId>
70+
<scope>test</scope>
71+
</dependency>
72+
73+
<dependency>
74+
<groupId>com.github.jknack</groupId>
75+
<artifactId>handlebars</artifactId>
76+
<version>${project.version}</version>
77+
<scope>test</scope>
78+
<classifier>tests</classifier>
79+
</dependency>
80+
4881
</dependencies>
4982

5083
</project>

handlebars-humanize/src/test/java/com/github/jknack/handlebars/HumanizeHelperTest.java

+18-7
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99
import org.junit.Test;
1010

11-
public class HumanizeHelperTest {
11+
public class HumanizeHelperTest extends AbstractTest {
1212
private static final Handlebars handlebars = new Handlebars();
1313

1414
static {
@@ -59,17 +59,28 @@ public void decamelize() throws IOException {
5959
*/
6060
@Test
6161
public void formatCurrency_es_AR() throws IOException {
62-
assertEquals("$34",
62+
withJava(v -> v <= 8, () -> assertEquals("$34",
6363
handlebars.compileInline("{{formatCurrency this locale=\"es_AR\"}}")
64-
.apply(34));
64+
.apply(34)));
65+
withJava(v -> v >= 9, () -> assertEquals("$\u00A034",
66+
handlebars.compileInline("{{formatCurrency this locale=\"es_AR\"}}")
67+
.apply(34)));
6568

66-
assertEquals("$1.000",
69+
withJava(v -> v == 8, () -> assertEquals("$1.000",
6770
handlebars.compileInline("{{formatCurrency this locale=\"es_AR\"}}")
68-
.apply(1000));
71+
.apply(1000)));
6972

70-
assertEquals("$12,50",
73+
withJava(v -> v >= 9, () -> assertEquals("$\u00A01.000",
7174
handlebars.compileInline("{{formatCurrency this locale=\"es_AR\"}}")
72-
.apply(12.5));
75+
.apply(1000)));
76+
77+
withJava(v -> v == 8, () -> assertEquals("$12,50",
78+
handlebars.compileInline("{{formatCurrency this locale=\"es_AR\"}}")
79+
.apply(12.5)));
80+
81+
withJava(v -> v >= 9, () -> assertEquals("$\u00A012,50",
82+
handlebars.compileInline("{{formatCurrency this locale=\"es_AR\"}}")
83+
.apply(12.5)));
7384
}
7485

7586
/**

handlebars-jackson2/pom.xml

+2-2
Original file line numberDiff line numberDiff line change
@@ -55,8 +55,8 @@
5555
</dependency>
5656

5757
<dependency>
58-
<groupId>org.easymock</groupId>
59-
<artifactId>easymock</artifactId>
58+
<groupId>org.mockito</groupId>
59+
<artifactId>mockito-core</artifactId>
6060
<scope>test</scope>
6161
</dependency>
6262
</dependencies>

0 commit comments

Comments
 (0)