### Question:
AvroSerDeTransformation { Table apply(Table table, String avroSchemaDestination, String eventId) throws Exception { if (avroSchemaDestination == null) { return table; } avroSchemaDestination = addTrailingSlash(avroSchemaDestination); avroSchemaDestination += eventId; String avroSchemaSource = table.getParameters().get(AVRO_SCHEMA_URL_PARAMETER); copy(avroSchemaSource, avroSchemaDestination); table.putToParameters(AVRO_SCHEMA_URL_PARAMETER, avroSchemaDestination + "/" + getAvroSchemaFileName(avroSchemaSource)); LOG.info("Avro SerDe transformation has been applied to table '{}'", table.getTableName()); return table; } @Autowired  AvroSerDeTransformation(HiveConf sourceHiveConf, HiveConf replicaHiveConf);   }### Answer:
@Test public void applyTable() throws Exception { File srcSchemaFile = temporaryFolder.newFile(); File dstFolder = temporaryFolder.newFolder(); table.putToParameters("avro.schema.url", srcSchemaFile.toString()); table = avroSerDeTransformation.apply(table, dstFolder.toString(), "1"); String replicaBasePath = table.getParameters().get("avro.schema.url"); replicaBasePath = replicaBasePath.substring(0, replicaBasePath.lastIndexOf("/")); assertThat(replicaBasePath, startsWith(dstFolder.toString())); assertTrue(new File(replicaBasePath).exists()); }
@Test public void applyPartition() throws Exception { File srcSchemaFile = temporaryFolder.newFile(); File dstFolder = temporaryFolder.newFolder(); partition.putToParameters("avro.schema.url", srcSchemaFile.toString()); partition = avroSerDeTransformation.apply(partition, dstFolder.toString(), "1"); String replicaBasePath = partition.getParameters().get("avro.schema.url"); replicaBasePath = replicaBasePath.substring(0, replicaBasePath.lastIndexOf("/")); assertThat(replicaBasePath, startsWith(dstFolder.toString())); assertTrue(new File(replicaBasePath).exists()); }
@Test public void nullAvroDestinationFailsInTableApply() throws Exception { table.putToParameters("avro.schema.url", "/test/"); Table result = avroSerDeTransformation.apply(table, null, "1"); assertThat(result, is(table)); }
@Test public void nullAvroDestinationFailsInPartitionApply() throws Exception { partition.putToParameters("avro.schema.url", "/test/"); Partition result = avroSerDeTransformation.apply(partition, null, "1"); assertThat(result, is(partition)); }