11/*
2- * Copyright IBM Corp. 2016
2+ * Copyright IBM Corp. 2016, 2017
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.
1515 */
1616package com .ibm .g11n .pipeline .resfilter ;
1717
18+ import static org .junit .Assert .assertEquals ;
1819import static org .junit .Assert .assertTrue ;
1920
2021import java .io .File ;
2324import java .io .IOException ;
2425import java .io .InputStream ;
2526import java .io .OutputStream ;
27+ import java .util .ArrayList ;
2628import java .util .Collection ;
29+ import java .util .Collections ;
2730import java .util .LinkedList ;
31+ import java .util .List ;
2832
2933import org .junit .Test ;
3034
35+ import com .ibm .g11n .pipeline .resfilter .ResourceString .ResourceStringComparator ;
36+
3137/**
32- * @author farhan
38+ * @author farhan, jcemmons
3339 *
3440 */
3541public class XLIFFResourceTest {
3642 private static final File INPUT_FILE = new File ("src/test/resource/resfilter/xliff/input.xlf" );
3743
38- @ SuppressWarnings ("unused" )
3944 private static final File EXPECTED_WRITE_FILE = new File ("src/test/resource/resfilter/xliff/write-output.xlf" );
4045
4146 private static final File MERGE_INPUT_1_FILE = new File ("src/test/resource/resfilter/xliff/merge-input-1.xlf" );
@@ -45,25 +50,27 @@ public class XLIFFResourceTest {
4550 @ SuppressWarnings ("unused" )
4651 private static final File EXPECTED_MERGE_2_FILE = new File ("src/test/resource/resfilter/xliff/merge-output-2.xlf" );
4752
48- private static Collection <ResourceString > EXPECTED_INPUT_RES_LIST ;
53+ private static final Collection <ResourceString > EXPECTED_INPUT_RES_LIST ;
4954
5055 static {
51- EXPECTED_INPUT_RES_LIST = new LinkedList <ResourceString >();
56+ List <ResourceString > lst = new LinkedList <>();
57+
58+ lst .add (new ResourceString ("1" , "Quetzal" , 1 ));
59+ lst .add (new ResourceString ("3" , "An application to manipulate and process XLIFF documents" , 2 ));
60+ lst .add (new ResourceString ("4" , "XLIFF Data Manager" , 3 ));
61+ Collections .sort (lst , new ResourceStringComparator ());
62+ EXPECTED_INPUT_RES_LIST = lst ;
5263
53- EXPECTED_INPUT_RES_LIST .add (new ResourceString ("1" , "Quetzal" , 1 ));
54- EXPECTED_INPUT_RES_LIST
55- .add (new ResourceString ("3" , "An application to manipulate and process XLIFF documents" , 2 ));
56- EXPECTED_INPUT_RES_LIST .add (new ResourceString ("4" , "XLIFF Data Manager" , 3 ));
5764 }
5865
5966 private static Bundle WRITE_BUNDLE ;
6067
6168 static {
6269 WRITE_BUNDLE = new Bundle ();
6370
64- WRITE_BUNDLE .addResourceString ("3" , "An application to manipulate and process XLIFF documents" , 2 );
65- WRITE_BUNDLE .addResourceString ("4" , "XLIFF Data Manager " , 3 );
66- WRITE_BUNDLE .addResourceString ("1" , "Quetzal" , 1 );
71+ WRITE_BUNDLE .addResourceString ("3" , "XLIFF 文書を編集、または処理 するアプリケーションです。" , 2 , null , " An application to manipulate and process XLIFF documents" );
72+ WRITE_BUNDLE .addResourceString ("4" , "XLIFF データ・マネージャ " , 3 , null , "XLIFF Data Manager" );
73+ WRITE_BUNDLE .addResourceString ("1" , "Quetzal" , 1 , null , "Quetzal" );
6774 }
6875
6976 private static Bundle MERGE_BUNDLE ;
@@ -82,24 +89,22 @@ public void testParse() throws IOException {
8289 assertTrue ("The input test file <" + INPUT_FILE + "> does not exist." , INPUT_FILE .exists ());
8390
8491 try (InputStream is = new FileInputStream (INPUT_FILE )) {
85- @ SuppressWarnings ("unused" )
8692 Bundle bundle = res .parse (is );
87- // TODO: Not ready yet
88- // assertEquals("ResourceStrings did not match.", EXPECTED_INPUT_RES_LIST, bundle.getResourceStrings());
93+ List <ResourceString > resStrList = new ArrayList <>(bundle .getResourceStrings ());
94+ Collections .sort (resStrList , new ResourceStringComparator ());
95+ assertEquals ("ResourceStrings did not match." , EXPECTED_INPUT_RES_LIST , resStrList );
8996 }
9097 }
9198
92- @ SuppressWarnings ("deprecation" )
9399 @ Test
94100 public void testWrite () throws IOException {
95101 File tempFile = File .createTempFile (this .getClass ().getSimpleName (), ".xlf" );
96102 tempFile .deleteOnExit ();
97103
98104 try (OutputStream os = new FileOutputStream (tempFile )) {
99- res .write (os , null , WRITE_BUNDLE );
105+ res .write (os , "ja" , WRITE_BUNDLE );
100106 os .flush ();
101- // TODO: Not ready yet
102- // assertTrue(ResourceTestUtil.compareFiles(EXPECTED_WRITE_FILE, tempFile));
107+ assertTrue (ResourceTestUtil .compareFiles (EXPECTED_WRITE_FILE , tempFile ));
103108 }
104109 }
105110
0 commit comments