Package org.yaac.server.egql

Source Code of org.yaac.server.egql.EvaluationWithContextTest

package org.yaac.server.egql;

import static org.junit.Assert.assertEquals;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
import static org.yaac.server.egql.TestUtil.evaluate;

import java.math.BigDecimal;

import org.junit.Test;
import org.yaac.server.egql.evaluator.EvaluationResult;
import org.yaac.server.egql.processor.ProcessData.ProcessDataRecord;

/**
* everything related to evaluation context
*
* with and without alias
*
* @author Max Zhu (thebbsky@gmail.com)
*
*/
public class EvaluationWithContextTest {

  @Test
  public void test1() throws Exception {   
    ProcessDataRecord record = mock(ProcessDataRecord.class);
    when(record.lookup("a")).thenReturn(new EvaluationResult(null, null, null, new BigDecimal("1.5")));
   
    assertEquals(new EvaluationResult(new BigDecimal("5.5")), evaluate("4 + a", record));
  }
 
  @Test
  public void test2() throws Exception {   
    ProcessDataRecord record = mock(ProcessDataRecord.class);
    when(record.lookup("a")).thenReturn(new EvaluationResult(null, null, null, new BigDecimal("1.5")));
    when(record.lookup("b")).thenReturn(new EvaluationResult(null, null, null, new BigDecimal("4.5")));
   
    assertEquals(new BigDecimal("3"), evaluate("b / a", record).getPayload());
  }
}
TOP

Related Classes of org.yaac.server.egql.EvaluationWithContextTest

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.