-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test showing that translation from sbgn 0.2 does not use proper encod…
…ing on machines with encoding different than utf-8 (for instance typical Windows machine)
- Loading branch information
1 parent
3c0607f
commit 09c8a73
Showing
2 changed files
with
61 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
package org.sbgn; | ||
|
||
import static org.junit.Assert.assertEquals; | ||
|
||
import java.io.File; | ||
import java.lang.reflect.Field; | ||
import java.lang.reflect.Modifier; | ||
import java.nio.charset.Charset; | ||
import java.nio.charset.StandardCharsets; | ||
|
||
import javax.xml.bind.JAXBException; | ||
|
||
import org.junit.Test; | ||
import org.sbgn.bindings.Sbgn; | ||
|
||
public class SbgnUtilTest { | ||
|
||
@Test | ||
public void testUtfEncodingWithDifferentSystemFileEncoding() throws JAXBException { | ||
try { | ||
// modify the encoding that was taken from file.encoding system property | ||
// this is done at JVM startup therefore instead of changing system property we | ||
// must modify the cached value to simulate running it on the machine with | ||
// ISO-8859-1 encoding | ||
Field field = null; | ||
for (Field f : Charset.class.getDeclaredFields()) { | ||
if (f.getName().equals("defaultCharset")) { | ||
field = f; | ||
} | ||
} | ||
field.setAccessible(true); | ||
Field modifiersField = Field.class.getDeclaredField("modifiers"); | ||
modifiersField.setAccessible(true); | ||
modifiersField.setInt(field, field.getModifiers() & ~Modifier.FINAL); | ||
|
||
field.set(null, StandardCharsets.ISO_8859_1); | ||
|
||
try { | ||
Sbgn sbgn = SbgnUtil.readFromFile(new File("test-files/PD/utf8_sbgn.0.2.sbgn")); | ||
assertEquals("β", sbgn.getMap().get(0).getGlyph().get(0).getLabel().getText()); | ||
} finally { | ||
//restore default encoding to UTF-8 | ||
field.set(null, StandardCharsets.UTF_8); | ||
} | ||
|
||
} catch (Exception e) { | ||
e.printStackTrace(); | ||
} | ||
|
||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
<?xml version="1.0" encoding="UTF-8" standalone="yes"?> | ||
<sbgn xmlns="http://sbgn.org/libsbgn/0.2"> | ||
<map language="process description"> | ||
<glyph class="simple chemical" id="glyph_n3"> | ||
<label text="β"/> | ||
<bbox w="140.0" h="32.0" x="75.0" y="272.53503"/> | ||
</glyph> | ||
</map> | ||
</sbgn> |