Skip to content

Commit

Permalink
Merge pull request #74 from zeenea/ZEE-6771/missing_constructor
Browse files Browse the repository at this point in the history
[ZEE-6771] Add missing ItemInventory constructor
  • Loading branch information
martin-guerre authored Feb 19, 2025
2 parents d88b7a0 + dd36ec8 commit 3433e63
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 16 deletions.
16 changes: 16 additions & 0 deletions src/main/java/zeenea/connector/common/ItemInventory.java
Original file line number Diff line number Diff line change
Expand Up @@ -37,12 +37,28 @@ private ItemInventory(Builder builder) {
* @param itemIdentifier the identifier for the item
* @param labelPath the path of labels associated with the item
* @return a new ItemInventory instance
* @deprecated since 2.3.0
*/
@Deprecated(
since = "Deprecated since version 2.3.0. Scheduled for removal in version 3.0.0.",
forRemoval = true)
public static ItemInventory of(
@NotNull ItemIdentifier itemIdentifier, @NotNull List<String> labelPath) {
return builder().itemIdentifier(itemIdentifier).labels(labelPath).build();
}

/**
* Creates a new ItemInventory instance with the specified item and label identifiers.
*
* @param itemIdentifier the identifier for the item
* @param labelIdentifier the label identifier associated with the item
* @return a new ItemInventory instance
*/
public static ItemInventory of(
@NotNull ItemIdentifier itemIdentifier, @NotNull LabelIdentifier labelIdentifier) {
return builder().itemIdentifier(itemIdentifier).labelIdentifier(labelIdentifier).build();
}

/**
* Gets the identifier for the item.
*
Expand Down
47 changes: 32 additions & 15 deletions src/test/java/zeenea/connector/common/ItemInventoryTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,21 +13,27 @@ class ItemInventoryTest {
void shouldCreateItemInventory() {
ItemIdentifier identifier =
ItemIdentifier.of(List.of(IdentificationProperty.of("key", "value")));
List<String> labels = List.of("label1", "label2");
ItemInventory inventory = ItemInventory.of(identifier, labels);
LabelIdentifier labelIdentifier =
LabelIdentifier.of(
IdentificationProperty.of("label1", "value1"),
IdentificationProperty.of("label2", "value2"));
ItemInventory inventory = ItemInventory.of(identifier, labelIdentifier);
assertNotNull(inventory);
assertEquals(identifier, inventory.getItemIdentifier());
assertEquals(labels, inventory.getLabels());
assertEquals(labelIdentifier, inventory.getLabelIdentifier());
}

@Test
@DisplayName("ItemInventory should be equal to another with same properties")
void shouldBeEqualToAnotherWithSameProperties() {
ItemIdentifier identifier =
ItemIdentifier.of(List.of(IdentificationProperty.of("key", "value")));
List<String> labels = List.of("label1", "label2");
ItemInventory inventory1 = ItemInventory.of(identifier, labels);
ItemInventory inventory2 = ItemInventory.of(identifier, labels);
LabelIdentifier labelIdentifier =
LabelIdentifier.of(
IdentificationProperty.of("label1", "value1"),
IdentificationProperty.of("label2", "value2"));
ItemInventory inventory1 = ItemInventory.of(identifier, labelIdentifier);
ItemInventory inventory2 = ItemInventory.of(identifier, labelIdentifier);
assertEquals(inventory1, inventory2);
assertEquals(inventory1.hashCode(), inventory2.hashCode());
}
Expand All @@ -39,25 +45,36 @@ void shouldNotBeEqualToAnotherWithDifferentProperties() {
ItemIdentifier.of(List.of(IdentificationProperty.of("key1", "value1")));
ItemIdentifier identifier2 =
ItemIdentifier.of(List.of(IdentificationProperty.of("key2", "value2")));
List<String> labels1 = List.of("label1", "label2");
List<String> labels2 = List.of("label3", "label4");
ItemInventory inventory1 = ItemInventory.of(identifier1, labels1);
ItemInventory inventory2 = ItemInventory.of(identifier2, labels2);
LabelIdentifier labelIdentifier1 =
LabelIdentifier.of(
IdentificationProperty.of("label1", "value1"),
IdentificationProperty.of("label2", "value2"));
LabelIdentifier labelIdentifier2 =
LabelIdentifier.of(
IdentificationProperty.of("label1", "value3"),
IdentificationProperty.of("label2", "value2"));

ItemInventory inventory1 = ItemInventory.of(identifier1, labelIdentifier1);
ItemInventory inventory2 = ItemInventory.of(identifier2, labelIdentifier2);
assertNotEquals(inventory1, inventory2);
}

@Test
@DisplayName("ItemInventory factory should fail with null item identifier")
void shouldFailWithNullItemIdentifier() {
List<String> labels = List.of("label1", "label2");
assertThrows(NullPointerException.class, () -> ItemInventory.of(null, labels));
LabelIdentifier labelIdentifier =
LabelIdentifier.of(
IdentificationProperty.of("label1", "value1"),
IdentificationProperty.of("label2", "value2"));
assertThrows(NullPointerException.class, () -> ItemInventory.of(null, labelIdentifier));
}

@Test
@DisplayName("ItemInventory factory should fail with null label path")
void shouldFailWithNullLabelPath() {
@DisplayName("ItemInventory factory should fail with null label identifier")
void shouldFailWithNullLabelIdentifier() {
ItemIdentifier identifier =
ItemIdentifier.of(List.of(IdentificationProperty.of("key", "value")));
assertThrows(NullPointerException.class, () -> ItemInventory.of(identifier, null));
LabelIdentifier labelIdentifier = null;
assertThrows(NullPointerException.class, () -> ItemInventory.of(identifier, labelIdentifier));
}
}
2 changes: 1 addition & 1 deletion version.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
2.3.0
2.3.1

0 comments on commit 3433e63

Please sign in to comment.