### Question:
ExpiredHousekeepingMetadataGenerator implements HousekeepingEntityGenerator { @Override public List<HousekeepingEntity> generate(ListenerEvent listenerEvent, String clientId) { List<HousekeepingEntity> housekeepingEntities = new ArrayList<>(); switch (listenerEvent.getEventType()) { case CREATE_TABLE: housekeepingEntities.add(generateHousekeepingEntity((CreateTableEvent) listenerEvent, clientId)); break; case ALTER_TABLE: housekeepingEntities.add(generateHousekeepingEntity((AlterTableEvent) listenerEvent, clientId)); break; case ADD_PARTITION: housekeepingEntities.add(generateHousekeepingEntity((AddPartitionEvent) listenerEvent, clientId)); break; case ALTER_PARTITION: housekeepingEntities.add(generateHousekeepingEntity((AlterPartitionEvent) listenerEvent, clientId)); break; default: throw new BeekeeperException(format("No handler case for %s event type", listenerEvent.getEventType())); } return housekeepingEntities; } ExpiredHousekeepingMetadataGenerator(String cleanupDelay); @VisibleForTesting  ExpiredHousekeepingMetadataGenerator(CleanupDelayExtractor cleanupDelayExtractor, Clock clock); @Override List<HousekeepingEntity> generate(ListenerEvent listenerEvent, String clientId); @Override LifecycleEventType getLifecycleEventType(); static final String EXPIRED_DATA_RETENTION_PERIOD_PROPERTY_KEY; }### Answer:
@Test public void typicalHandleCreateTableEvent() { setupClockAndExtractor(createTableEvent); setupListenerEvent(createTableEvent, CREATE_TABLE); when(createTableEvent.getTableLocation()).thenReturn(PATH); List<HousekeepingEntity> housekeepingEntities = generator.generate(createTableEvent, CLIENT_ID); assertThat(housekeepingEntities.size()).isEqualTo(1); assertExpiredHousekeepingMetadataEntity(housekeepingEntities.get(0), null); }
@Test public void typicalHandleAlterTableEvent() { setupClockAndExtractor(alterTableEvent); setupListenerEvent(alterTableEvent, ALTER_TABLE); when(alterTableEvent.getTableLocation()).thenReturn(PATH); List<HousekeepingEntity> housekeepingEntities = generator.generate(alterTableEvent, CLIENT_ID); assertThat(housekeepingEntities.size()).isEqualTo(1); assertExpiredHousekeepingMetadataEntity(housekeepingEntities.get(0), null); }
@Test public void typicalHandleAddPartitionEvent() { setupClockAndExtractor(addPartitionEvent); setupListenerEvent(addPartitionEvent, ADD_PARTITION); when(addPartitionEvent.getPartitionLocation()).thenReturn(PATH); when(addPartitionEvent.getPartitionKeys()).thenReturn(PARTITION_KEYS); when(addPartitionEvent.getPartitionValues()).thenReturn(PARTITION_VALUES); List<HousekeepingEntity> housekeepingEntities = generator.generate(addPartitionEvent, CLIENT_ID); assertThat(housekeepingEntities.size()).isEqualTo(1); assertExpiredHousekeepingMetadataEntity(housekeepingEntities.get(0), PARTITION_NAME); }
@Test public void typicalHandleAlterPartitionEvent() { setupClockAndExtractor(alterPartitionEvent); setupListenerEvent(alterPartitionEvent, ALTER_PARTITION); when(alterPartitionEvent.getPartitionLocation()).thenReturn(PATH); when(alterPartitionEvent.getPartitionKeys()).thenReturn(PARTITION_KEYS); when(alterPartitionEvent.getPartitionValues()).thenReturn(PARTITION_VALUES); List<HousekeepingEntity> housekeepingEntities = generator.generate(alterPartitionEvent, CLIENT_ID); assertThat(housekeepingEntities.size()).isEqualTo(1); assertExpiredHousekeepingMetadataEntity(housekeepingEntities.get(0), PARTITION_NAME); }
@Test public void exceptionThrownOnUnhandledEvent() { DropTableEvent dropTableEvent = mock(DropTableEvent.class); when(dropTableEvent.getEventType()).thenReturn(DROP_TABLE); try { generator.generate(dropTableEvent, CLIENT_ID); fail("Should have thrown exception"); } catch (BeekeeperException e) { assertThat(e.getMessage()).isEqualTo(format("No handler case for %s event type", dropTableEvent.getEventType())); } }