title: How Can I Test Aggregate if ID is randomly generated?
body: <p>This may be more of a design question but I have an aggregate member that is generated via a command and need to be able to test that the Event is generated given the command was run.</p>
  
  <p>however, I don't see any obvious way to do an <code>anyString</code> match on one field of the event in the TestFixture framework.</p>
  
  <p>Is it "bad practice" to generate IDs in the aggregate when created? Should IDs be generated outside of the aggregate?</p>
  
  <pre class="lang-java prettyprint-override"><code>@AggregateMember(eventForwardingMode = ForwardMatchingInstances.class)
  private List&lt;TimeCardEntry&gt; timeCardEntries = new ArrayList&lt;&gt;();
  
  data class ClockInCommand(@TargetAggregateIdentifier val employeeName: String)
  
  @CommandHandler
  public TimeCard(ClockInCommand cmd) {
    apply(new ClockInEvent(cmd.getEmployeeName(),
        GenericEventMessage.clock.instant(),
        UUID.randomUUID().toString()));
  
  
  @EventSourcingHandler
  public void on(ClockInEvent event) {
    this.employeeName = event.getEmployeeName();
    timeCardEntries.add(new TimeCardEntry(event.getTimeCardEntryId(), event.getTime()));
  }
  
  @Data
  public class TimeCardEntry {
  
    @EntityId
    private final String timeCardEntryId;
    private final Instant clockInTime;
    private Instant clockOutTime;
  
    @EventSourcingHandler
    public void on(ClockOutEvent event) {
      this.clockOutTime = event.getTime();
    }
  
    private boolean isClockedIn() {
      return clockOutTime != null;
    }
  }
  
  </code></pre>
  
  <pre class="lang-java prettyprint-override"><code>@ParameterizedTest
  @MethodSource(value = "randomEmployeeName")
  void testClockInCommand(String employeeName) {
      testFixture.givenNoPriorActivity()
              .when(new ClockInCommand(employeeName))
              .expectEvents(new ClockInEvent(employeeName, testFixture.currentTime(), "Any-String-Works"));
  }
  </code></pre>