### Question:
RecodeRulesConverter implements ReverseConverter<IDataSet, TransferRuleDescriptor> { @Override public TransferRuleDescriptor convert(IDataSet source) { Collection<RecodeRule> result = new ArrayList<>(); try { for (String tableName : source.getTableNames()) { ITable table = source.getTable(tableName); int columnCount = table.getTableMetaData().getColumns().length; if (columnCount >= MIN_COLUMN_COUNT) { DictionaryNamedPath from = new DictionaryNamedPath(null, tableName); DictionaryNamedPath to = new DictionaryNamedPath(null, tableName); result.addAll(createRecodeRules(from, to, table)); } else { throw new IllegalArgumentException( String.format( "Recode table with name '%s' does not have enough columns to create recode rules. Expected: %d, got: %d", tableName, MIN_COLUMN_COUNT, columnCount ) ); } } } catch (DataSetException ex) { ReflectionUtil.rethrowRuntimeException(ex); } return new TransferRuleDescriptor(result); }  @Override TransferRuleDescriptor convert(IDataSet source); @Override IDataSet reverseConvert(TransferRuleDescriptor target);  }### Answer:
@Test(expectedExceptions = IllegalArgumentException.class) public void testConvertFailed() throws Exception { DefaultTable table = new DefaultTable(new DefaultTableMetaData( "testDictionary", new Column[]{new Column("column", DataType.UNKNOWN)} )); DefaultDataSet dataSet = new DefaultDataSet(table); converter.convert(dataSet); }
@Test public void testConvertSuccess() throws Exception { DictionaryNamedPath dictionaryNamedPath = new DictionaryNamedPath(null, "testDictionary"); DefaultTable table = new DefaultTable(new DefaultTableMetaData( dictionaryNamedPath.getDictionaryName(), new Column[]{new Column("from.c1", DataType.UNKNOWN), new Column("c2", DataType.UNKNOWN), new Column("c3", DataType.UNKNOWN)} )); table.addRow(new Object[]{"1", "one", "001"}); table.addRow(new Object[]{"2", "two", "002"}); table.addRow(new Object[]{"3", null, "002"}); DefaultDataSet dataSet = new DefaultDataSet(table); TransferRuleDescriptor descriptor = converter.convert(dataSet); assertNotNull(descriptor); List<RecodeRule> recodeRules = Lists.newArrayList(descriptor.getContent()); assertEquals(recodeRules.size(), 3); { assertEquals(recodeRules.get(0).getFromNamedPath(), new FieldNamedPath(dictionaryNamedPath, "c1", "1")); assertEquals(recodeRules.get(0).getToNamedPath(), new FieldNamedPath(dictionaryNamedPath, "c2", "one")); } { assertEquals(recodeRules.get(1).getFromNamedPath(), new FieldNamedPath(dictionaryNamedPath, "c1", "2")); assertEquals(recodeRules.get(1).getToNamedPath(), new FieldNamedPath(dictionaryNamedPath, "c2", "two")); } { assertEquals(recodeRules.get(2).getFromNamedPath(), new FieldNamedPath(dictionaryNamedPath, "c1", "3")); assertEquals(recodeRules.get(2).getToNamedPath(), new FieldNamedPath(dictionaryNamedPath, "c2", null)); } assertObjectSerialization(recodeRules); }