• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /**
2  * Copyright 2007 Google Inc.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 package com.tonicsystems.jarjar;
18 
19 import junit.framework.*;
20 
21 import java.util.Collections;
22 
23 public class PackageRemapperTest
24 extends TestCase
25 {
26     protected PackageRemapper remapper;
27 
setUp()28     protected void setUp() {
29         Rule rule = new Rule();
30         rule.setPattern("org.**");
31         rule.setResult("foo.@1");
32         remapper = new PackageRemapper(Collections.singletonList(rule), false);
33     }
34 
testMapValue()35     public void testMapValue() {
36       assertUnchangedValue("[^\\s;/@&=,.?:+$]");
37       assertUnchangedValue("[Ljava/lang/Object;");
38       assertUnchangedValue("[Lorg/example/Object;");
39       assertUnchangedValue("[Ljava.lang.Object;");
40       assertUnchangedValue("[Lorg.example/Object;");
41       assertUnchangedValue("[L;");
42       assertUnchangedValue("[Lorg.example.Object;;");
43       assertUnchangedValue("[Lorg.example.Obj ct;");
44       assertUnchangedValue("org.example/Object");
45 
46       assertEquals("[Lfoo.example.Object;", remapper.mapValue("[Lorg.example.Object;"));
47       assertEquals("foo.example.Object", remapper.mapValue("org.example.Object"));
48       assertEquals("foo/example/Object", remapper.mapValue("org/example/Object"));
49       assertEquals("foo/example.Object", remapper.mapValue("org/example.Object")); // path match
50 
51       assertEquals("foo.example.package-info", remapper.mapValue("org.example.package-info"));
52       assertEquals("foo/example/package-info", remapper.mapValue("org/example/package-info"));
53       assertEquals("foo/example.package-info", remapper.mapValue("org/example.package-info"));
54     }
55 
assertUnchangedValue(String value)56     private void assertUnchangedValue(String value) {
57         assertEquals(value, remapper.mapValue(value));
58     }
59 }
60