<commit_before>package org.deviantcode.controllers;

import org.deviantcode.db.ItemDAO;
import org.deviantcode.models.Item;
import org.easymock.EasyMock;
import org.easymock.IMocksControl;
import org.springframework.test.util.ReflectionTestUtils;
import org.testng.annotations.Test;

import java.util.List;

import static org.testng.Assert.assertEquals;
import static org.easymock.EasyMock.*;

@Test(groups = "unit")
public class InventoryControllerTests {
    @Test
    public void testShowAllInventory() {
        IMocksControl mocksControl = EasyMock.createControl();
        final String itemName = "Test Item";
        Item mockItem = mocksControl.createMock(Item.class);
        expect(mockItem.getName()).andReturn(itemName);
        final List<Item> mockItems = mocksControl.createMock(List.class);
        expect(mockItems.get(0)).andReturn(mockItem);

        ItemDAO mockDAO = mocksControl.createMock(ItemDAO.class);
        expect(mockDAO.getAll()).andReturn(mockItems);

        mocksControl.replay();

        InventoryController inventoryController = new InventoryController();
        ReflectionTestUtils.setField(inventoryController, "itemDAO", mockDAO);

        List<Item> actualList = inventoryController.getAll();
        Item actual = actualList.get(0);
        final Item expected = new Item();
        expected.setName(itemName);
        assertEquals(actual.getName(), expected.getName());
    }

    @Test
    public void testGetInventory() {
        IMocksControl mocksControl = EasyMock.createControl();
        final String itemName = "Test Item";
        Item mockItem = mocksControl.createMock(Item.class);
        expect(mockItem.getName()).andReturn(itemName);
        final List<Item> mockItems = mocksControl.createMock(List.class);
        expect(mockItems.get(0)).andReturn(mockItem);

        ItemDAO mockDAO = mocksControl.createMock(ItemDAO.class);
        expect(mockDAO.getAll()).andReturn(mockItems);

        mocksControl.replay();

        InventoryController inventoryController = new InventoryController();
        ReflectionTestUtils.setField(inventoryController, "itemDAO", mockDAO);

        List<Item> actualList = (List<Item>)ReflectionTestUtils.invokeGetterMethod(inventoryController, "getInventory");
        Item actual = actualList.get(0);
        final Item expected = new Item();
        expected.setName(itemName);
        assertEquals(actual.getName(), expected.getName());
    }

    @Test
    public void testGetItem() {
        final String itemName = "<NAME>";
        IMocksControl mocksControl = EasyMock.createControl();

        Item mockItem = mocksControl.createMock(Item.class);
        expect(mockItem.getName()).andReturn(itemName);

        ItemDAO mockDAO = mocksControl.createMock(ItemDAO.class);
        expect(mockDAO.get(anyObject(String.class))).andReturn(mockItem);

        mocksControl.replay();

        InventoryController inventoryController = new InventoryController();
        ReflectionTestUtils.setField(inventoryController, "itemDAO", mockDAO);


        final Item expected = new Item();
        expected.setName(itemName);
        Item actual = inventoryController.get(itemName);
        assertEquals(actual.getName(), expected.getName());
    }
}<commit_msg>Add basic unit tests for create and update<commit_after>package org.deviantcode.controllers;

import org.deviantcode.db.ItemDAO;
import org.deviantcode.models.Item;
import org.easymock.EasyMock;
import org.easymock.IMocksControl;
import org.springframework.test.util.ReflectionTestUtils;
import org.testng.annotations.Test;

import java.math.BigDecimal;
import java.util.List;

import static org.testng.Assert.assertEquals;
import static org.easymock.EasyMock.*;

