### Question:
TransformationListener implements AgentBuilder.Listener { protected void collectDataFromEvent(TypeDescription typeDescription, DynamicType dynamicType) { if (instrumentedTypes.containsKey(typeDescription.getInternalName())) { instrumentedTypes.get(typeDescription.getInternalName()).update(uid, dynamicType.getBytes()); } else { instrumentedTypes.put(typeDescription.getInternalName(), new InstrumentedClassState(uid, dynamicType.getBytes())); } if (!dynamicType.getAuxiliaryTypes().isEmpty()) { for (Map.Entry<TypeDescription, byte[]> auxiliaryEntry : dynamicType.getAuxiliaryTypes().entrySet()) { instrumentedTypes.put(auxiliaryEntry.getKey().getInternalName(), new InstrumentedClassState(null, auxiliaryEntry.getValue())); } } } TransformationListener(final String uid); void onDiscovery(String typeName, ClassLoader classLoader, JavaModule module, boolean loaded); void onTransformation(TypeDescription typeDescription, ClassLoader classLoader, JavaModule module, boolean loaded, DynamicType dynamicType); void onIgnored(TypeDescription typeDescription, ClassLoader classLoader, JavaModule module, boolean loaded); void onError(String typeName, ClassLoader classLoader, JavaModule module, boolean loaded, Throwable throwable); void onComplete(String typeName, ClassLoader classLoader, JavaModule module, boolean loaded);  }### Answer:
@Test public void testCollectDataFromEventWorksAndPopulatesMapWithNewEntries() { TransformationListener mockListener = Mockito.spy(new TransformationListener(uid)); Mockito.doCallRealMethod().when(mockListener).collectDataFromEvent(mockTypeDescription, mockDynamicTypeWithAuxiliary); mockListener.collectDataFromEvent(mockTypeDescription, mockDynamicTypeWithAuxiliary); Assert.assertTrue(TransformationListener.getInstrumentedTypes().size() == 3); }
@Test public void testCollectDataFromEventWorksAndUpdatesExistingEntriesFromMap() { DynamicType updatedType = MockEntities.makeMockDynamicType(); Mockito.doCallRealMethod().when(mockListener).collectDataFromEvent(mockTypeDescription, mockDynamicTypeWithAuxiliary); Mockito.doCallRealMethod().when(mockListener).collectDataFromEvent(mockTypeDescription, updatedType); mockListener.collectDataFromEvent(mockTypeDescription, mockDynamicTypeWithAuxiliary); mockListener.collectDataFromEvent(mockTypeDescription, updatedType); Assert.assertTrue(TransformationListener.getInstrumentedTypes().size() == 3); }