@SuppressWarnings("unchecked") @Test public void testMapIdFieldKey() throws Exception { String[] fields = { "data.element.id" }; BSONObject elem = new BasicBSONObject("value", 7631); BSONObject data = new BasicBSONObject("element", elem); BSONObject entry = new BasicBSONObject("data", data); final BSONWritable entity = new BSONWritable(entry); IDMapper<IdFieldEmittableKey> mapper = new IDMapper<IdFieldEmittableKey>(); IDMapper<IdFieldEmittableKey>.Context context = Mockito.mock(IDMapper.Context.class); PowerMockito.when(context, "write", Matchers.any(EmittableKey.class), Matchers.any(BSONObject.class)).thenAnswer(new Answer<BSONObject>() { @Override public BSONObject answer(InvocationOnMock invocation) throws Throwable { Object[] args = invocation.getArguments(); assertNotNull(args); assertEquals(args.length, 2); assertTrue(args[0] instanceof IdFieldEmittableKey); assertTrue(args[1] instanceof BSONWritable); IdFieldEmittableKey id = (IdFieldEmittableKey) args[0]; assertEquals(id.getIdField().toString(), "data.element.id"); Text idValue = id.getId(); assertEquals(Long.parseLong(idValue.toString()), 3697); BSONWritable e = (BSONWritable) args[1]; assertEquals(e, entity); return null; } }); IdFieldEmittableKey id = new IdFieldEmittableKey(); id.setFieldNames(fields); id.setId(new Text("3697")); mapper.map(id, entity, context); }
@Override public void map(T id, BSONWritable entity, Context context) throws IOException, InterruptedException { for (String field : idFields.values()) { BSONUtilities.removeField(entity, field); } context.write(id, entity); }
IDMapper extends Mapper<T, BSONWritable, T, BSONWritable> { @Override public void map(T id, BSONWritable entity, Context context) throws IOException, InterruptedException { for (String field : idFields.values()) { BSONUtilities.removeField(entity, field); } context.write(id, entity); } }
IDMapper extends Mapper<T, BSONWritable, T, BSONWritable> { @Override public void map(T id, BSONWritable entity, Context context) throws IOException, InterruptedException { for (String field : idFields.values()) { BSONUtilities.removeField(entity, field); } context.write(id, entity); }  }
IDMapper extends Mapper<T, BSONWritable, T, BSONWritable> { @Override public void map(T id, BSONWritable entity, Context context) throws IOException, InterruptedException { for (String field : idFields.values()) { BSONUtilities.removeField(entity, field); } context.write(id, entity); }  @Override void map(T id, BSONWritable entity, Context context); }
IDMapper extends Mapper<T, BSONWritable, T, BSONWritable> { @Override public void map(T id, BSONWritable entity, Context context) throws IOException, InterruptedException { for (String field : idFields.values()) { BSONUtilities.removeField(entity, field); } context.write(id, entity); }  @Override void map(T id, BSONWritable entity, Context context);  }