### Question:
IdColumnExtractor extends BaseColumnExtractor { @Override public void extract(String prefix) { for (DbAttribute dba : dbEntity.getPrimaryKeys()) { addDbAttribute(prefix, prefix, dba); if(result != null) { result.addDbField(dba.getName(), prefix + dba.getName()); } } if(result != null) { context.getSqlResult().addEntityResult(result); } } IdColumnExtractor(TranslatorContext context, DbEntity dbEntity);   IdColumnExtractor(TranslatorContext context, ObjEntity objEntity); @Override void extract(String prefix);  }### Answer:
@Test public void testExtractNoPrefix() { DbEntity mockDbEntity = createMockDbEntity("mock"); TranslatableQueryWrapper wrapper = new MockQueryWrapperBuilder() .withMetaData(new MockQueryMetadataBuilder() .withDbEntity(mockDbEntity) .build()) .build(); TranslatorContext context = new MockTranslatorContext(wrapper); DataMap dataMap = new DataMap(); dataMap.addDbEntity(mockDbEntity); ObjEntity entity = new ObjEntity(); entity.setDataMap(dataMap); entity.setDbEntity(mockDbEntity); IdColumnExtractor extractor = new IdColumnExtractor(context, entity); extractor.extract(); assertEquals(1, context.getResultNodeList().size()); ResultNodeDescriptor descriptor0 = context.getResultNodeList().get(0); assertNull(descriptor0.getProperty()); assertNotNull(descriptor0.getNode()); assertThat(descriptor0.getNode(), instanceOf(ColumnNode.class)); assertFalse(descriptor0.isAggregate()); assertTrue(descriptor0.isInDataRow()); assertEquals("id", descriptor0.getDataRowKey()); assertNotNull(descriptor0.getDbAttribute()); assertEquals(Types.BIGINT, descriptor0.getJdbcType()); }
@Test public void testExtractWithPrefix() { DbEntity mockDbEntity = createMockDbEntity("mock1"); DbEntity mock2DbEntity = createMockDbEntity("mock2"); TranslatableQueryWrapper wrapper = new MockQueryWrapperBuilder() .withMetaData(new MockQueryMetadataBuilder() .withDbEntity(mockDbEntity) .build()) .build(); TranslatorContext context = new MockTranslatorContext(wrapper); ObjEntity entity = new ObjEntity(); entity.setDbEntity(mockDbEntity); DataMap dataMap = new DataMap(); dataMap.addDbEntity(mockDbEntity); dataMap.addDbEntity(mock2DbEntity); mockDbEntity.setDataMap(dataMap); entity.setDataMap(dataMap); DbRelationship relationship = new DbRelationship(); relationship.setSourceEntity(mockDbEntity); relationship.setTargetEntityName("mock1"); context.getTableTree().addJoinTable("prefix", relationship, JoinType.INNER); IdColumnExtractor extractor = new IdColumnExtractor(context, entity); extractor.extract("prefix"); assertEquals(1, context.getResultNodeList().size()); ResultNodeDescriptor descriptor0 = context.getResultNodeList().get(0); assertNull(descriptor0.getProperty()); assertNotNull(descriptor0.getNode()); assertThat(descriptor0.getNode(), instanceOf(ColumnNode.class)); assertFalse(descriptor0.isAggregate()); assertTrue(descriptor0.isInDataRow()); assertEquals("prefix.id", descriptor0.getDataRowKey()); assertNotNull(descriptor0.getDbAttribute()); assertEquals(Types.BIGINT, descriptor0.getJdbcType()); }