001/* 002 * Licensed to the Apache Software Foundation (ASF) under one or more 003 * contributor license agreements. See the NOTICE file distributed with 004 * this work for additional information regarding copyright ownership. 005 * The ASF licenses this file to You under the Apache License, Version 2.0 006 * (the "License"); you may not use this file except in compliance with 007 * the License. You may obtain a copy of the License at 008 * 009 * http://www.apache.org/licenses/LICENSE-2.0 010 * 011 * Unless required by applicable law or agreed to in writing, software 012 * distributed under the License is distributed on an "AS IS" BASIS, 013 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 014 * See the License for the specific language governing permissions and 015 * limitations under the License. 016 */ 017 018package org.apache.commons.lang3.text.translate; 019 020import static org.junit.Assert.assertEquals; 021import static org.junit.Assert.fail; 022 023import org.junit.Test; 024 025/** 026 * Unit tests for {@link org.apache.commons.lang3.text.translate.UnicodeEscaper}. 027 * @version $Id: UnicodeUnescaperTest.java 1436770 2013-01-22 07:09:45Z ggregory $ 028 */ 029public class UnicodeUnescaperTest { 030 031 // Requested in LANG-507 032 @Test 033 public void testUPlus() { 034 final UnicodeUnescaper uu = new UnicodeUnescaper(); 035 036 final String input = "\\u+0047"; 037 assertEquals("Failed to unescape Unicode characters with 'u+' notation", "G", uu.translate(input)); 038 } 039 040 @Test 041 public void testUuuuu() { 042 final UnicodeUnescaper uu = new UnicodeUnescaper(); 043 044 final String input = "\\uuuuuuuu0047"; 045 final String result = uu.translate(input); 046 assertEquals("Failed to unescape Unicode characters with many 'u' characters", "G", result); 047 } 048 049 @Test 050 public void testLessThanFour() { 051 final UnicodeUnescaper uu = new UnicodeUnescaper(); 052 053 final String input = "\\0047\\u006"; 054 try { 055 uu.translate(input); 056 fail("A lack of digits in a Unicode escape sequence failed to throw an exception"); 057 } catch(final IllegalArgumentException iae) { 058 // expected 059 } 060 } 061}