1/* 2 * Copyright (C) 2008 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 17package org.apache.harmony.luni.tests.java.util; 18 19import dalvik.annotation.TestTargets; 20import dalvik.annotation.TestLevel; 21import dalvik.annotation.TestTargetNew; 22import dalvik.annotation.TestTargetClass; 23 24import junit.framework.TestCase; 25 26import java.util.Formattable; 27import java.util.Formatter; 28 29@TestTargetClass(Formattable.class) 30public class FormattableTest extends TestCase { 31 32 class Mock_Formattable implements Formattable { 33 boolean flag = false; 34 35 public void formatTo(Formatter arg0, int arg1, int arg2, int arg3) { 36 StringBuilder sb = new StringBuilder(); 37 38 if (arg3 == 1) { 39 sb.append("single precision "); 40 } 41 if (arg3 == 2) { 42 sb.append("double precision "); 43 } 44 45 arg0.format(sb.toString()); 46 flag = true; 47 } 48 49 public boolean isFormatToCalled() { 50 return flag; 51 } 52 } 53 54 @TestTargetNew( 55 level = TestLevel.COMPLETE, 56 notes = "", 57 method = "formatTo", 58 args = {java.util.Formatter.class, int.class, int.class, int.class} 59 ) 60 public void testFormatTo() { 61 Formatter fmt = new Formatter(); 62 Mock_Formattable mf = new Mock_Formattable(); 63 64 assertTrue(fmt.format("%1.1s", mf).toString().equals("single precision ")); 65 assertTrue(fmt.format("%2.1s", mf).toString().equals("single precision single precision ")); 66 assertTrue(fmt.format("%2.2s", mf).toString().equals("single precision single precision double precision ")); 67 assertTrue(mf.isFormatToCalled()); 68 } 69 70} 71