1/* 2 * Copyright 2012 AndroidPlot.com 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 com.androidplot.xy; 18 19import android.content.Context; 20import android.graphics.*; 21import android.os.Handler; 22import android.util.Log; 23import android.view.View; 24import com.androidplot.util.FontUtils; 25import com.androidplot.util.PixelUtils; 26import com.androidplot.util.ValPixConverter; 27import mockit.*; 28import org.junit.After; 29import org.junit.Before; 30import org.junit.Test; 31 32import static junit.framework.Assert.assertEquals; 33 34@UsingMocksAndStubs({Log.class,View.class,Handler.class,Paint.class,Color.class, Rect.class, RectF.class, 35 FontUtils.class, PixelUtils.class, Canvas.class}) 36 37public class XYSeriesRendererTest { 38 39 @MockClass(realClass = Context.class) 40 public static class MockContext {} 41 42 @Before 43 public void setUp() throws Exception { 44 45 } 46 47 @After 48 public void tearDown() throws Exception { 49 50 } 51 52 53 @Test 54 public void testDataToGridCorrelation() throws Exception { 55 Context context = Mockit.setUpMock(new MockContext()); 56 //RectF gridRect = Mockit.setUpMock(new MockRectF()); 57 //Mockit.setUpMock(RectF.class, new MockRectF()); 58 //@MockClass(realClass = RectF.class) 59 new MockUp<RectF>() 60 { 61 final float left = 5; 62 final float top = 5; 63 final float right = 104; 64 final float bottom = 104; 65 66 @Mock void $init() {} 67 68 @Mock float width() {return 100;} 69 @Mock float height() {return 100;} 70 71 }; 72 RectF gridRect = new RectF(); 73 XYPlot plot = new XYPlot(context, "Test"); 74 plot.setDomainStepMode(XYStepMode.SUBDIVIDE); 75 plot.setDomainStepValue(10); 76 plot.setDomainBoundaries(0, 100, BoundaryMode.FIXED); 77 plot.setRangeBoundaries(0, 100, BoundaryMode.FIXED); 78 plot.calculateMinMaxVals(); 79 XYStep domainStep = XYStepCalculator.getStep(plot, XYAxisType.DOMAIN, gridRect, plot.getCalculatedMinX().doubleValue(), plot.getCalculatedMaxX().doubleValue()); 80 81 float width = gridRect.width(); 82 83 int x = 0; 84 float val = ValPixConverter.valToPix(x, 0, 9, gridRect.width(), false) + (gridRect.left); 85 86 assertEquals(val, domainStep.getStepPix()*x); 87 88 x = 1; 89 val = ValPixConverter.valToPix(x, 0, 9, gridRect.width(), false) + (gridRect.left); 90 91 assertEquals(val, domainStep.getStepPix()*x); 92 93 x = 9; 94 val = ValPixConverter.valToPix(x, 0, 9, gridRect.width(), false) + (gridRect.left); 95 96 assertEquals(val, domainStep.getStepPix()*x); 97 } 98 99} 100