Skip to content

Commit 6ddfb91

Browse files
committed
Parameterized unit tests and added corresponding Maven dependencies
1 parent f6caf12 commit 6ddfb91

File tree

2 files changed

+54
-31
lines changed

2 files changed

+54
-31
lines changed

pom.xml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -200,6 +200,12 @@
200200
<version>5.7.1</version>
201201
<scope>test</scope>
202202
</dependency>
203+
<dependency>
204+
<groupId>org.junit.jupiter</groupId>
205+
<artifactId>junit-jupiter-params</artifactId>
206+
<version>5.7.1</version>
207+
<scope>test</scope>
208+
</dependency>
203209
<dependency>
204210
<groupId>org.hsqldb</groupId>
205211
<artifactId>hsqldb</artifactId>

src/test/java/org/apache/ibatis/parsing/GenericTokenParserTest.java

Lines changed: 48 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/**
2-
* Copyright 2009-2020 the original author or authors.
2+
* Copyright 2009-2021 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -16,14 +16,19 @@
1616
package org.apache.ibatis.parsing;
1717

1818
import static org.junit.jupiter.api.Assertions.assertEquals;
19+
import static org.junit.jupiter.params.provider.Arguments.arguments;
1920

2021
import java.time.Duration;
2122
import java.util.HashMap;
2223
import java.util.Map;
24+
import java.util.stream.Stream;
2325

2426
import org.junit.jupiter.api.Assertions;
2527
import org.junit.jupiter.api.Disabled;
2628
import org.junit.jupiter.api.Test;
29+
import org.junit.jupiter.params.ParameterizedTest;
30+
import org.junit.jupiter.params.provider.Arguments;
31+
import org.junit.jupiter.params.provider.MethodSource;
2732

2833
class GenericTokenParserTest {
2934

@@ -40,8 +45,9 @@ public String handleToken(String content) {
4045
}
4146
}
4247

43-
@Test
44-
void shouldDemonstrateGenericTokenReplacement() {
48+
@ParameterizedTest
49+
@MethodSource("shouldDemonstrateGenericTokenReplacementProvider")
50+
void shouldDemonstrateGenericTokenReplacement(String expected, String text) {
4551
GenericTokenParser parser = new GenericTokenParser("${", "}", new VariableTokenHandler(new HashMap<String, String>() {
4652
{
4753
put("first_name", "James");
@@ -51,39 +57,50 @@ void shouldDemonstrateGenericTokenReplacement() {
5157
put("", "");
5258
}
5359
}));
60+
assertEquals(expected, parser.parse(text));
61+
}
5462

55-
assertEquals("James T Kirk reporting.", parser.parse("${first_name} ${initial} ${last_name} reporting."));
56-
assertEquals("Hello captain James T Kirk", parser.parse("Hello captain ${first_name} ${initial} ${last_name}"));
57-
assertEquals("James T Kirk", parser.parse("${first_name} ${initial} ${last_name}"));
58-
assertEquals("JamesTKirk", parser.parse("${first_name}${initial}${last_name}"));
59-
assertEquals("{}JamesTKirk", parser.parse("{}${first_name}${initial}${last_name}"));
60-
assertEquals("}JamesTKirk", parser.parse("}${first_name}${initial}${last_name}"));
61-
62-
assertEquals("}James{{T}}Kirk", parser.parse("}${first_name}{{${initial}}}${last_name}"));
63-
assertEquals("}James}T{Kirk", parser.parse("}${first_name}}${initial}{${last_name}"));
64-
assertEquals("}James}T{Kirk", parser.parse("}${first_name}}${initial}{${last_name}"));
65-
assertEquals("}James}T{Kirk{{}}", parser.parse("}${first_name}}${initial}{${last_name}{{}}"));
66-
assertEquals("}James}T{Kirk{{}}", parser.parse("}${first_name}}${initial}{${last_name}{{}}${}"));
67-
68-
assertEquals("{$$something}JamesTKirk", parser.parse("{$$something}${first_name}${initial}${last_name}"));
69-
assertEquals("${", parser.parse("${"));
70-
assertEquals("${\\}", parser.parse("${\\}"));
71-
assertEquals("Hiya", parser.parse("${var{with\\}brace}"));
72-
assertEquals("", parser.parse("${}"));
73-
assertEquals("}", parser.parse("}"));
74-
assertEquals("Hello ${ this is a test.", parser.parse("Hello ${ this is a test."));
75-
assertEquals("Hello } this is a test.", parser.parse("Hello } this is a test."));
76-
assertEquals("Hello } ${ this is a test.", parser.parse("Hello } ${ this is a test."));
63+
static Stream<Arguments> shouldDemonstrateGenericTokenReplacementProvider() {
64+
return Stream.of(
65+
arguments("James T Kirk reporting.", "${first_name} ${initial} ${last_name} reporting."),
66+
arguments("Hello captain James T Kirk", "Hello captain ${first_name} ${initial} ${last_name}"),
67+
arguments("James T Kirk", "${first_name} ${initial} ${last_name}"),
68+
arguments("JamesTKirk", "${first_name}${initial}${last_name}"),
69+
arguments("{}JamesTKirk", "{}${first_name}${initial}${last_name}"),
70+
arguments("}JamesTKirk", "}${first_name}${initial}${last_name}"),
71+
72+
arguments("}James{{T}}Kirk", "}${first_name}{{${initial}}}${last_name}"),
73+
arguments("}James}T{Kirk", "}${first_name}}${initial}{${last_name}"),
74+
arguments("}James}T{Kirk", "}${first_name}}${initial}{${last_name}"),
75+
arguments("}James}T{Kirk{{}}", "}${first_name}}${initial}{${last_name}{{}}"),
76+
arguments("}James}T{Kirk{{}}", "}${first_name}}${initial}{${last_name}{{}}${}"),
77+
78+
arguments("{$$something}JamesTKirk", "{$$something}${first_name}${initial}${last_name}"),
79+
arguments("${", "${"),
80+
arguments("${\\}", "${\\}"),
81+
arguments("Hiya", "${var{with\\}brace}"),
82+
arguments("", "${}"),
83+
arguments("}", "}"),
84+
arguments("Hello ${ this is a test.", "Hello ${ this is a test."),
85+
arguments("Hello } this is a test.", "Hello } this is a test."),
86+
arguments("Hello } ${ this is a test.", "Hello } ${ this is a test.")
87+
);
7788
}
7889

79-
@Test
80-
void shallNotInterpolateSkippedVaiables() {
90+
@ParameterizedTest
91+
@MethodSource("shallNotInterpolateSkippedVariablesProvider")
92+
void shallNotInterpolateSkippedVariables(String expected, String text) {
8193
GenericTokenParser parser = new GenericTokenParser("${", "}", new VariableTokenHandler(new HashMap<>()));
94+
assertEquals(expected, parser.parse(text));
95+
}
8296

83-
assertEquals("${skipped} variable", parser.parse("\\${skipped} variable"));
84-
assertEquals("This is a ${skipped} variable", parser.parse("This is a \\${skipped} variable"));
85-
assertEquals("null ${skipped} variable", parser.parse("${skipped} \\${skipped} variable"));
86-
assertEquals("The null is ${skipped} variable", parser.parse("The ${skipped} is \\${skipped} variable"));
97+
static Stream<Arguments> shallNotInterpolateSkippedVariablesProvider() {
98+
return Stream.of(
99+
arguments("${skipped} variable", "\\${skipped} variable"),
100+
arguments("This is a ${skipped} variable", "This is a \\${skipped} variable"),
101+
arguments("null ${skipped} variable", "${skipped} \\${skipped} variable"),
102+
arguments("The null is ${skipped} variable", "The ${skipped} is \\${skipped} variable")
103+
);
87104
}
88105

89106
@Disabled("Because it randomly fails on Travis CI. It could be useful during development.")

0 commit comments

Comments
 (0)