Tests and fixes for dereferencing tags in Repository.resolve()
[egit/fonseca.git] / org.spearce.jgit.test / tst / org / spearce / jgit / lib / ConstantsEncodingTest.java
blob7b3e5a002cb6761e65e0462b8392247065bca539
1 /*
2 * Copyright (C) 2008, Google Inc.
4 * All rights reserved.
6 * Redistribution and use in source and binary forms, with or
7 * without modification, are permitted provided that the following
8 * conditions are met:
10 * - Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
13 * - Redistributions in binary form must reproduce the above
14 * copyright notice, this list of conditions and the following
15 * disclaimer in the documentation and/or other materials provided
16 * with the distribution.
18 * - Neither the name of the Git Development Community nor the
19 * names of its contributors may be used to endorse or promote
20 * products derived from this software without specific prior
21 * written permission.
23 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
24 * CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
25 * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
26 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
27 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
28 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
29 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
30 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
31 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
32 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
33 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
34 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
35 * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
38 package org.spearce.jgit.lib;
40 import java.io.UnsupportedEncodingException;
41 import java.util.Arrays;
43 import junit.framework.TestCase;
45 public class ConstantsEncodingTest extends TestCase {
46 public void testEncodeASCII_SimpleASCII()
47 throws UnsupportedEncodingException {
48 final String src = "abc";
49 final byte[] exp = { 'a', 'b', 'c' };
50 final byte[] res = Constants.encodeASCII(src);
51 assertTrue(Arrays.equals(exp, res));
52 assertEquals(src, new String(res, 0, res.length, "UTF-8"));
55 public void testEncodeASCII_FailOnNonASCII() {
56 final String src = "Ūnĭcōde̽";
57 try {
58 Constants.encodeASCII(src);
59 fail("Incorrectly accepted a Unicode character");
60 } catch (IllegalArgumentException err) {
61 assertEquals("Not ASCII string: " + src, err.getMessage());
65 public void testEncodeASCII_Number13() {
66 final long src = 13;
67 final byte[] exp = { '1', '3' };
68 final byte[] res = Constants.encodeASCII(src);
69 assertTrue(Arrays.equals(exp, res));
72 public void testEncode_SimpleASCII() throws UnsupportedEncodingException {
73 final String src = "abc";
74 final byte[] exp = { 'a', 'b', 'c' };
75 final byte[] res = Constants.encode(src);
76 assertTrue(Arrays.equals(exp, res));
77 assertEquals(src, new String(res, 0, res.length, "UTF-8"));
80 public void testEncode_Unicode() throws UnsupportedEncodingException {
81 final String src = "Ūnĭcōde̽";
82 final byte[] exp = { (byte) 0xC5, (byte) 0xAA, 0x6E, (byte) 0xC4,
83 (byte) 0xAD, 0x63, (byte) 0xC5, (byte) 0x8D, 0x64, 0x65,
84 (byte) 0xCC, (byte) 0xBD };
85 final byte[] res = Constants.encode(src);
86 assertTrue(Arrays.equals(exp, res));
87 assertEquals(src, new String(res, 0, res.length, "UTF-8"));