@Test(groups = "unit")
public class InventoryControllerTests {
    @Test
    public void testGetAll() {
        IMocksControl mocksControl = EasyMock.createControl();
        final String itemName = "<NAME>";
        Item mockItem = mocksControl.createMock(Item.class);
        expect(mockItem.getName()).andReturn(itemName);
        final List<Item> mockItems = mocksControl.createMock(List.class);
        expect(mockItems.get(0)).andReturn(mockItem);

        ItemDAO mockDAO = mocksControl.createMock(ItemDAO.class);
        expect(mockDAO.getAll()).andReturn(mockItems);

        mocksControl.replay();

        InventoryController inventoryController = new InventoryController();
        ReflectionTestUtils.setField(inventoryController, "itemDAO", mockDAO);

        List<Item> actualList = inventoryController.getAll();
        Item actual = actualList.get(0);
        final Item expected = new Item();
        expected.setName(itemName);
        assertEquals(actual.getName(), expected.getName());
    }

    @Test
    public void testGetInventoryMethod() {
        IMocksControl mocksControl = EasyMock.createControl();
        final String itemName = "Test Item";
        Item mockItem = mocksControl.createMock(Item.class);
        expect(mockItem.getName()).andReturn(itemName);
        final List<Item> mockItems = mocksControl.createMock(List.class);
        expect(mockItems.get(0)).andReturn(mockItem);

        ItemDAO mockDAO = mocksControl.createMock(ItemDAO.class);
        expect(mockDAO.getAll()).andReturn(mockItems);

        mocksControl.replay();

        InventoryController inventoryController = new InventoryController();
        ReflectionTestUtils.setField(inventoryController, "itemDAO", mockDAO);

        List<Item> actualList = (List<Item>)ReflectionTestUtils.invokeGetterMethod(inventoryController, "getInventory");
        Item actual = actualList.get(0);
        final Item expected = new Item();
        expected.setName(itemName);
        assertEquals(actual.getName(), expected.getName());
    }

    @Test
    public void testGet() {
        final String itemName = "Test Item";
        IMocksControl mocksControl = EasyMock.createControl();

        Item mockItem = mocksControl.createMock(Item.class);
        expect(mockItem.getName()).andReturn(itemName);

        ItemDAO mockDAO = mocksControl.createMock(ItemDAO.class);
        expect(mockDAO.get(anyObject(String.class))).andReturn(mockItem);

        mocksControl.replay();

        InventoryController inventoryController = new InventoryController();
        ReflectionTestUtils.setField(inventoryController, "itemDAO", mockDAO);


        final Item expected = new Item();
        expected.setName(itemName);
        Item actual = inventoryController.get(itemName);
        assertEquals(actual.getName(), expected.getName());
    }

    @Test
    public void testCreate() {
        final String name = "Test Item";
        final String descr = "A Test Description";
        final String manufacturer = "Test Manufacturer";
        final String make = "Tester";
        final String model = "Testv1";
        final String color = "Black";
        final String serialno = "123456789";
        final BigDecimal price = new BigDecimal(123.42);

        IMocksControl mocksControl = EasyMock.createControl();

        ItemDAO mockDAO = mocksControl.createMock(ItemDAO.class);
        expect(mockDAO.get(anyObject(String.class))).andReturn(null);
        mockDAO.create(
                anyObject(String.class),
                anyObject(String.class),
                anyObject(String.class),
                anyObject(String.class),
                anyObject(String.class),
                anyObject(String.class),
                anyObject(String.class),
                anyObject(BigDecimal.class));
        expectLastCall();

        Item mockItem = mocksControl.createMock(Item.class);
        expect(mockItem.getName()).andReturn(name);
        expect(mockItem.getDescr()).andReturn(descr);
        expect(mockItem.getManufacturer()).andReturn(manufacturer);
        expect(mockItem.getMake()).andReturn(make);
        expect(mockItem.getModel()).andReturn(model);
        expect(mockItem.getColor()).andReturn(color);
        expect(mockItem.getSerialNo()).andReturn(serialno);
        expect(mockItem.getPrice()).andReturn(price);

        expect(mockDAO.get(anyObject(String.class))).andReturn(mockItem);

        mocksControl.replay();

        InventoryController inventoryController = new InventoryController();
        ReflectionTestUtils.setField(inventoryController, "itemDAO", mockDAO);

        final Item expected = new Item();
        expected.setName(name);
        expected.setDescr(descr);
        expected.setManufacturer(manufacturer);
        expected.setMake(make);
        expected.setModel(model);
        expected.setColor(color);
        expected.setSerialNo(serialno);
        expected.setPrice(price);
        Item actual = inventoryController.create(name, descr, manufacturer, make, model, color, serialno, price);
        assertEquals(actual.getName(), expected.getName());
        assertEquals(actual.getDescr(), expected.getDescr());
        assertEquals(actual.getManufacturer(), expected.getManufacturer());
        assertEquals(actual.getMake(), expected.getMake());
        assertEquals(actual.getModel(), expected.getModel());
        assertEquals(actual.getColor(), expected.getColor());
        assertEquals(actual.getSerialNo(), expected.getSerialNo());
        assertEquals(actual.getPrice(), expected.getPrice());
    }

