Skip to content

Commit

Permalink
Feature: Added test cases for creating inventory.
Browse files Browse the repository at this point in the history
  • Loading branch information
ishika28 committed Jul 4, 2020
1 parent 5d10064 commit 20d90e1
Show file tree
Hide file tree
Showing 2 changed files with 62 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
package com.pemits.webcare.api.inventory.repository;

import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.hasSize;
import static org.hamcrest.Matchers.notNullValue;

import java.time.LocalDate;
import java.util.Arrays;
import java.util.List;

import org.junit.Test;
import org.springframework.beans.factory.annotation.Autowired;

import com.pemits.webcare.BaseJpaTest;
import com.pemits.webcare.api.inventory.entity.Inventory;

public class InventoryRepositoryTest extends BaseJpaTest {

private static final String MOCK_INVENTORY_NAME1 = "Inventory1";
private static final String MOCK_INVENTORY_NAME2 = "Inventory2";

@Autowired
private InventoryRepository repository;

@Test
public void testSaveShouldReturnSavedInventory() {
Inventory inventory = new Inventory();
inventory.setName(MOCK_INVENTORY_NAME1);
inventory.setPrice(1200.50f);
inventory.setQuantity(100);
inventory.setTotalPrice(1200.50f * 100);
inventory.setPurchaseDate(LocalDate.now());

Inventory saved = repository.save(inventory);

assertThat(saved.getId(), notNullValue());
}

@Test
public void testSaveAllShouldReturnAllSavedInventories() {
Inventory inventory1 = new Inventory();
inventory1.setName(MOCK_INVENTORY_NAME1);
inventory1.setPrice(1200.50f);
inventory1.setQuantity(100);
inventory1.setTotalPrice(1200.50f * 100);
inventory1.setPurchaseDate(LocalDate.now());

Inventory inventory2 = new Inventory();
inventory2.setName(MOCK_INVENTORY_NAME2);
inventory2.setPrice(2200.50f);
inventory2.setQuantity(100);
inventory2.setTotalPrice(2200.50f * 100);
inventory2.setPurchaseDate(LocalDate.now());

List<Inventory> saved = repository.saveAll(Arrays.asList(inventory1, inventory2));

assertThat(saved, hasSize(2));
assertThat(saved.get(0).getId(), notNullValue());
assertThat(saved.get(1).getId(), notNullValue());
}

}
Empty file.

0 comments on commit 20d90e1

Please sign in to comment.