@@ -55,12 +55,13 @@ public void tearDown() throws Exception {
5555 @ Test
5656 public void sentenceByChinese () throws Exception {
5757 final Writer writer = new Writer ();
58- // TODO: 17-11-19 testWriter()
58+ testWriterCn ( writer . sentenceByChinese (), "我是来自北京的小明。" );
5959 }
6060
6161 @ Test
6262 public void sentenceByEnglish () throws Exception {
63- // TODO: 17-11-19 testWriter()
63+ final Writer writer = new Writer ();
64+ testWriter (writer .sentenceByEnglish (), "I am a student from London." );
6465 }
6566
6667 /**
@@ -70,12 +71,26 @@ public void sentenceByEnglish() throws Exception {
7071 * @param expectedString 期望值
7172 */
7273 private void testWriter (final CharacterComposite givenComposite , final String expectedString ) {
73- final String [] words = expectedString .split (" " );
74+ final String [] words = expectedString .trim (). split (" " );
7475 assertNotNull (givenComposite );
7576 assertEquals (givenComposite .count (), words .length );
7677
7778 givenComposite .print ();
7879
7980 assertEquals (expectedString , new String (this .stdOutBuffer .toByteArray ()).trim ());
8081 }
82+
83+ /**
84+ * 测试输出是否和预期相等_中文
85+ *
86+ * @param givenComposite 输入的组件
87+ * @param expectedString 期望值
88+ */
89+ private void testWriterCn (final CharacterComposite givenComposite , final String expectedString ) {
90+ assertNotNull (givenComposite );
91+
92+ givenComposite .print ();
93+
94+ assertEquals (expectedString , new String (this .stdOutBuffer .toByteArray ()).trim ());
95+ }
8196}
0 commit comments