@Test @DisplayName("create instance for non-command execution context") void createForNonCommand() { TenantId tenant = generate(); CurrentTenant.set(tenant); TenantAwareOperation op = createOperation(); assertEquals(tenant, op.tenantId()); op.execute(); assertEquals(tenant, getTenantFromRun(op)); }
public void execute() { Optional<TenantId> remembered = CurrentTenant.get(); try { CurrentTenant.set(tenantId()); run(); } finally { if (remembered.isPresent()) { CurrentTenant.set(remembered.get()); } else { CurrentTenant.clear(); } } }
TenantAwareOperation extends TenantAware implements Runnable { public void execute() { Optional<TenantId> remembered = CurrentTenant.get(); try { CurrentTenant.set(tenantId()); run(); } finally { if (remembered.isPresent()) { CurrentTenant.set(remembered.get()); } else { CurrentTenant.clear(); } } } }
TenantAwareOperation extends TenantAware implements Runnable { public void execute() { Optional<TenantId> remembered = CurrentTenant.get(); try { CurrentTenant.set(tenantId()); run(); } finally { if (remembered.isPresent()) { CurrentTenant.set(remembered.get()); } else { CurrentTenant.clear(); } } } protected  TenantAwareOperation(); protected  TenantAwareOperation(TenantId tenantId); }
TenantAwareOperation extends TenantAware implements Runnable { public void execute() { Optional<TenantId> remembered = CurrentTenant.get(); try { CurrentTenant.set(tenantId()); run(); } finally { if (remembered.isPresent()) { CurrentTenant.set(remembered.get()); } else { CurrentTenant.clear(); } } } protected  TenantAwareOperation(); protected  TenantAwareOperation(TenantId tenantId); void execute(); }
TenantAwareOperation extends TenantAware implements Runnable { public void execute() { Optional<TenantId> remembered = CurrentTenant.get(); try { CurrentTenant.set(tenantId()); run(); } finally { if (remembered.isPresent()) { CurrentTenant.set(remembered.get()); } else { CurrentTenant.clear(); } } } protected  TenantAwareOperation(); protected  TenantAwareOperation(TenantId tenantId); void execute();  }