    @Test
    public void testUpdate() {
        final String name = "<NAME>";
        final String descr = "A Test Description";
        final String manufacturer = "Test Manufacturer";
        final String make = "Tester";
        final String model = "Testv1";
        final String color = "Black";
        final String serialno = "123456789";
        final BigDecimal price = new BigDecimal(123.42);

        IMocksControl mocksControl = EasyMock.createControl();
        Item mockItem = mocksControl.createMock(Item.class);
        expect(mockItem.getName()).andReturn(name);
        expect(mockItem.getDescr()).andReturn(descr);
        expect(mockItem.getManufacturer()).andReturn(manufacturer);
        expect(mockItem.getMake()).andReturn(make);
        expect(mockItem.getModel()).andReturn(model);
        expect(mockItem.getColor()).andReturn(color);
        expect(mockItem.getSerialNo()).andReturn(serialno);
        expect(mockItem.getPrice()).andReturn(price);

        ItemDAO mockDAO = mocksControl.createMock(ItemDAO.class);
        expect(mockDAO.get(anyObject(String.class))).andReturn(mockItem);
        mockDAO.update(
                anyObject(Item.class),
                anyObject(String.class),
                anyObject(String.class),
                anyObject(String.class),
                anyObject(String.class),
                anyObject(String.class),
                anyObject(String.class),
                anyObject(BigDecimal.class));
        expectLastCall();

        expect(mockDAO.get(anyObject(String.class))).andReturn(mockItem);

        mocksControl.replay();

        InventoryController inventoryController = new InventoryController();
        ReflectionTestUtils.setField(inventoryController, "itemDAO", mockDAO);

        final Item expected = new Item();
        expected.setName(name);
        expected.setDescr(descr);
        expected.setManufacturer(manufacturer);
        expected.setMake(make);
        expected.setModel(model);
        expected.setColor(color);
        expected.setSerialNo(serialno);
        expected.setPrice(price);
        Item actual = inventoryController.create(name, descr, manufacturer, make, model, color, serialno, price);
        assertEquals(actual.getName(), expected.getName());
        assertEquals(actual.getDescr(), expected.getDescr());
        assertEquals(actual.getManufacturer(), expected.getManufacturer());
        assertEquals(actual.getMake(), expected.getMake());
        assertEquals(actual.getModel(), expected.getModel());
        assertEquals(actual.getColor(), expected.getColor());
        assertEquals(actual.getSerialNo(), expected.getSerialNo());
        assertEquals(actual.getPrice(), expected.getPrice());
    }
}
{'fraction_non_alphanumeric': 0.11550632911392406, 'fraction_numerical': 0.0031645569620253164, 'mean_word_length': 3.3073888091822097, 'pattern_counts': {'":': 0, '<': 16, '<?xml version=': 0, '>': 16, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5327014', 'n_tokens_mistral': 3270, 'n_tokens_neox': 3149, 'n_words': 562}