Skip to content

Commit

Permalink
OAM-191: Addded coverage tests and renamed test class.
Browse files Browse the repository at this point in the history
  • Loading branch information
tsznaj committed Jun 13, 2024
1 parent ddc41ca commit 98c087d
Show file tree
Hide file tree
Showing 3 changed files with 189 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -587,6 +587,53 @@ public void shouldOrderableLotIdentityIsNotEqualToOrderableLotUnitIdentityDueToL
assertThat(areEqual, is(false));
}

@Test
public void shouldOrderableLotIdentityIsNotEqualToNull() {
//given
UUID orderableId = UUID.randomUUID();
UUID lotId = UUID.randomUUID();
StockCardSummariesService.OrderableLotIdentity orderableLotIdentity =
new StockCardSummariesService.OrderableLotIdentity(
orderableId,
lotId
);
OrderableLotUnitIdentity orderableLotUnitIdentity = null;

//when
boolean areEqual =
orderableLotIdentity.equalsOrderableLotUnitIdentity(orderableLotUnitIdentity);

//then
assertThat(areEqual, is(false));
}

@Test
public void shouldOrderableLotIdentityIsNotEqualDueToNullOrderableId() {
//given
UUID orderableId2 = UUID.randomUUID();
UUID lotId1 = UUID.randomUUID();
UUID lotId2 = UUID.randomUUID();
UUID unitOfOrderableId = UUID.randomUUID();
StockCardSummariesService.OrderableLotIdentity orderableLotIdentity =
new StockCardSummariesService.OrderableLotIdentity(
null,
lotId1
);
OrderableLotUnitIdentity orderableLotUnitIdentity =
new OrderableLotUnitIdentity(
orderableId2,
lotId2,
unitOfOrderableId
);

//when
boolean areEqual =
orderableLotIdentity.equalsOrderableLotUnitIdentity(orderableLotUnitIdentity);

//then
assertThat(areEqual, is(false));
}

private void checkStockCardDto(
List<StockCardDto> stockCardsDtos,
UUID orderableId1,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,10 @@
import static java.util.UUID.fromString;
import static java.util.UUID.randomUUID;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;

import java.util.UUID;
import org.junit.Test;
import org.openlmis.stockmanagement.domain.identity.OrderableLotUnitIdentity;

Expand All @@ -44,4 +46,117 @@ public void sameOrderableAndLotIdShouldEqualAndHaveSameHash() throws Exception {
assertTrue(equals);
assertEquals(identity1Hash, identity2Hash);
}
}

@Test
public void shouldNotBeEqualDueToOrderableId() {
//given
UUID orderableId1 = UUID.randomUUID();
UUID orderableId2 = UUID.randomUUID();

UUID lotId = UUID.randomUUID();
UUID unitOfOrderableId = UUID.randomUUID();

OrderableLotUnitIdentity orderableLotUnitIdentity1 =
new OrderableLotUnitIdentity(
orderableId1,
lotId,
unitOfOrderableId
);
OrderableLotUnitIdentity orderableLotUnitIdentity2 =
new OrderableLotUnitIdentity(
orderableId2,
lotId,
unitOfOrderableId
);

//when
boolean areEqual =
orderableLotUnitIdentity1.equals(orderableLotUnitIdentity2);

//then
assertFalse(areEqual);
}

@Test
public void shouldNotBeEqualDueToLotId() {
//given
UUID orderableId = UUID.randomUUID();

UUID lotId1 = UUID.randomUUID();
UUID lotId2 = UUID.randomUUID();

UUID unitOfOrderableId = UUID.randomUUID();

OrderableLotUnitIdentity orderableLotUnitIdentity1 =
new OrderableLotUnitIdentity(
orderableId,
lotId1,
unitOfOrderableId
);
OrderableLotUnitIdentity orderableLotUnitIdentity2 =
new OrderableLotUnitIdentity(
orderableId,
lotId2,
unitOfOrderableId
);

//when
boolean areEqual =
orderableLotUnitIdentity1.equals(orderableLotUnitIdentity2);

//then
assertFalse(areEqual);
}

@Test
public void shouldNotBeEqualDueToUnitOfOrderableId() {
//given
UUID orderableId = UUID.randomUUID();
UUID lotId = UUID.randomUUID();
UUID unitOfOrderableId1 = UUID.randomUUID();
UUID unitOfOrderableId2 = UUID.randomUUID();

OrderableLotUnitIdentity orderableLotUnitIdentity1 =
new OrderableLotUnitIdentity(
orderableId,
lotId,
unitOfOrderableId1
);
OrderableLotUnitIdentity orderableLotUnitIdentity2 =
new OrderableLotUnitIdentity(
orderableId,
lotId,
unitOfOrderableId2
);

//when
boolean areEqual =
orderableLotUnitIdentity1.equals(orderableLotUnitIdentity2);

//then
assertFalse(areEqual);
}

@Test
public void shouldNotBeEqualDueToSecondIdentityIsNull() {
//given
UUID orderableId = UUID.randomUUID();
UUID lotId = UUID.randomUUID();
UUID unitOfOrderableId = UUID.randomUUID();

OrderableLotUnitIdentity orderableLotUnitIdentity1 =
new OrderableLotUnitIdentity(
orderableId,
lotId,
unitOfOrderableId
);
OrderableLotUnitIdentity orderableLotUnitIdentity2 = null;

//when
boolean areEqual =
orderableLotUnitIdentity1.equals(orderableLotUnitIdentity2);

//then
assertFalse(areEqual);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import static org.junit.rules.ExpectedException.none;
import static org.openlmis.stockmanagement.i18n.MessageKeys.ERROR_EVENT_ORDERABLE_LOT_DUPLICATION;

import java.time.LocalDate;
import java.util.Arrays;
import java.util.UUID;
import org.junit.Rule;
Expand All @@ -30,9 +31,11 @@
import org.mockito.runners.MockitoJUnitRunner;
import org.openlmis.stockmanagement.dto.StockEventDto;
import org.openlmis.stockmanagement.dto.StockEventLineItemDto;
import org.openlmis.stockmanagement.testutils.StockEventDtoDataBuilder;
import org.openlmis.stockmanagement.testutils.StockEventLineItemDtoDataBuilder;

@RunWith(MockitoJUnitRunner.class)
public class OrderableLotDuplicationValidatorTest {
public class OrderableLotUnitDuplicationValidatorTest {

@Rule
public ExpectedException expectedEx = none();
Expand Down Expand Up @@ -60,6 +63,28 @@ public void physicalInventoryEventWithSameOrderableAndLotAppearTwiceShouldNotPas
orderableLotUnitDuplicationValidator.validate(eventDto);
}

@Test
public void shouldValidateCorrectlyWhenNoDuplicates() {
//given
StockEventDto eventDto = createEventDto();

//when
orderableLotUnitDuplicationValidator.validate(eventDto);

//then
//no exception - ok
}

private StockEventDto createEventDto() {
return new StockEventDtoDataBuilder()
.addLineItem(new StockEventLineItemDtoDataBuilder()
.withReasonId(UUID.randomUUID())
.withQuantity(10)
.withOccurredDate(LocalDate.now())
.buildForAdjustment())
.build();
}

private StockEventDto createStockEventDtoWithDuplicateOrderableLot(UUID reasonId) {
//given: an event with orderable appear twice
StockEventLineItemDto eventLineItem1 = new StockEventLineItemDto();
Expand Down

0 comments on commit 98c087d

Please sign in to comment.