1 /* 2 * Copyright (C) 2009 The Android Open Source Project 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.android.mkstubs.sourcer; 18 19 20 import org.junit.After; 21 import org.junit.Assert; 22 import org.junit.Before; 23 import org.junit.Test; 24 import org.objectweb.asm.Opcodes; 25 26 import java.io.StringWriter; 27 28 /** 29 * 30 */ 31 public class FieldSourcerTest { 32 33 private StringWriter mWriter; 34 35 @Before 36 public void setUp() throws Exception { 37 mWriter = new StringWriter(); 38 } 39 40 @After 41 public void tearDown() throws Exception { 42 mWriter = null; 43 } 44 45 @Test 46 public void testStringField() throws Exception { 47 48 FieldSourcer fs = new FieldSourcer(new Output(mWriter), 49 Opcodes.ACC_PUBLIC, // access 50 "mArg", // name 51 "Ljava/lang/String;", // desc 52 null // signature 53 ); 54 fs.visitEnd(); 55 56 String s = mWriter.toString(); 57 Assert.assertEquals("public java.lang.String mArg;\n", s); 58 } 59 60 @Test 61 public void testTemplateTypeField() throws Exception { 62 63 FieldSourcer fs = new FieldSourcer(new Output(mWriter), 64 Opcodes.ACC_PRIVATE | Opcodes.ACC_FINAL, // access 65 "mList", // name 66 "Ljava/util/ArrayList;", // desc 67 "Ljava/util/ArrayList<Ljava/lang/String;>;" // signature 68 ); 69 fs.visitEnd(); 70 71 String s = mWriter.toString(); 72 Assert.assertEquals("private final java.util.ArrayList<java.lang.String> mList;\n", s); 73 } 74 75 } 76