Skip to content

Commit

Permalink
Clean up code in src/main/test
Browse files Browse the repository at this point in the history
Replace deprecated org.junit.Assert.assertThat with org.hamcrest.MatcherAssert.assertThat.
Organize imports.
Replace HashMap subclass with Collections.singletonMap where possible.
Add SupressWarnings "unused", "deprecation", "serial" where appropriate.
DateTest: Add additional checks for vararg method.
  • Loading branch information
kohlschuetter committed Jun 27, 2023
1 parent 949b1f8 commit e96c161
Show file tree
Hide file tree
Showing 83 changed files with 247 additions and 229 deletions.
4 changes: 1 addition & 3 deletions src/test/java/liqp/InsertionTest.java
Original file line number Diff line number Diff line change
@@ -1,15 +1,13 @@
package liqp;

import static org.hamcrest.CoreMatchers.is;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertThat;
import static org.junit.Assert.fail;

import org.antlr.v4.runtime.RecognitionException;
import org.junit.Test;

import liqp.blocks.Block;
import liqp.exceptions.LiquidException;
import liqp.nodes.LNode;
import liqp.tags.Tag;

Expand Down
7 changes: 3 additions & 4 deletions src/test/java/liqp/LValueTest.java
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
package liqp;

import com.fasterxml.jackson.databind.ObjectMapper;
import liqp.filters.Date;
import liqp.spi.SPIHelper;
import static org.junit.Assert.assertTrue;

import org.junit.Test;

