Home | History | Annotate | Download | only in sourcer
      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.Before;
     22 import org.junit.Test;
     23 import org.objectweb.asm.Opcodes;
     24 
     25 import java.io.StringWriter;
     26 
     27 /**
     28  *
     29  */
     30 public class MethodSourcerTest extends TestHelper {
     31 
     32     private StringWriter mWriter;
     33     private Output mOutput;
     34 
     35     @Before
     36     public void setUp() throws Exception {
     37         mWriter = new StringWriter();
     38         mOutput = new Output(mWriter);
     39     }
     40 
     41     @After
     42     public void tearDown() throws Exception {
     43         mWriter = null;
     44     }
     45 
     46     @Test
     47     public void testVoid() {
     48         MethodSourcer m = new MethodSourcer(mOutput,
     49                 "foo", //classname
     50                 Opcodes.ACC_PUBLIC, //access
     51                 "testVoid", //name
     52                 "()V", //desc
     53                 null, //signature
     54                 null); //exception
     55         m.visitEnd();
     56 
     57         assertSourceEquals(
     58                 "public void testVoid() { }",
     59                 mWriter.toString());
     60     }
     61 
     62     @Test
     63     public void testVoidThrow() {
     64         MethodSourcer m = new MethodSourcer(mOutput,
     65                 "foo", //classname
     66                 Opcodes.ACC_PUBLIC, //access
     67                 "testVoid", //name
     68                 "()V", //desc
     69                 null, //signature
     70                 new String[] { "java/lang/Exception" }); //exception
     71         m.visitEnd();
     72 
     73         assertSourceEquals(
     74                 "public void testVoid() throws java.lang.Exception { }",
     75                 mWriter.toString());
     76     }
     77 
     78     @Test
     79     public void testReturnMap() {
     80         MethodSourcer m = new MethodSourcer(mOutput,
     81                 "foo", //classname
     82                 Opcodes.ACC_PUBLIC, //access
     83                 "getMap_T_U", //name
     84                 "()Ljava/util/Map;", //desc
     85                 "()Ljava/util/Map<TT;TU;>;", //signature
     86                 null); //exception
     87         m.visitEnd();
     88 
     89         assertSourceEquals(
     90                 "public java.util.Map<T, U> getMap_T_U() { }",
     91                 mWriter.toString());
     92     }
     93 
     94 }
     95