2 * Copyright (C) 2008 The Android Open Source Project
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
18 package com.android.tools.layoutlib.create;
21 import static org.junit.Assert.assertArrayEquals;
23 import com.android.tools.layoutlib.create.LogTest.MockLog;
25 import org.junit.After;
26 import org.junit.Before;
27 import org.junit.Test;
30 import java.io.IOException;
32 import java.util.ArrayList;
36 * Unit tests for some methods of {@link AsmGenerator}.
38 public class AsmGeneratorTest {
41 private ArrayList<String> mOsJarPath;
42 private String mOsDestJar;
43 private File mTempFile;
46 public void setUp() throws Exception {
47 mLog = new LogTest.MockLog();
48 URL url = this.getClass().getClassLoader().getResource("data/mock_android.jar");
50 mOsJarPath = new ArrayList<String>();
51 mOsJarPath.add(url.getFile());
53 mTempFile = File.createTempFile("mock", "jar");
54 mOsDestJar = mTempFile.getAbsolutePath();
55 mTempFile.deleteOnExit();
59 public void tearDown() throws Exception {
60 if (mTempFile != null) {
67 public void testClassRenaming() throws IOException, LogAbortException {
69 AsmGenerator agen = new AsmGenerator(mLog, mOsDestJar,
70 null, // classes to inject in the final JAR
71 null, // methods to force override
72 new String[] { // classes to rename (so that we can replace them)
73 "mock_android.view.View", "mock_android.view._Original_View",
74 "not.an.actual.ClassName", "anoter.fake.NewClassName",
76 null // methods deleted from their return type.
79 AsmAnalyzer aa = new AsmAnalyzer(mLog, mOsJarPath, agen,
81 new String[] { // include classes
87 Set<String> notRenamed = agen.getClassesNotRenamed();
88 assertArrayEquals(new String[] { "not/an/actual/ClassName" }, notRenamed.toArray());