• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

link-intersystems / java-event-sourcing / #13

15 Oct 2023 10:02AM UTC coverage: 96.482% (-3.5%) from 100.0%
#13

push

renelink
Added eventsource-db repository implementation.

47 of 47 new or added lines in 3 files covered. (100.0%)

192 of 199 relevant lines covered (96.48%)

0.96 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

95.83
/inventory-management/entities/src/main/java/com/link_intersystems/inventory/InventoryItem.java
1
package com.link_intersystems.inventory;
2

3
import java.util.Objects;
4

5
import static java.util.Objects.*;
6

7
public class InventoryItem {
8

9
    private InventoryItemIdentifier identifier;
10
    private Quantity quantity = new Quantity(0);
1✔
11

12
    public InventoryItem(InventoryItemIdentifier identifier) {
1✔
13
        this.identifier = requireNonNull(identifier);
1✔
14
    }
1✔
15

16
    public InventoryItemIdentifier getIdentifier() {
17
        return identifier;
1✔
18
    }
19

20
    public Quantity getQuantity() {
21
        return quantity;
1✔
22
    }
23

24
    void setQuantity(Quantity quantity) {
25
        this.quantity = requireNonNull(quantity);
1✔
26
    }
1✔
27

28
    static abstract class QuantityEvent extends InventoryItemEvent {
29

30
        private Quantity quantityDiff;
31

32
        public QuantityEvent(InventoryItemIdentifier identifier, Quantity quantityDiff) {
33
            super(identifier);
1✔
34
            this.quantityDiff = requireNonNull(quantityDiff);
1✔
35
        }
1✔
36

37
        public Quantity getQuantity() {
38
            return quantityDiff;
×
39
        }
40

41
        @Override
42
        public void apply(InventoryItem inventoryItem) {
43
            if (!Objects.equals(this.getIdentifier(), inventoryItem.getIdentifier())) {
1✔
44
                throw new IllegalArgumentException(this + " can not be applied to " + inventoryItem + ", because of a different identifier.");
1✔
45
            }
46

47
            Quantity newQuantity = getNewQuantity(inventoryItem, quantityDiff);
1✔
48
            inventoryItem.setQuantity(newQuantity);
1✔
49
        }
1✔
50

51
        protected abstract Quantity getNewQuantity(InventoryItem inventoryItem, Quantity quantityDiff);
52

53
        @Override
54
        public boolean equals(Object o) {
55
            if (this == o) return true;
1✔
56
            if (o == null || getClass() != o.getClass()) return false;
1✔
57
            QuantityEvent quantityEvent = (QuantityEvent) o;
1✔
58
            if (!Objects.equals(quantityDiff, quantityEvent.quantityDiff)) {
1✔
59
                return false;
1✔
60
            }
61

62
            return super.equals(o);
1✔
63
        }
64

65
        @Override
66
        public int hashCode() {
67
            return Objects.hash(super.hashCode(), quantityDiff);
1✔
68
        }
69
    }
70

71
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc