1/* 2 * Copyright 2010 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 */ 16package com.google.android.testing.mocking; 17 18import junit.framework.TestCase; 19 20import java.io.File; 21import java.util.Vector; 22 23/** 24 * @author swoodward@google.com (Stephen Woodward) 25 */ 26public class FileUtilsTest extends TestCase { 27 public void testGetFilenameForClass() { 28 assertEquals(convertPathToNative("java/lang/Object.class"), 29 FileUtils.getFilenameFor(Object.class.getName())); 30 assertEquals(convertPathToNative( 31 "com/google/android/testing/mocking/FileUtilsTest$InnerClass.class"), 32 FileUtils.getFilenameFor(InnerClass.class.getName())); 33 } 34 35 public void testGetClassNameFor() { 36 assertEquals(convertPathToNative("java/lang/Object.class"), 37 FileUtils.getFilenameFor(Object.class.getName())); 38 assertEquals(convertPathToNative( 39 "com/google/android/testing/mocking/FileUtilsTest$InnerClass.class"), 40 FileUtils.getFilenameFor(InnerClass.class.getName())); 41 } 42 43 public void testGetInterfaceNameFor() { 44 assertEquals("v15.genmocks.java.util.VectorDelegateInterface", 45 FileUtils.getInterfaceNameFor(Vector.class, SdkVersion.CUPCAKE)); 46 assertEquals("v16.genmocks.java.util.VectorDelegateInterface", 47 FileUtils.getInterfaceNameFor(Vector.class, SdkVersion.DONUT)); 48 assertEquals("v201.genmocks.java.util.VectorDelegateInterface", 49 FileUtils.getInterfaceNameFor(Vector.class, SdkVersion.ECLAIR_0_1)); 50 assertEquals("v21.genmocks.java.util.VectorDelegateInterface", 51 FileUtils.getInterfaceNameFor(Vector.class, SdkVersion.ECLAIR_MR1)); 52 assertEquals("v22.genmocks.java.util.VectorDelegateInterface", 53 FileUtils.getInterfaceNameFor(Vector.class, SdkVersion.FROYO)); 54 assertEquals("genmocks.java.util.VectorDelegateInterface", 55 FileUtils.getInterfaceNameFor(Vector.class, SdkVersion.UNKNOWN)); 56 } 57 58 public void testGetSubclassNameFor() { 59 assertEquals("v15.genmocks.java.util.VectorDelegateSubclass", 60 FileUtils.getSubclassNameFor(Vector.class, SdkVersion.CUPCAKE)); 61 assertEquals("v16.genmocks.java.util.VectorDelegateSubclass", 62 FileUtils.getSubclassNameFor(Vector.class, SdkVersion.DONUT)); 63 assertEquals("v201.genmocks.java.util.VectorDelegateSubclass", 64 FileUtils.getSubclassNameFor(Vector.class, SdkVersion.ECLAIR_0_1)); 65 assertEquals("v21.genmocks.java.util.VectorDelegateSubclass", 66 FileUtils.getSubclassNameFor(Vector.class, SdkVersion.ECLAIR_MR1)); 67 assertEquals("v22.genmocks.java.util.VectorDelegateSubclass", 68 FileUtils.getSubclassNameFor(Vector.class, SdkVersion.FROYO)); 69 assertEquals("genmocks.java.util.VectorDelegateSubclass", 70 FileUtils.getSubclassNameFor(Vector.class, SdkVersion.UNKNOWN)); 71 } 72 73 private String convertPathToNative(String path) { 74 return path.replace('/', File.separatorChar).replace('\\', File.separatorChar); 75 } 76 77 class InnerClass { 78 } 79} 80