### Question:
Log4j2Lookup implements ValueResolver { @Override public String resolve(VirtualProperty property) { if (property.isDynamic()) { return resolve(property.getValue()); } return property.getValue(); } Log4j2Lookup(StrSubstitutor strSubstitutor); @Override String resolve(VirtualProperty property); @Override String resolve(String unresolved);  }### Answer:
@Test public void resolvesDynamicPropertyOnEachCall() { String expectedValue = UUID.randomUUID().toString(); VirtualProperty virtualProperty = VirtualPropertyTest.createDefaultVirtualPropertyBuilder() .withValue(expectedValue) .withDynamic(true) .build(); StrSubstitutor strSubstitutor = spy(createDefaultTestStrSubstitutor()); Log4j2Lookup lookup = createDefaultTestLog4j2Lookup(strSubstitutor); lookup.resolve(virtualProperty); lookup.resolve(virtualProperty); ArgumentCaptor<String> captor = ArgumentCaptor.forClass(String.class); verify(strSubstitutor, times(2)).replace(captor.capture()); Assert.assertEquals(expectedValue, captor.getAllValues().get(0)); Assert.assertEquals(expectedValue, captor.getAllValues().get(1)); }
@Test public void resolvesDynamicPropertyDelegatesToStringBasedApi() { String expectedValue = UUID.randomUUID().toString(); VirtualProperty virtualProperty = VirtualPropertyTest.createDefaultVirtualPropertyBuilder() .withValue(expectedValue) .withDynamic(true) .build(); Log4j2Lookup lookup = spy(createDefaultTestLog4j2Lookup(createDefaultTestStrSubstitutor())); lookup.resolve(virtualProperty); ArgumentCaptor<String> captor = ArgumentCaptor.forClass(String.class); verify(lookup, times(1)).resolve(captor.capture()); Assert.assertEquals(expectedValue, captor.getValue()); }
@Test public void doesNotResolveNonDynamicVirtualProperties() { VirtualProperty virtualProperty = VirtualPropertyTest.createDefaultVirtualPropertyBuilder() .withDynamic(false) .build(); StrSubstitutor strSubstitutor = spy(createDefaultTestStrSubstitutor()); Log4j2Lookup lookup = createDefaultTestLog4j2Lookup(strSubstitutor); lookup.resolve(virtualProperty); verify(strSubstitutor, never()).replace(anyString()); }