Skip to content

Commit c612809

Browse files
committed
issue #759 : Use fixed Locale.ENGLISH for XML error verification
Signed-off-by: Peter Ansell <p_ansell@yahoo.com>
1 parent 305e4a3 commit c612809

2 files changed

Lines changed: 42 additions & 10 deletions

File tree

core/rio/rdfxml/src/test/java/org/eclipse/rdf4j/rio/rdfxml/RDFXMLParserTest.java

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
import java.net.URL;
1919
import java.util.Collection;
2020
import java.util.Iterator;
21+
import java.util.Locale;
2122

2223
import org.eclipse.rdf4j.model.IRI;
2324
import org.eclipse.rdf4j.model.Statement;
@@ -31,6 +32,7 @@
3132
import org.eclipse.rdf4j.rio.helpers.StatementCollector;
3233
import org.hamcrest.CoreMatchers;
3334
import org.hamcrest.Matchers;
35+
import org.junit.After;
3436
import org.junit.Before;
3537
import org.junit.Test;
3638

@@ -44,10 +46,15 @@ public class RDFXMLParserTest {
4446

4547
private ParseErrorCollector el;
4648

49+
private Locale platformLocale;
50+
4751
@Before
4852
public void setUp()
4953
throws Exception
5054
{
55+
platformLocale = Locale.getDefault();
56+
57+
Locale.setDefault(Locale.ENGLISH);
5158
vf = SimpleValueFactory.getInstance();
5259
parser = new RDFXMLParser();
5360
sc = new StatementCollector();
@@ -56,6 +63,13 @@ public void setUp()
5663
parser.setParseErrorListener(el);
5764
}
5865

66+
@After
67+
public void tearDown()
68+
throws Exception
69+
{
70+
Locale.setDefault(platformLocale);
71+
}
72+
5973
@Test
6074
public void rdfXmlLoadedFromInsideAJarResolvesRelativeUris()
6175
throws Exception
@@ -121,7 +135,8 @@ public void testRDFXMLWhitespace()
121135
public void testFatalErrorPrologContent()
122136
throws Exception
123137
{
124-
// Temporarily override System.err to verify that nothing is being printed to it for this test
138+
// Temporarily override System.err to verify that nothing is being
139+
// printed to it for this test
125140
PrintStream oldErr = System.err;
126141
ByteArrayOutputStream tempErr = new ByteArrayOutputStream();
127142
System.setErr(new PrintStream(tempErr));
@@ -134,13 +149,14 @@ public void testFatalErrorPrologContent()
134149
parser.parse(in, "");
135150
}
136151
catch (RDFParseException e) {
137-
// FIXME exact error message is locale-dependent. Just fall through, error is expected. See #280.
138-
// assertEquals("Content is not allowed in prolog. [line 1, column 1]", e.getMessage());
152+
assertEquals("Content is not allowed in prolog. [line 1, column 1]", e.getMessage());
139153
}
140154
finally {
141-
// Reset System Error output to ensure that we don't interfere with other tests
155+
// Reset System Error output to ensure that we don't interfere with
156+
// other tests
142157
System.setErr(oldErr);
143-
// Reset System Out output to ensure that we don't interfere with other tests
158+
// Reset System Out output to ensure that we don't interfere with
159+
// other tests
144160
System.setOut(oldOut);
145161
}
146162
// Verify nothing was printed to System.err during test

core/rio/trix/src/test/java/org/eclipse/rdf4j/rio/trix/TriXParserTest.java

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,15 @@
1212
import java.io.ByteArrayOutputStream;
1313
import java.io.InputStream;
1414
import java.io.PrintStream;
15+
import java.util.Locale;
1516

1617
import org.eclipse.rdf4j.model.ValueFactory;
1718
import org.eclipse.rdf4j.model.impl.SimpleValueFactory;
1819
import org.eclipse.rdf4j.rio.RDFParseException;
1920
import org.eclipse.rdf4j.rio.RDFParser;
2021
import org.eclipse.rdf4j.rio.helpers.ParseErrorCollector;
2122
import org.eclipse.rdf4j.rio.helpers.StatementCollector;
23+
import org.junit.After;
2224
import org.junit.Before;
2325
import org.junit.Test;
2426

@@ -32,10 +34,15 @@ public class TriXParserTest {
3234

3335
private ParseErrorCollector el;
3436

37+
private Locale platformLocale;
38+
3539
@Before
3640
public void setUp()
3741
throws Exception
3842
{
43+
platformLocale = Locale.getDefault();
44+
45+
Locale.setDefault(Locale.ENGLISH);
3946
vf = SimpleValueFactory.getInstance();
4047
parser = new TriXParser();
4148
sc = new StatementCollector();
@@ -44,11 +51,19 @@ public void setUp()
4451
parser.setParseErrorListener(el);
4552
}
4653

54+
@After
55+
public void tearDown()
56+
throws Exception
57+
{
58+
Locale.setDefault(platformLocale);
59+
}
60+
4761
@Test
4862
public void testFatalErrorPrologContent()
4963
throws Exception
5064
{
51-
// Temporarily override System.err to verify that nothing is being printed to it for this test
65+
// Temporarily override System.err to verify that nothing is being
66+
// printed to it for this test
5267
PrintStream oldErr = System.err;
5368
ByteArrayOutputStream tempErr = new ByteArrayOutputStream();
5469
System.setErr(new PrintStream(tempErr));
@@ -61,13 +76,14 @@ public void testFatalErrorPrologContent()
6176
parser.parse(in, "");
6277
}
6378
catch (RDFParseException e) {
64-
// FIXME exact error message is locale-dependent. Just fall through, error is expected. See #280.
65-
// assertEquals("Content is not allowed in prolog. [line 1, column 1]", e.getMessage());
79+
assertEquals("Content is not allowed in prolog. [line 1, column 1]", e.getMessage());
6680
}
6781
finally {
68-
// Reset System Error output to ensure that we don't interfere with other tests
82+
// Reset System Error output to ensure that we don't interfere with
83+
// other tests
6984
System.setErr(oldErr);
70-
// Reset System Out output to ensure that we don't interfere with other tests
85+
// Reset System Out output to ensure that we don't interfere with
86+
// other tests
7187
System.setOut(oldOut);
7288
}
7389
// Verify nothing was printed to System.err during test

0 commit comments

Comments
 (0)