import static org.junit.Assert.*;
import liqp.spi.SPIHelper;
public class LValueTest {
@Test
public void testIsTemporal() {
Expand Down
2 changes: 2 additions & 0 deletions src/test/java/liqp/ReadmeSamplesTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ public class ReadmeSamplesTest {
@Test
public void testInspectable() {
class MyParams implements Inspectable {
@SuppressWarnings("unused")
public String name = "tobi";
};
Template template = TemplateParser.DEFAULT.parse("hi {{name}}");
Expand Down Expand Up @@ -40,6 +41,7 @@ public void testEagerMode() {
.build();

Map<String, Object> in = Collections.singletonMap("a", new Object() {
@SuppressWarnings("unused")
public String val = "tobi";
});

Expand Down
2 changes: 1 addition & 1 deletion src/test/java/liqp/RenderSettingsTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@


import static org.hamcrest.CoreMatchers.is;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertThat;
import static org.junit.Assert.assertTrue;

import java.util.ArrayList;
Expand Down
6 changes: 3 additions & 3 deletions src/test/java/liqp/StatementsTest.java
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
package liqp;

import org.junit.Test;

import static org.hamcrest.CoreMatchers.is;
import static org.junit.Assert.assertThat;
import static org.hamcrest.MatcherAssert.assertThat;

import org.junit.Test;

public class StatementsTest {

Expand Down
40 changes: 25 additions & 15 deletions src/test/java/liqp/TemplateTest.java
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
package liqp;

import liqp.filters.Filter;
import liqp.blocks.Block;
import liqp.tags.Tag;
import liqp.nodes.LNode;
import liqp.parser.Inspectable;
import org.antlr.v4.runtime.RecognitionException;
import org.junit.Test;
import static liqp.TestUtils.assertPatternResultEquals;
import static org.hamcrest.CoreMatchers.is;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;

import java.io.File;
import java.io.FileInputStream;
Expand All @@ -23,9 +21,14 @@
import java.util.Locale;
import java.util.Map;

import static liqp.TestUtils.assertPatternResultEquals;
import static org.hamcrest.CoreMatchers.is;
import static org.junit.Assert.*;
import org.antlr.v4.runtime.RecognitionException;
import org.junit.Test;

import liqp.blocks.Block;
import liqp.filters.Filter;
import liqp.nodes.LNode;
import liqp.parser.Inspectable;
import liqp.tags.Tag;

public class TemplateTest {

Expand All @@ -46,6 +49,7 @@ static class Foo implements Inspectable {

public String a = "A";
private String b = "B";
@SuppressWarnings("unused")
private String c = "C";

public String getB() {
Expand Down Expand Up @@ -160,6 +164,7 @@ public SampleDateInspectable(Date date) {
}
}

@SuppressWarnings("deprecation")
@Test
public void testRenderInspectableDateType() {
// given
Expand All @@ -175,6 +180,7 @@ public void testRenderInspectableDateType() {
assertEquals("31 Dec, 2020", res);
}

@SuppressWarnings("deprecation")
@Test
public void testRenderDateType() {
// given
Expand Down Expand Up @@ -211,21 +217,25 @@ public void testDeepData() {
assertEquals("ok", rendered);
}

@SuppressWarnings("unused")
@Test
public void testDeepInspectable() {

// given
Inspectable data = new Inspectable() {
public Inspectable a = new Inspectable() {
public Object[] b = new Object[]{null, null, new Inspectable() {
public List d = new ArrayList();
public List<Object> d = new ArrayList<Object>();
{
d.add(new Object()); // 0
d.add(new Object()); // 1
d.add(new Object()); // 2
d.add(new HashMap() {{
put("e", ZonedDateTime.of(LocalDateTime.of(2021, 11, 3, 16, 40, 44), ZoneId.of("America/Los_Angeles")));
}
d.add(new HashMap<String, ZonedDateTime>() {
private static final long serialVersionUID = 1L;
{
put("e", ZonedDateTime.of(LocalDateTime.of(2021, 11, 3, 16, 40, 44),
ZoneId.of("America/Los_Angeles")));
}
}); // 3
}
}};
Expand Down Expand Up @@ -324,7 +334,7 @@ public Object apply(Object value, TemplateContext context, Object... params) {

private Map<String, Object> getDeepData() {
Map<String, Object> data = new HashMap<>();
Map secondIndex = Collections.singletonMap("e", "ok");
Map<?,?> secondIndex = Collections.singletonMap("e", "ok");
Object[] d = new Object[]{null, null, null, secondIndex};
List<Object> firstIndex = new ArrayList<>();
firstIndex.add(new Object()); // 0
Expand Down
4 changes: 2 additions & 2 deletions src/test/java/liqp/blocks/CaptureTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import static liqp.TestUtils.assertPatternResultEquals;
import static org.hamcrest.CoreMatchers.is;
import static org.junit.Assert.assertThat;
import static org.hamcrest.MatcherAssert.assertThat;

import org.antlr.v4.runtime.RecognitionException;
import org.junit.Test;
Expand Down Expand Up @@ -133,7 +133,7 @@ public void captureTest() throws Exception {
@Test(expected=LiquidException.class)
public void capture_detects_bad_syntaxTest() throws Exception {
Template template = TemplateParser.DEFAULT.parse("{{ var2 }}{% capture %}{{ var }} foo {% endcapture %}{{ var2 }}{{ var2 }}");
String res = template.render("{ \"var\" : \"content\" }");
template.render("{ \"var\" : \"content\" }");
}

@Test
Expand Down
11 changes: 6 additions & 5 deletions src/test/java/liqp/blocks/CaseTest.java
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
package liqp.blocks;

import liqp.Template;
import liqp.TemplateParser;
import liqp.exceptions.LiquidException;
import static org.hamcrest.CoreMatchers.is;
import static org.hamcrest.MatcherAssert.assertThat;

import org.antlr.v4.runtime.RecognitionException;
import org.junit.Test;

import static org.hamcrest.CoreMatchers.is;
import static org.junit.Assert.assertThat;
import liqp.Template;
import liqp.TemplateParser;
import liqp.exceptions.LiquidException;

public class CaseTest {

Expand Down
8 changes: 4 additions & 4 deletions src/test/java/liqp/blocks/CommentTest.java
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
package liqp.blocks;

import liqp.Template;
import liqp.TemplateParser;
import static org.hamcrest.CoreMatchers.is;
import static org.hamcrest.MatcherAssert.assertThat;

import org.antlr.v4.runtime.RecognitionException;
import org.junit.Test;

import static org.hamcrest.CoreMatchers.is;
import static org.junit.Assert.assertThat;
import liqp.Template;
import liqp.TemplateParser;

public class CommentTest {

Expand Down
8 changes: 4 additions & 4 deletions src/test/java/liqp/blocks/CycleTest.java
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
package liqp.blocks;

import liqp.Template;
import liqp.TemplateParser;
import static org.hamcrest.CoreMatchers.is;
import static org.hamcrest.MatcherAssert.assertThat;

import org.antlr.v4.runtime.RecognitionException;
import org.junit.Test;

import static org.hamcrest.CoreMatchers.is;
import static org.junit.Assert.assertThat;
import liqp.Template;
import liqp.TemplateParser;

public class CycleTest {

Expand Down
8 changes: 4 additions & 4 deletions src/test/java/liqp/blocks/ForTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,15 @@
import static java.util.Collections.singletonMap;
import static liqp.TestUtils.assertPatternResultEquals;
import static org.hamcrest.CoreMatchers.is;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertThat;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;

import java.util.HashMap;
import java.util.Map;

import org.antlr.v4.runtime.RecognitionException;
import org.junit.Assert;
import org.junit.Test;

import liqp.RenderSettings;
Expand Down Expand Up @@ -173,6 +172,7 @@ public void test_for_with_hash_value_range() {
public void test_for_with_drop_value_range() {
//noinspection unused
Object foobar = new Inspectable() {
@SuppressWarnings("unused")
public final int value = 3;
};
assertTemplateResult(" 1 2 3 ", "{%for item in (1..foobar.value) %} {{item}} {%endfor%}", singletonMap("foobar", foobar));
Expand Down Expand Up @@ -846,7 +846,7 @@ public void mapTest() {
String expected = "a is AAA;b is BBB;";
String rendered = TemplateParser.DEFAULT.parse(template).render(hash);

Assert.assertThat(rendered, is(expected));
assertThat(rendered, is(expected));
}


Expand Down Expand Up @@ -920,7 +920,7 @@ public void assertTemplateResult(String expected, String template) {
assertThat(TemplateParser.DEFAULT.parse(template).render(), is(expected));
}

public void assertTemplateResult(String expected, String template, Map data) {
public void assertTemplateResult(String expected, String template, Map<String, Object> data) {
assertThat(TemplateParser.DEFAULT.parse(template).render(data), is(expected));
}
public void assertTemplateResult(String expected, String template, String data) {
Expand Down
2 changes: 1 addition & 1 deletion src/test/java/liqp/blocks/IfchangedTest.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package liqp.blocks;

import static org.hamcrest.CoreMatchers.is;
import static org.junit.Assert.assertThat;
import static org.hamcrest.MatcherAssert.assertThat;

import org.junit.Test;

Expand Down
2 changes: 1 addition & 1 deletion src/test/java/liqp/blocks/RawTest.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package liqp.blocks;

import static org.hamcrest.CoreMatchers.is;
import static org.junit.Assert.assertThat;
import static org.hamcrest.MatcherAssert.assertThat;

import org.antlr.v4.runtime.RecognitionException;
import org.junit.Test;
Expand Down
2 changes: 1 addition & 1 deletion src/test/java/liqp/blocks/TablerowTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import static liqp.TestUtils.assertPatternResultEquals;
import static org.hamcrest.CoreMatchers.is;
import static org.junit.Assert.assertThat;
import static org.hamcrest.MatcherAssert.assertThat;

import org.antlr.v4.runtime.RecognitionException;
import org.junit.Test;
Expand Down
2 changes: 1 addition & 1 deletion src/test/java/liqp/blocks/UnlessTest.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package liqp.blocks;

import static org.hamcrest.CoreMatchers.is;
import static org.junit.Assert.assertThat;
import static org.hamcrest.MatcherAssert.assertThat;

import org.antlr.v4.runtime.RecognitionException;
import org.junit.Test;
Expand Down
2 changes: 1 addition & 1 deletion src/test/java/liqp/filters/At_LeastTest.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package liqp.filters;

import static org.hamcrest.CoreMatchers.is;
import static org.junit.Assert.assertThat;
import static org.hamcrest.MatcherAssert.assertThat;

import org.antlr.v4.runtime.RecognitionException;
import org.junit.Test;
Expand Down
2 changes: 1 addition & 1 deletion src/test/java/liqp/filters/At_MostTest.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package liqp.filters;

import static org.hamcrest.CoreMatchers.is;
import static org.junit.Assert.assertThat;
import static org.hamcrest.MatcherAssert.assertThat;

import org.antlr.v4.runtime.RecognitionException;
import org.junit.Test;
Expand Down
2 changes: 1 addition & 1 deletion src/test/java/liqp/filters/CapitalizeTest.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package liqp.filters;

import static org.hamcrest.CoreMatchers.is;
import static org.junit.Assert.assertThat;
import static org.hamcrest.MatcherAssert.assertThat;

import org.antlr.v4.runtime.RecognitionException;
import org.junit.Test;
Expand Down
2 changes: 1 addition & 1 deletion src/test/java/liqp/filters/CeilTest.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package liqp.filters;

import static org.hamcrest.CoreMatchers.is;
import static org.junit.Assert.assertThat;
import static org.hamcrest.MatcherAssert.assertThat;

import org.antlr.v4.runtime.RecognitionException;
import org.junit.Test;
Expand Down
2 changes: 1 addition & 1 deletion src/test/java/liqp/filters/CompactTest.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package liqp.filters;

import static org.hamcrest.CoreMatchers.is;
import static org.junit.Assert.assertThat;
import static org.hamcrest.MatcherAssert.assertThat;

import org.antlr.v4.runtime.RecognitionException;
import org.junit.Test;
Expand Down
2 changes: 1 addition & 1 deletion src/test/java/liqp/filters/ConcatTest.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package liqp.filters;

import static org.hamcrest.CoreMatchers.is;
import static org.junit.Assert.assertThat;
import static org.hamcrest.MatcherAssert.assertThat;

import org.junit.Test;

Expand Down
5 changes: 4 additions & 1 deletion src/test/java/liqp/filters/DateTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,10 @@ public void applyOriginalTest() throws Exception {
assertThat(filter.apply("2006-07-05 10:00:00", context,"%B"), is((Object)"July"));

assertThat(filter.apply("2006-07-05 10:00:00", context,""), is((Object)"2006-07-05 10:00:00"));
assertThat(filter.apply("2006-07-05 10:00:00", context,null), is((Object)"2006-07-05 10:00:00"));
assertThat(filter.apply("2006-07-05 10:00:00", context), is((Object)"2006-07-05 10:00:00"));
assertThat(filter.apply("2006-07-05 10:00:00", context, (Object)null), is((Object)"2006-07-05 10:00:00"));
assertThat(filter.apply("2006-07-05 10:00:00", context, (Object[])null), is((Object)"2006-07-05 10:00:00"));
assertThat(filter.apply("2006-07-05 10:00:00", context, new Object[0]), is((Object)"2006-07-05 10:00:00"));

assertThat(filter.apply("2006-07-05 10:00:00", context,"%m/%d/%Y"), is((Object)"07/05/2006"));

Expand Down
2 changes: 1 addition & 1 deletion src/test/java/liqp/filters/DefaultTest.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package liqp.filters;

import static org.hamcrest.CoreMatchers.is;
import static org.junit.Assert.assertThat;
import static org.hamcrest.MatcherAssert.assertThat;

import org.antlr.v4.runtime.RecognitionException;
import org.junit.Test;
Expand Down
Loading

0 comments on commit e96c161

Please sign in to comment.