ContextShopCodeLookUpQueryParameterStrategyValueProviderImpl implements CsvLookUpQueryParameterStrategyValueProvider { @Override public Object getPlaceholderValue(final String placeholder, final CsvImpExDescriptor descriptor, final Object masterObject, final CsvImpExTuple tuple, final CsvValueAdapter adapter, final String queryTemplate) { if (descriptor.getContext().getShopCode() != null) { return descriptor.getContext().getShopCode(); } if (descriptor.getContext().getShopCodeColumn() != null) { final CsvImpExColumn column = descriptor.getColumn(descriptor.getContext().getShopCodeColumn()); return tuple.getColumnValue(column, asIs); } return null; }  @Override Object getPlaceholderValue(final String placeholder,
                                      final CsvImpExDescriptor descriptor,
                                      final Object masterObject,
                                      final CsvImpExTuple tuple,
                                      final CsvValueAdapter adapter,
                                      final String queryTemplate);  }
@Test public void testGetPlaceholderValueNone() throws Exception { final CsvImpExDescriptor descriptor = mockery.mock(CsvImpExDescriptor.class, "descriptor"); final CsvImpExContext context = mockery.mock(CsvImpExContext.class, "context"); final CsvValueAdapter adapter = mockery.mock(CsvValueAdapter.class, "adapter"); final ContextShopCodeLookUpQueryParameterStrategyValueProviderImpl provider = new ContextShopCodeLookUpQueryParameterStrategyValueProviderImpl(); mockery.checking(new Expectations() {{ allowing(descriptor).getContext(); will(returnValue(context)); allowing(context).getShopCode(); will(returnValue(null)); allowing(context).getShopCodeColumn(); will(returnValue(null)); }}); assertNull(provider.getPlaceholderValue(null, descriptor, null, null, adapter, null)); mockery.assertIsSatisfied(); }
@Test public void testGetPlaceholderValueShopCode() throws Exception { final CsvImpExDescriptor descriptor = mockery.mock(CsvImpExDescriptor.class, "descriptor"); final CsvImpExContext context = mockery.mock(CsvImpExContext.class, "context"); final CsvValueAdapter adapter = mockery.mock(CsvValueAdapter.class, "adapter"); final ContextShopCodeLookUpQueryParameterStrategyValueProviderImpl provider = new ContextShopCodeLookUpQueryParameterStrategyValueProviderImpl(); mockery.checking(new Expectations() {{ allowing(descriptor).getContext(); will(returnValue(context)); allowing(context).getShopCode(); will(returnValue("ABC")); allowing(context).getShopCodeColumn(); will(returnValue(null)); }}); assertEquals("ABC", provider.getPlaceholderValue(null, descriptor, null, null, adapter, null)); mockery.assertIsSatisfied(); }
@Test public void testGetPlaceholderValueShopCodeColumn() throws Exception { final CsvImpExDescriptor descriptor = mockery.mock(CsvImpExDescriptor.class, "descriptor"); final CsvImpExContext context = mockery.mock(CsvImpExContext.class, "context"); final CsvImportColumn shopCode = mockery.mock(CsvImportColumn.class, "shopCode"); final CsvImportTuple importTuple = mockery.mock(CsvImportTuple.class, "importTuple"); final CsvValueAdapter adapter = mockery.mock(CsvValueAdapter.class, "adapter"); final ContextShopCodeLookUpQueryParameterStrategyValueProviderImpl provider = new ContextShopCodeLookUpQueryParameterStrategyValueProviderImpl(); mockery.checking(new Expectations() {{ allowing(descriptor).getContext(); will(returnValue(context)); allowing(context).getShopCode(); will(returnValue(null)); allowing(context).getShopCodeColumn(); will(returnValue("shopCode")); allowing(descriptor).getColumn("shopCode"); will(returnValue(shopCode)); allowing(importTuple).getColumnValue(with(equal(shopCode)), with(any(CsvValueAdapter.class))); will(returnValue("CDE")); }}); assertEquals("CDE", provider.getPlaceholderValue(null, descriptor, null, importTuple, adapter, null)); mockery.assertIsSatisfied(); }