| /* |
| * Licensed to the Apache Software Foundation (ASF) under one or more |
| * contributor license agreements. See the NOTICE file distributed with |
| * this work for additional information regarding copyright ownership. |
| * The ASF licenses this file to You under the Apache License, Version 2.0 |
| * (the "License"); you may not use this file except in compliance with |
| * the License. You may obtain a copy of the License at |
| * |
| * http://www.apache.org/licenses/LICENSE-2.0 |
| * |
| * Unless required by applicable law or agreed to in writing, software |
| * distributed under the License is distributed on an "AS IS" BASIS, |
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| * See the License for the specific language governing permissions and |
| * limitations under the License. |
| */ |
| package org.apache.james.mime4j.util; |
| |
| import junit.framework.TestCase; |
| |
| public class MessageUtilsTest extends TestCase { |
| |
| public void testAllASCII() { |
| String s = "Like hello and stuff"; |
| assertTrue(MessageUtils.isASCII(s)); |
| } |
| |
| static final int RUSSIAN_HELLO [] = { |
| 0x412, 0x441, 0x435, 0x43C, 0x5F, 0x43F, 0x440, 0x438, |
| 0x432, 0x435, 0x442 |
| }; |
| |
| static final int SWISS_GERMAN_HELLO [] = { |
| 0x47, 0x72, 0xFC, 0x65, 0x7A, 0x69, 0x5F, 0x7A, 0xE4, 0x6D, 0xE4 |
| }; |
| |
| private static String constructString(int [] unicodeChars) { |
| StringBuffer buffer = new StringBuffer(); |
| if (unicodeChars != null) { |
| for (int i = 0; i < unicodeChars.length; i++) { |
| buffer.append((char)unicodeChars[i]); |
| } |
| } |
| return buffer.toString(); |
| } |
| |
| public void testNonASCII() { |
| String s = constructString(SWISS_GERMAN_HELLO); |
| assertFalse(MessageUtils.isASCII(s)); |
| s = constructString(RUSSIAN_HELLO); |
| assertFalse(MessageUtils.isASCII(s)); |
| } |
| |
| } |