KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > tonbeller > jpivot > olap > model > JunitUtil


1 package com.tonbeller.jpivot.olap.model;
2
3 import com.tonbeller.jpivot.olap.model.Cell;
4 import com.tonbeller.jpivot.olap.model.Member;
5 import com.tonbeller.jpivot.olap.model.Position;
6 import com.tonbeller.jpivot.olap.model.Result;
7
8 /**
9  * Utilities for Junit tests
10  */

11 public class JunitUtil {
12
13
14   /**
15    * assert position by members and values
16    */

17   static public void assertPosition(Result result, int iAxis, int iPos, String JavaDoc[] members,
18       String JavaDoc[] formattedValues) {
19     Position pos = (Position) result.getAxes()[iAxis].getPositions().get(iPos);
20     int nPos0 = result.getAxes()[0].getPositions().size();
21     for (int i = 0; i < pos.getMembers().length; i++) {
22       Member m = pos.getMembers()[i];
23       String JavaDoc s = m.getLabel();
24       junit.framework.Assert.assertEquals(s, members[i]);
25     }
26
27     // cells of position ipos on axis 1 have the numbers ipos*nPos0 ...
28
int nCell = iPos * nPos0;
29     for (int i = 0; i < formattedValues.length; i++) {
30       Cell cell = (Cell) result.getCells().get(nCell + i);
31       // we remove any non digit char
32
String JavaDoc cellval = cell.getFormattedValue().replaceAll("[^0-9]", "");
33       String JavaDoc fval = formattedValues[i].replaceAll("[^0-9]", "");
34       junit.framework.Assert.assertEquals(cellval, fval);
35     }
36   }
37
38 }
39
Popular Tags