junitutil.java

来自「OLAP 的客户端代码」· Java 代码 · 共 39 行

JAVA
39
字号
package com.tonbeller.jpivot.olap.model;

import com.tonbeller.jpivot.olap.model.Cell;
import com.tonbeller.jpivot.olap.model.Member;
import com.tonbeller.jpivot.olap.model.Position;
import com.tonbeller.jpivot.olap.model.Result;

/**
 * Utilities for Junit tests
 */
public class JunitUtil {


  /**
   * assert position by members and values
   */
  static public void assertPosition(Result result, int iAxis, int iPos, String[] members,
      String[] formattedValues) {
    Position pos = (Position) result.getAxes()[iAxis].getPositions().get(iPos);
    int nPos0 = result.getAxes()[0].getPositions().size();
    for (int i = 0; i < pos.getMembers().length; i++) {
      Member m = pos.getMembers()[i];
      String s = m.getLabel();
      junit.framework.Assert.assertEquals(s, members[i]);
    }

    // cells of position ipos on axis 1 have the numbers ipos*nPos0 ... 
    int nCell = iPos * nPos0;
    for (int i = 0; i < formattedValues.length; i++) {
      Cell cell = (Cell) result.getCells().get(nCell + i);
      // we remove any non digit char 
      String cellval = cell.getFormattedValue().replaceAll("[^0-9]", "");
      String fval = formattedValues[i].replaceAll("[^0-9]", "");
      junit.framework.Assert.assertEquals(cellval, fval);
    }
  }

}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?