private static ExpectedVersion getEffectiveExpectedVersion( final ExpectedVersion commandExpectedVersion, final ExpectedVersion operationExpectedVersion) { try { return ExpectedVersion.merge(commandExpectedVersion, operationExpectedVersion); } catch (ConflictingExpectedVersionsException ex) { throw new InvalidCommandException( "Conflicting expected version constraints: " + ex.getMessage(), ex); } }
private static ExpectedVersion getEffectiveExpectedVersion( final ExpectedVersion commandExpectedVersion, final ExpectedVersion operationExpectedVersion) { try { return ExpectedVersion.merge(commandExpectedVersion, operationExpectedVersion); } catch (ConflictingExpectedVersionsException ex) { throw new InvalidCommandException( "Conflicting expected version constraints: " + ex.getMessage(), ex); } }
private void assertMergeFailOneDirection( final ExpectedVersion first, final ExpectedVersion second) { try { merge(first, second); fail("Expected failure for merging " + first + " with " + second); } catch (RuntimeException ex) { // Success } } }
@Test(expected = InvalidCommandException.class) @SuppressWarnings("unchecked") public void conflictingVersionsGiveInvalidCommand() { PowerMockito.mockStatic(ExpectedVersion.class); PowerMockito.when(ExpectedVersion.merge(any(), any())) .thenThrow(new ConflictingExpectedVersionsException( "error", null, null)); Operation operation = new OperationHandlerOperation( (x, y) -> null, true, false, ExpectedVersion.exactly(42)); DefaultCommand command = new DefaultCommand(repository, operation); command.setAggregateId(AGGREGATE_ID); command.run(); }