1   /*
2    *  Licensed to the Apache Software Foundation (ASF) under one
3    *  or more contributor license agreements.  See the NOTICE file
4    *  distributed with this work for additional information
5    *  regarding copyright ownership.  The ASF licenses this file
6    *  to you under the Apache License, Version 2.0 (the
7    *  "License"); you may not use this file except in compliance
8    *  with the License.  You may obtain a copy of the License at
9    *
10   *    http://www.apache.org/licenses/LICENSE-2.0
11   *
12   *  Unless required by applicable law or agreed to in writing,
13   *  software distributed under the License is distributed on an
14   *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15   *  KIND, either express or implied.  See the License for the
16   *  specific language governing permissions and limitations
17   *  under the License.
18   *
19   */
20  package org.apache.mina.filter.codec.textline;
21  
22  import java.nio.charset.Charset;
23  
24  import junit.framework.Assert;
25  import junit.framework.TestCase;
26  
27  import org.apache.mina.core.buffer.IoBuffer;
28  import org.apache.mina.filter.codec.ProtocolCodecSession;
29  import org.apache.mina.filter.codec.ProtocolEncoderOutput;
30  
31  /**
32   * Tests {@link TextLineEncoder}.
33   *
34   * @author The Apache MINA Project (dev@mina.apache.org)
35   * @version $Rev: 671827 $, $Date: 2008-06-26 10:49:48 +0200 (Thu, 26 Jun 2008) $
36   */
37  public class TextLineEncoderTest extends TestCase {
38      public static void main(String[] args) {
39          junit.textui.TestRunner.run(TextLineEncoderTest.class);
40      }
41  
42      public void testEncode() throws Exception {
43          TextLineEncoder encoder = new TextLineEncoder(Charset.forName("UTF-8"),
44                  LineDelimiter.WINDOWS);
45          ProtocolCodecSession session = new ProtocolCodecSession();
46          ProtocolEncoderOutput out = session.getEncoderOutput();
47  
48          encoder.encode(session, "ABC", out);
49          Assert.assertEquals(1, session.getEncoderOutputQueue().size());
50          IoBuffer buf = (IoBuffer) session.getEncoderOutputQueue().poll();
51          Assert.assertEquals(5, buf.remaining());
52          Assert.assertEquals('A', buf.get());
53          Assert.assertEquals('B', buf.get());
54          Assert.assertEquals('C', buf.get());
55          Assert.assertEquals('\r', buf.get());
56          Assert.assertEquals('\n', buf.get());
57      }
58  }