Java 类org.mockito.internal.stubbing.answers.CallsRealMethods 实例源码
项目:monarch
文件:RemoteOperationMessageTest.java
@Before
public void setUp() throws InterruptedException {
cache = Fakes.cache();
dm = mock(DistributionManager.class);
msg = mock(RemoteOperationMessage.class);
r = mock(LocalRegion.class);
txMgr = mock(TXManagerImpl.class);
tx = mock(TXStateProxyImpl.class);
when(msg.checkCacheClosing(dm)).thenReturn(false);
when(msg.checkDSClosing(dm)).thenReturn(false);
when(msg.getCache(dm)).thenReturn(cache);
when(msg.getRegionByPath(cache)).thenReturn(r);
when(msg.getTXManager(cache)).thenReturn(txMgr);
doAnswer(new CallsRealMethods()).when(msg).process(dm);
}
项目:monarch
文件:PartitionMessageTest.java
@Before
public void setUp() throws PRLocallyDestroyedException, InterruptedException {
cache = Fakes.cache();
dm = mock(DistributionManager.class);
msg = mock(PartitionMessage.class);
pr = mock(PartitionedRegion.class);
txMgr = mock(TXManagerImpl.class);
tx = mock(TXStateProxyImpl.class);
when(msg.checkCacheClosing(dm)).thenReturn(false);
when(msg.checkDSClosing(dm)).thenReturn(false);
when(msg.getPartitionedRegion()).thenReturn(pr);
when(msg.getGemFireCacheImpl()).thenReturn(cache);
when(msg.getStartPartitionMessageProcessingTime(pr)).thenReturn(startTime);
when(msg.getTXManagerImpl(cache)).thenReturn(txMgr);
doAnswer(new CallsRealMethods()).when(msg).process(dm);
}
项目:springmock
文件:MockitoDoubleConfigurationParserTest.java
@Test
public void should_override_default_answer_for_spy_beans() {
//given
final MockitoDoubleConfiguration configuration = configurationParser.parseSpyConfiguration(ANY_NAME, AnyTest.withAnswer());
//when
configuration.createMockSettings(mockSettings);
//then
final InOrder defaultAnswer = Mockito.inOrder(mockSettings);
defaultAnswer
.verify(mockSettings)
.defaultAnswer(argThat(HasDefaultAnswer.hasAnswerOfType(CallsRealMethods.class)));
defaultAnswer
.verify(mockSettings)
.defaultAnswer(argThat(HasDefaultAnswer.hasAnswerOfType(DoesNothing.class)));
}
项目:pulsar-reporting-api
文件:AbstracDataSourceProviderFactoryTest.java
@Test
public void testFactory() {
DBConnector collector=Mockito.mock(
DBConnector.class);
Table table=new Table();
table.setTableName("tst");
Mockito.when(collector.getAllTables()).thenReturn(Sets.newHashSet("tst"));
Mockito.when(collector.getTableMeta("tst")).thenReturn(table);
AbstractDataSourceProviderFactory factory = Mockito.mock(AbstractDataSourceProviderFactory.class,
new CallsRealMethods());
Mockito.doReturn(collector)
.when(factory)
.getDBCollector(Matchers.any(DataSourceConfiguration.class));
DataSourceConfiguration configuration = new DataSourceConfiguration(
DataSourceTypeEnum.DRUID, "testdb");
configuration.setEndPoint(Lists.newArrayList("http://test")); assertEquals(Lists.newArrayList(table),factory.create(configuration).getTables());
}
项目:springmock
文件:MockitoDoubleConfigurationParserTest.java
@Test
public void should_set_default_answer_for_spy_beans() {
//given
final MockitoDoubleConfiguration configuration = configurationParser.parseSpyConfiguration(ANY_NAME, AnyTest.spy());
//when
configuration.createMockSettings(mockSettings);
//then
Mockito
.verify(mockSettings)
.defaultAnswer(argThat(HasDefaultAnswer.hasAnswerOfType(CallsRealMethods.class)));
}
项目:pulsar-reporting-api
文件:SQLTranslatorTest.java
@SuppressWarnings("unchecked")
@Test
public void testParse() {
String sql = "select count(clickcount_ag) as \"clickcount_ag\", testdim from tabletest group by testdim limit 100";
SQLTranslator sqlTranslator = Mockito.mock(SQLTranslator.class,
new CallsRealMethods());
Mockito.doReturn("")
.when(sqlTranslator)
.checkNameChange(Mockito.any(ColumnReference.class),
Mockito.any(Table.class), Mockito.any(Map.class));
assertEquals("tabletest", sqlTranslator.getTableName(sql));
QueryDescription queryDesc = sqlTranslator.parse(sql);
SelectNode selectNode = queryDesc.getSelectNode();
TableDimension dimension = new TableDimension();
dimension.setName("testdim");
dimension.setType(0);
dimension.setMultiValue(true);
assertEquals("testdim", dimension.getName());
assertEquals(0, dimension.getType());
TableDimension metric2 = new TableDimension();
metric2.setName("clickcount_ag");
metric2.setType(0);
metric2.setMultiValue(true);
List<TableDimension> metrics = new ArrayList<TableDimension>();
metrics.add(metric2);
Table table = new Table();
table.setTableName("tabletest");
table.setNoInnerJoin(false);
table.setDateColumn("testDate");
table.setDimensions(Lists.newArrayList(dimension));
table.setMetrics(metrics);
assertTrue(sqlTranslator.parseResultList(selectNode, table)
.getDimensions().contains("testdim"));
}
项目:pulsar-reporting-api
文件:SQLTranslatorTest.java
@SuppressWarnings("unchecked")
@Test
public void testInvalidAggregate() {
String sql = "select count(*) as testdim from tabletest where (site=0 or not(region='11')) order by notexist";
SQLTranslator sqlTranslator = Mockito.mock(SQLTranslator.class,
new CallsRealMethods());
Mockito.doReturn("")
.when(sqlTranslator)
.checkNameChange(Mockito.any(ColumnReference.class),
Mockito.any(Table.class), Mockito.any(Map.class));
assertEquals("tabletest", sqlTranslator.getTableName(sql));
sqlTranslator.parse(sql);
AggregateNode node =Mockito.mock(AggregateNode.class);
Mockito.when(node.getAggregateName()).thenReturn("countall");
TableDimension dimension = new TableDimension();
dimension.setName("testDim");
dimension.setType(0);
dimension.setMultiValue(true);
assertEquals("testDim", dimension.getName());
assertEquals(0, dimension.getType());
Table table = new Table();
table.setTableName("tabletest");
table.setNoInnerJoin(false);
table.setDateColumn("testDate");
table.setDimensions(Lists.newArrayList(dimension));
try {
sqlTranslator.getAggregateKey(node, table,null,true);
fail("expected SqlTranslationException");
} catch (SqlTranslationException ex) {
assertTrue(true);
}
}
项目:pulsar-reporting-api
文件:SQLTranslatorTest.java
@SuppressWarnings("unchecked")
@Test
public void testCountAll() {
String sql = "select count(*) as testdim from tabletest where (site=0 or not(region='11')) order by notexist";
SQLTranslator sqlTranslator = Mockito.mock(SQLTranslator.class,
new CallsRealMethods());
Mockito.doReturn("")
.when(sqlTranslator)
.checkNameChange(Mockito.any(ColumnReference.class),
Mockito.any(Table.class), Mockito.any(Map.class));
assertEquals("tabletest", sqlTranslator.getTableName(sql));
sqlTranslator.parse(sql);
AggregateNode node =Mockito.mock(AggregateNode.class);
Mockito.when(node.getAggregateName()).thenReturn("count(*)");
TableDimension dimension = new TableDimension();
dimension.setName("testDim");
dimension.setType(0);
dimension.setMultiValue(true);
assertEquals("testDim", dimension.getName());
assertEquals(0, dimension.getType());
Table table = new Table();
table.setTableName("tabletest");
table.setNoInnerJoin(false);
table.setDateColumn("testDate");
table.setDimensions(Lists.newArrayList(dimension));
assertEquals("countall",sqlTranslator.getAggregateKey(node, table,null,true));
}
项目:pulsar-reporting-api
文件:SQLTranslatorTest.java
@SuppressWarnings("unchecked")
@Test
public void testGetAggregate() {
String sql = "select count(testdim) as testdim from tabletest where (site=0 or not(region='11')) order by notexist";
SQLTranslator sqlTranslator = Mockito.mock(SQLTranslator.class,
new CallsRealMethods());
Mockito.doReturn("")
.when(sqlTranslator)
.checkNameChange(Mockito.any(ColumnReference.class),
Mockito.any(Table.class), Mockito.any(Map.class));
assertEquals("tabletest", sqlTranslator.getTableName(sql));
sqlTranslator.parse(sql);
AggregateNode node =Mockito.mock(AggregateNode.class);
Mockito.when(node.getAggregateName()).thenReturn("count");
Mockito.when(node.isDistinct()).thenReturn(true);
ColumnReference cNode=new ColumnReference();
TableName name=new TableName();
cNode.init("test",name);
Mockito.when(node.getOperand()).thenReturn(cNode);
TableDimension dimension = new TableDimension();
dimension.setName("testDim");
dimension.setType(0);
dimension.setMultiValue(true);
assertEquals("testDim", dimension.getName());
assertEquals(0, dimension.getType());
Table table = new Table();
table.setTableName("tabletest");
table.setNoInnerJoin(false);
table.setDateColumn("testDate");
table.setDimensions(Lists.newArrayList(dimension));
try {
sqlTranslator.getAggregateKey(node, table,null,false);
} catch (SqlTranslationException ex) {
fail("unexpected SqlTranslationException");
}
}
项目:pulsar-reporting-api
文件:SQLTranslatorTest.java
@SuppressWarnings("unchecked")
@Test
public void testGetAggregateNumericConstantNode() throws StandardException {
String sql = "select count(testdim) as testdim from tabletest where (site=0 or not(region='11')) order by notexist";
SQLTranslator sqlTranslator = Mockito.mock(SQLTranslator.class,
new CallsRealMethods());
Mockito.doReturn("")
.when(sqlTranslator)
.checkNameChange(Mockito.any(ColumnReference.class),
Mockito.any(Table.class), Mockito.any(Map.class));
assertEquals("tabletest", sqlTranslator.getTableName(sql));
sqlTranslator.parse(sql);
AggregateNode node =Mockito.mock(AggregateNode.class);
Mockito.when(node.getAggregateName()).thenReturn("count");
Mockito.when(node.isDistinct()).thenReturn(true);
NumericConstantNode nNode=new NumericConstantNode();
Mockito.when(node.getOperand()).thenReturn(nNode);
TableDimension dimension = new TableDimension();
dimension.setName("testDim");
dimension.setType(0);
dimension.setMultiValue(true);
assertEquals("testDim", dimension.getName());
assertEquals(0, dimension.getType());
Table table = new Table();
table.setTableName("tabletest");
table.setNoInnerJoin(false);
table.setDateColumn("testDate");
table.setDimensions(Lists.newArrayList(dimension));
try {
sqlTranslator.getAggregateKey(node, table,null,false);
fail("expected SqlTranslationException");
} catch (SqlTranslationException ex) {
assertTrue(true);
}
}
项目:pulsar-reporting-api
文件:SQLTranslatorTest.java
@SuppressWarnings("unchecked")
@Test
public void testGetAggregateNumericConstantNodeNot1() throws StandardException {
String sql = "select count(testdim) as testdim from tabletest where (site=0 or not(region='11')) order by notexist";
SQLTranslator sqlTranslator = Mockito.mock(SQLTranslator.class,
new CallsRealMethods());
Mockito.doReturn("")
.when(sqlTranslator)
.checkNameChange(Mockito.any(ColumnReference.class),
Mockito.any(Table.class), Mockito.any(Map.class));
assertEquals("tabletest", sqlTranslator.getTableName(sql));
sqlTranslator.parse(sql);
AggregateNode node =Mockito.mock(AggregateNode.class);
Mockito.when(node.getAggregateName()).thenReturn("count");
Mockito.when(node.isDistinct()).thenReturn(true);
NumericConstantNode nNode=new NumericConstantNode();
nNode.setValue(2);
Mockito.when(node.getOperand()).thenReturn(nNode);
TableDimension dimension = new TableDimension();
dimension.setName("testDim");
dimension.setType(0);
dimension.setMultiValue(true);
assertEquals("testDim", dimension.getName());
assertEquals(0, dimension.getType());
Table table = new Table();
table.setTableName("tabletest");
table.setNoInnerJoin(false);
table.setDateColumn("testDate");
table.setDimensions(Lists.newArrayList(dimension));
try {
sqlTranslator.getAggregateKey(node, table,null,false);
fail("expected SqlTranslationException");
} catch (SqlTranslationException ex) {
assertTrue(true);
}
}
项目:pulsar-reporting-api
文件:SQLTranslatorTest.java
@SuppressWarnings("unchecked")
@Test
public void testGetAggregateNumericConstantNodeNotInt() throws StandardException {
String sql = "select count(testdim) as testdim from tabletest where (site=0 or not(region='11')) order by notexist";
SQLTranslator sqlTranslator = Mockito.mock(SQLTranslator.class,
new CallsRealMethods());
Mockito.doReturn("")
.when(sqlTranslator)
.checkNameChange(Mockito.any(ColumnReference.class),
Mockito.any(Table.class), Mockito.any(Map.class));
assertEquals("tabletest", sqlTranslator.getTableName(sql));
sqlTranslator.parse(sql);
AggregateNode node =Mockito.mock(AggregateNode.class);
Mockito.when(node.getAggregateName()).thenReturn("count");
Mockito.when(node.isDistinct()).thenReturn(true);
NumericConstantNode nNode=new NumericConstantNode();
nNode.setValue("test");
Mockito.when(node.getOperand()).thenReturn(nNode);
TableDimension dimension = new TableDimension();
dimension.setName("testDim");
dimension.setType(0);
dimension.setMultiValue(true);
assertEquals("testDim", dimension.getName());
assertEquals(0, dimension.getType());
Table table = new Table();
table.setTableName("tabletest");
table.setNoInnerJoin(false);
table.setDateColumn("testDate");
table.setDimensions(Lists.newArrayList(dimension));
try {
sqlTranslator.getAggregateKey(node, table,null,false);
fail("expected SqlTranslationException");
} catch (SqlTranslationException ex) {
assertTrue(true);
}
}
项目:pulsar-reporting-api
文件:SQLTranslatorTest.java
@SuppressWarnings("unchecked")
@Test
public void testGetUnsupportAggregate() throws StandardException {
String sql = "select count(testdim) as testdim from tabletest where (site=0 or not(region='11')) order by notexist";
SQLTranslator sqlTranslator = Mockito.mock(SQLTranslator.class,
new CallsRealMethods());
Mockito.doReturn("")
.when(sqlTranslator)
.checkNameChange(Mockito.any(ColumnReference.class),
Mockito.any(Table.class), Mockito.any(Map.class));
assertEquals("tabletest", sqlTranslator.getTableName(sql));
sqlTranslator.parse(sql);
AggregateNode node =Mockito.mock(AggregateNode.class);
Mockito.when(node.getAggregateName()).thenReturn("count");
Mockito.when(node.isDistinct()).thenReturn(true);
Mockito.when(node.getOperand()).thenReturn(null);
TableDimension dimension = new TableDimension();
dimension.setName("testDim");
dimension.setType(0);
dimension.setMultiValue(true);
assertEquals("testDim", dimension.getName());
assertEquals(0, dimension.getType());
Table table = new Table();
table.setTableName("tabletest");
table.setNoInnerJoin(false);
table.setDateColumn("testDate");
table.setDimensions(Lists.newArrayList(dimension));
try {
sqlTranslator.getAggregateKey(node, table,null,false);
fail("expected SqlTranslationException");
} catch (SqlTranslationException ex) {
assertTrue(true);
}
}
项目:joynr
文件:AbstractTypeUtilTest.java
@Test
public void testMultipleOutParameters() throws Exception {
URL fixtureURL = AbstractTypeUtilTest.class.getResource("MultipleOutParameters.fidl");
ModelLoader loader = new ModelLoader(fixtureURL.getPath());
Resource fixtureResource = loader.getResources().iterator().next();
class MyCallsRealMethods extends CallsRealMethods {
private static final long serialVersionUID = 1L;
@Override
public Object answer(InvocationOnMock invocation) throws Throwable {
if (invocation.getMethod().getName().equals("getTypeName")) {
Class<?> parameterType0 = invocation.getMethod().getParameterTypes()[0];
if (parameterType0.equals(FBasicTypeId.class)) {
return ((FBasicTypeId) invocation.getArguments()[0]).getName();
} else if (parameterType0.equals(FType.class)) {
return ((FType) invocation.getArguments()[0]).getName();
} else {
return super.answer(invocation);
}
} else {
return super.answer(invocation);
}
}
}
AbstractTypeUtil typeUtil = mock(AbstractTypeUtil.class, new MyCallsRealMethods());
Guice.createInjector().injectMembers(typeUtil);
FModel model = (FModel) fixtureResource.getContents().get(0);
String stringDatatype = FBasicTypeId.STRING.getName();
String numberDatatype = FBasicTypeId.INT16.getName();
String complexDatatype = model.getTypeCollections().get(0).getTypes().get(0).getName();
FMethod fixture = model.getInterfaces().get(0).getMethods().get(0);
Iterator<String> result = typeUtil.getTypeNamesForOutputParameter(fixture).iterator();
assertEquals(result.next(), stringDatatype);
assertEquals(result.next(), numberDatatype);
assertEquals(result.next(), complexDatatype);
assertFalse(result.hasNext());
}
项目:pulsar-reporting-api
文件:SQLTranslatorTest.java
@SuppressWarnings("unchecked")
@Test
public void testParseCount() {
String sql = "select count(distinct(testdim)) as testdim from tabletest where (site=0 or not(region='11')) order by notexist";
SQLTranslator sqlTranslator = Mockito.mock(SQLTranslator.class,
new CallsRealMethods());
Mockito.doReturn("")
.when(sqlTranslator)
.checkNameChange(Mockito.any(ColumnReference.class),
Mockito.any(Table.class), Mockito.any(Map.class));
assertEquals("tabletest", sqlTranslator.getTableName(sql));
QueryDescription queryDesc = sqlTranslator.parse(sql);
SelectNode selectNode = queryDesc.getSelectNode();
TableDimension dimension = new TableDimension();
dimension.setName("testdim");
dimension.setType(0);
dimension.setMultiValue(true);
assertEquals("testdim", dimension.getName());
assertEquals(0, dimension.getType());
TableDimension metric = new TableDimension();
metric.setName("count");
metric.setType(0);
metric.setMultiValue(true);
TableDimension metric2 = new TableDimension();
metric2.setName("clickcount_ag");
metric2.setType(0);
metric2.setMultiValue(true);
List<TableDimension> metrics = new ArrayList<TableDimension>();
metrics.add(metric2);
metrics.add(metric);
Table table = new Table();
table.setTableName("tabletest");
table.setNoInnerJoin(false);
table.setDateColumn("testDate");
table.setDimensions(Lists.newArrayList(dimension));
table.setMetrics(metrics);
assertTrue(sqlTranslator.parseResultList(selectNode, table)
.getSimpleAggregateColsMap().containsKey("testdim"));
assertTrue(sqlTranslator.parseResultList(selectNode, table)
.getAggrKeyToAliasMap().containsValue("testdim"));
}
项目:pulsar-reporting-api
文件:SQLTranslatorTest.java
@SuppressWarnings("unchecked")
@Test
public void testParseBinary() {
String sql = "select testdim*2 as testdim from tabletest where (site=0 or not(region='11')) order by notexist";
SQLTranslator sqlTranslator = Mockito.mock(SQLTranslator.class,
new CallsRealMethods());
Mockito.doReturn("")
.when(sqlTranslator)
.checkNameChange(Mockito.any(ColumnReference.class),
Mockito.any(Table.class), Mockito.any(Map.class));
assertEquals("tabletest", sqlTranslator.getTableName(sql));
QueryDescription queryDesc = sqlTranslator.parse(sql);
SelectNode selectNode = queryDesc.getSelectNode();
TableDimension dimension = new TableDimension();
dimension.setName("testdim");
dimension.setType(0);
dimension.setMultiValue(true);
assertEquals("testdim", dimension.getName());
assertEquals(0, dimension.getType());
TableDimension metric = new TableDimension();
metric.setName("count");
metric.setType(0);
metric.setMultiValue(true);
TableDimension metric2 = new TableDimension();
metric2.setName("clickcount_ag");
metric2.setType(0);
metric2.setMultiValue(true);
List<TableDimension> metrics = new ArrayList<TableDimension>();
metrics.add(metric2);
metrics.add(metric);
Table table = new Table();
table.setTableName("tabletest");
table.setNoInnerJoin(false);
table.setDateColumn("testDate");
table.setDimensions(Lists.newArrayList(dimension));
table.setMetrics(metrics);
assertTrue(sqlTranslator.parseResultList(selectNode, table)
.getAggrKeyToAliasMap().containsValue("testdim"));
}
项目:pulsar-reporting-api
文件:SQLTranslatorTest.java
@SuppressWarnings("unchecked")
@Test
public void testParseOderBy() {
String sql = "select count(1) as testdim from tabletest where (site=0 or not(region='11')) order by testdim";
SQLTranslator sqlTranslator = Mockito.mock(SQLTranslator.class,
new CallsRealMethods());
Mockito.doReturn("")
.when(sqlTranslator)
.checkNameChange(Mockito.any(ColumnReference.class),
Mockito.any(Table.class), Mockito.any(Map.class));
assertEquals("tabletest", sqlTranslator.getTableName(sql));
QueryDescription queryDesc = sqlTranslator.parse(sql);
SelectNode selectNode = queryDesc.getSelectNode();
TableDimension dimension = new TableDimension();
dimension.setName("testdim");
dimension.setType(0);
dimension.setMultiValue(true);
assertEquals("testdim", dimension.getName());
assertEquals(0, dimension.getType());
TableDimension metric = new TableDimension();
metric.setName("count");
metric.setType(0);
metric.setMultiValue(true);
TableDimension metric2 = new TableDimension();
metric2.setName("clickcount_ag");
metric2.setType(0);
metric2.setMultiValue(true);
List<TableDimension> metrics = new ArrayList<TableDimension>();
metrics.add(metric2);
metrics.add(metric);
Table table = new Table();
table.setTableName("tabletest");
table.setNoInnerJoin(false);
table.setDateColumn("testDate");
table.setDimensions(Lists.newArrayList(dimension));
table.setMetrics(metrics);
assertTrue(sqlTranslator.parseResultList(selectNode, table)
.getAggrKeyToAliasMap().containsValue("testdim"));
}
项目:pulsar-reporting-api
文件:SQLTranslatorTest.java
@SuppressWarnings("unchecked")
@Test
public void testAddCompositeAggregateNode() throws StandardException{
String sql = "select count(testdim) as testdim from tabletest where (site=0 or not(region='11')) order by notexist";
SQLTranslator sqlTranslator = Mockito.mock(SQLTranslator.class,
new CallsRealMethods());
Mockito.doReturn("")
.when(sqlTranslator)
.checkNameChange(Mockito.any(ColumnReference.class),
Mockito.any(Table.class), Mockito.any(Map.class));
assertEquals("tabletest", sqlTranslator.getTableName(sql));
sqlTranslator.parse(sql);
AggregateNode node =Mockito.mock(AggregateNode.class);
Mockito.when(node.getAggregateName()).thenReturn("count");
Mockito.when(node.isDistinct()).thenReturn(true);
NumericConstantNode nNode=new NumericConstantNode();
nNode.setValue(1);
Mockito.when(node.getOperand()).thenReturn(nNode);
TableDimension dimension = new TableDimension();
dimension.setName("testDim");
dimension.setType(0);
dimension.setMultiValue(true);
assertEquals("testDim", dimension.getName());
assertEquals(0, dimension.getType());
Table table = new Table();
table.setTableName("tabletest");
table.setNoInnerJoin(false);
table.setDateColumn("testDate");
table.setDimensions(Lists.newArrayList(dimension));
Map<String, AggregateNode> aggregateNodesMap =new HashMap<String, AggregateNode>();
aggregateNodesMap.put("count", node);
Map<String, String> aggrKeyToAliasMap =new HashMap<String, String>();
try {
sqlTranslator.addCompositeAggregateNode(node,aggregateNodesMap, aggrKeyToAliasMap, null, table,false);
} catch (SqlTranslationException ex) {
assertTrue(false);
fail("unexpected SqlTranslationException");
}
}
项目:pulsar-reporting-api
文件:SQLTranslatorTest.java
@SuppressWarnings("unchecked")
@Test
public void testAddCompositeAggregateNodeOperatorNode() throws StandardException{
String sql = "select count(testdim) as testdim from tabletest where (site=0 or not(region='11')) order by notexist";
SQLTranslator sqlTranslator = Mockito.mock(SQLTranslator.class,
new CallsRealMethods());
Mockito.doReturn("")
.when(sqlTranslator)
.checkNameChange(Mockito.any(ColumnReference.class),
Mockito.any(Table.class), Mockito.any(Map.class));
assertEquals("tabletest", sqlTranslator.getTableName(sql));
sqlTranslator.parse(sql);
BinaryArithmeticOperatorNode node =Mockito.mock(BinaryArithmeticOperatorNode.class);
NumericConstantNode nNode=new NumericConstantNode();
nNode.setValue(1);
NumericConstantNode rNode=new NumericConstantNode();
rNode.setValue(1);
Mockito.when(node.getLeftOperand()).thenReturn(nNode);
Mockito.when(node.getRightOperand()).thenReturn(rNode);
TableDimension dimension = new TableDimension();
dimension.setName("testDim");
dimension.setType(0);
dimension.setMultiValue(true);
assertEquals("testDim", dimension.getName());
assertEquals(0, dimension.getType());
Table table = new Table();
table.setTableName("tabletest");
table.setNoInnerJoin(false);
table.setDateColumn("testDate");
table.setDimensions(Lists.newArrayList(dimension));
Map<String, AggregateNode> aggregateNodesMap =new HashMap<String, AggregateNode>();
aggregateNodesMap.put("count", new AggregateNode());
Map<String, String> aggrKeyToAliasMap =new HashMap<String, String>();
try {
sqlTranslator.addCompositeAggregateNode(node,aggregateNodesMap, aggrKeyToAliasMap, null, table,false);
} catch (SqlTranslationException ex) {
assertTrue(false);
fail("unexpected SqlTranslationException");
}
}
项目:pulsar-reporting-api
文件:SQLTranslatorTest.java
@SuppressWarnings("unchecked")
@Test
public void testAddCompositeAggregateNodeOperatorNodeLeft() throws StandardException{
String sql = "select count(testdim) as testdim from tabletest where (site=0 or not(region='11')) order by notexist";
SQLTranslator sqlTranslator = Mockito.mock(SQLTranslator.class,
new CallsRealMethods());
Mockito.doReturn("")
.when(sqlTranslator)
.checkNameChange(Mockito.any(ColumnReference.class),
Mockito.any(Table.class), Mockito.any(Map.class));
assertEquals("tabletest", sqlTranslator.getTableName(sql));
sqlTranslator.parse(sql);
BinaryArithmeticOperatorNode node =Mockito.mock(BinaryArithmeticOperatorNode.class);
ColumnReference nNode= Mockito.mock(ColumnReference.class);
Mockito.when(nNode.getColumnName()).thenReturn("testdim");
NumericConstantNode rNode=new NumericConstantNode();
rNode.setValue(1);
Mockito.when(node.getLeftOperand()).thenReturn(nNode);
Mockito.when(node.getRightOperand()).thenReturn(nNode);
TableDimension dimension = new TableDimension();
dimension.setName("testDim");
dimension.setType(0);
dimension.setMultiValue(true);
assertEquals("testDim", dimension.getName());
assertEquals(0, dimension.getType());
Table table = new Table();
table.setTableName("tabletest");
table.setNoInnerJoin(false);
table.setDateColumn("testDate");
table.setDimensions(Lists.newArrayList(dimension));
Map<String, AggregateNode> aggregateNodesMap =new HashMap<String, AggregateNode>();
aggregateNodesMap.put("count", new AggregateNode());
Map<String, String> aggrKeyToAliasMap =new HashMap<String, String>();
try {
sqlTranslator.addCompositeAggregateNode(node,aggregateNodesMap, aggrKeyToAliasMap, null, table,false);
} catch (SqlTranslationException ex) {
assertTrue(false);
fail("unexpected SqlTranslationException");
}
}
项目:pulsar-reporting-api
文件:SQLTranslatorTest.java
@SuppressWarnings("unchecked")
@Test
public void testcolumnRefCheck() throws StandardException{
String sql = "select count(testdim) as testdim from tabletest where (site=0 or not(region='11')) order by notexist";
SQLTranslator sqlTranslator = Mockito.mock(SQLTranslator.class,
new CallsRealMethods());
Mockito.doReturn("")
.when(sqlTranslator)
.checkNameChange(Mockito.any(ColumnReference.class),
Mockito.any(Table.class), Mockito.any(Map.class));
assertEquals("tabletest", sqlTranslator.getTableName(sql));
sqlTranslator.parse(sql);
BinaryArithmeticOperatorNode node =Mockito.mock(BinaryArithmeticOperatorNode.class);
ColumnReference nNode= Mockito.mock(ColumnReference.class);
Mockito.when(nNode.getColumnName()).thenReturn("testdim");
NumericConstantNode rNode=new NumericConstantNode();
rNode.setValue(1);
Mockito.when(node.getLeftOperand()).thenReturn(nNode);
Mockito.when(node.getRightOperand()).thenReturn(nNode);
TableDimension dimension = new TableDimension();
dimension.setName("testdim");
dimension.setType(0);
dimension.setMultiValue(true);
assertEquals("testdim", dimension.getName());
assertEquals(0, dimension.getType());
Table table = new Table();
table.setTableName("tabletest");
table.setNoInnerJoin(false);
table.setDateColumn("testDate");
table.setDimensions(Lists.newArrayList(dimension));
Map<String, AggregateNode> aggregateNodesMap =new HashMap<String, AggregateNode>();
aggregateNodesMap.put("count", new AggregateNode());
try {
sqlTranslator.columnRefCheck(nNode, table, null, true, false);
fail("expected SqlTranslationException");
} catch (SqlTranslationException ex) {
assertTrue(true);
}
}
项目:astor
文件:BaseStubbing.java
public OngoingStubbing<T> thenCallRealMethod() {
return thenAnswer(new CallsRealMethods());
}
项目:astor
文件:BaseStubbing.java
public OngoingStubbing<T> thenCallRealMethod() {
return thenAnswer(new CallsRealMethods());
}
项目:springmock
文件:MockitoDoubleConfigurationParser.java
/**
* When working with mocks CallRealMethods is default answer. Otherwise method calls will not be passed to object
*
* @param configurationBuilder
*/
private void configureDefaultAnswerForSpy(MockitoDoubleConfigurationBuilder configurationBuilder) {
configurationBuilder.answer(CallsRealMethods.class);
}
项目:powermock
文件:PowerMockito.java
/**
* Use doCallRealMethod() when you want to call the real implementation of a
* method.
* <p>
* As usual you are going to read <b>the partial mock warning</b>: Object
* oriented programming is more less tackling complexity by dividing the
* complexity into separate, specific, SRPy objects. How does partial mock
* fit into this paradigm? Well, it just doesn't... Partial mock usually
* means that the complexity has been moved to a different method on the
* same object. In most cases, this is not the way you want to design your
* application.
* <p>
* However, there are rare cases when partial mocks come handy: dealing with
* code you cannot change easily (3rd party interfaces, interim refactoring
* of legacy code etc.) However, I wouldn't use partial mocks for new,
* test-driven & well-designed code.
* <p>
* See also javadoc {@link Mockito#spy(Object)} to find out more about
* partial mocks. <b>Mockito.spy() is a recommended way of creating partial
* mocks.</b> The reason is it guarantees real methods are called against
* correctly constructed object because you're responsible for constructing
* the object passed to spy() method.
* <p>
* Example:
*
* <pre>
* Foo mock = mock(Foo.class);
* doCallRealMethod().when(mock).someVoidMethod();
*
* // this will call the real implementation of Foo.someVoidMethod()
* mock.someVoidMethod();
* </pre>
* <p>
* See examples in javadoc for {@link Mockito} class
*
* @return stubber - to select a method for stubbing
*/
public static PowerMockitoStubber doCallRealMethod() {
return POWERMOCKITO_CORE.doAnswer(new CallsRealMethods());
}
项目:astor
文件:Mockito.java
/**
* Use doCallRealMethod() when you want to call the real implementation of a method.
* <p>
* As usual you are going to read <b>the partial mock warning</b>:
* Object oriented programming is more less tackling complexity by dividing the complexity into separate, specific, SRPy objects.
* How does partial mock fit into this paradigm? Well, it just doesn't...
* Partial mock usually means that the complexity has been moved to a different method on the same object.
* In most cases, this is not the way you want to design your application.
* <p>
* However, there are rare cases when partial mocks come handy:
* dealing with code you cannot change easily (3rd party interfaces, interim refactoring of legacy code etc.)
* However, I wouldn't use partial mocks for new, test-driven & well-designed code.
* <p>
* See also javadoc {@link Mockito#spy(Object)} to find out more about partial mocks.
* <b>Mockito.spy() is a recommended way of creating partial mocks.</b>
* The reason is it guarantees real methods are called against correctly constructed object because you're responsible for constructing the object passed to spy() method.
* <p>
* Example:
* <pre>
* Foo mock = mock(Foo.class);
* doCallRealMethod().when(mock).someVoidMethod();
*
* // this will call the real implementation of Foo.someVoidMethod()
* mock.someVoidMethod();
* </pre>
* <p>
* See examples in javadoc for {@link Mockito} class
*
* @return stubber - to select a method for stubbing
*/
public static Stubber doCallRealMethod() {
return MOCKITO_CORE.doAnswer(new CallsRealMethods());
}