Advertisement
riking

InventoryAddTest.java

Mar 19th, 2013
216
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 10.22 KB | None | 0 0
  1. package org.bukkit.craftbukkit.inventory;
  2.  
  3. import static org.junit.Assert.*;
  4. import static org.hamcrest.Matchers.*;
  5.  
  6. import java.util.Collections;
  7. import java.util.HashMap;
  8.  
  9. import net.minecraft.server.TileEntityChest;
  10.  
  11. import org.bukkit.Material;
  12. import org.bukkit.inventory.Inventory;
  13. import org.bukkit.inventory.ItemStack;
  14. import org.bukkit.support.AbstractTestingBase;
  15. import org.junit.Test;
  16.  
  17. public class InventoryAddTest extends AbstractTestingBase {
  18.     public static ItemStack[] emptyChest = new ItemStack[] { null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null};
  19.  
  20.     @Test
  21.     public void testAdd64OfMax64() {
  22.         TileEntityChest nmsinv = new TileEntityChest();
  23.         Inventory bukkitinv = new CraftInventory(nmsinv);
  24.         HashMap<Integer, ItemStack> leftover = bukkitinv.addItem(new ItemStack(Material.DIRT, 64));
  25.  
  26.         ItemStack[] expected = emptyChest.clone();
  27.         expected[0] = new ItemStack(Material.DIRT, 64);
  28.  
  29.         assertThat(bukkitinv.getContents(), is(expected));
  30.         assertThat(leftover, is(Collections.EMPTY_MAP));
  31.     }
  32.  
  33.     @Test
  34.     public void testAdd100OfMax64() {
  35.         TileEntityChest nmsinv = new TileEntityChest();
  36.         Inventory bukkitinv = new CraftInventory(nmsinv);
  37.         HashMap<Integer, ItemStack> leftover = bukkitinv.addItem(new ItemStack(Material.DIRT, 100));
  38.  
  39.         ItemStack[] expected = emptyChest.clone();
  40.         expected[0] = new ItemStack(Material.DIRT, 64);
  41.         expected[1] = new ItemStack(Material.DIRT, 36);
  42.  
  43.         assertThat(bukkitinv.getContents(), is(expected));
  44.         assertThat(leftover, is(Collections.EMPTY_MAP));
  45.     }
  46.    
  47.     @Test
  48.     public void testAddSplit64OfMax64() {
  49.         TileEntityChest nmsinv = new TileEntityChest();
  50.         Inventory bukkitinv = new CraftInventory(nmsinv);
  51.         HashMap<Integer, ItemStack> leftover = bukkitinv.addItemSplit(new ItemStack(Material.DIRT, 64));
  52.  
  53.         ItemStack[] expected = emptyChest.clone();
  54.         expected[0] = new ItemStack(Material.DIRT, 64);
  55.  
  56.         assertThat(bukkitinv.getContents(), is(expected));
  57.         assertThat(leftover, is(Collections.EMPTY_MAP));
  58.     }
  59.  
  60.     @Test
  61.     public void testAddSplit100OfMax64() {
  62.         TileEntityChest nmsinv = new TileEntityChest();
  63.         Inventory bukkitinv = new CraftInventory(nmsinv);
  64.         HashMap<Integer, ItemStack> leftover = bukkitinv.addItemSplit(new ItemStack(Material.DIRT, 100));
  65.  
  66.         ItemStack[] expected = emptyChest.clone();
  67.         expected[0] = new ItemStack(Material.DIRT, 64);
  68.         expected[1] = new ItemStack(Material.DIRT, 36);
  69.  
  70.         assertThat(bukkitinv.getContents(), is(expected));
  71.         assertThat(leftover, is(Collections.EMPTY_MAP));
  72.     }
  73.  
  74.     @Test
  75.     public void testAdd64OfMax64ToExisting10() {
  76.         TileEntityChest nmsinv = new TileEntityChest();
  77.         Inventory bukkitinv = new CraftInventory(nmsinv);
  78.         bukkitinv.setItem(0, new ItemStack(Material.DIRT, 10));
  79.         HashMap<Integer, ItemStack> leftover = bukkitinv.addItem(new ItemStack(Material.DIRT, 64));
  80.  
  81.         ItemStack[] expected = emptyChest.clone();
  82.         expected[0] = new ItemStack(Material.DIRT, 64);
  83.         expected[1] = new ItemStack(Material.DIRT, 10);
  84.  
  85.         assertThat(bukkitinv.getContents(), is(expected));
  86.         assertThat(leftover, is(Collections.EMPTY_MAP));
  87.     }
  88.    
  89.     @Test
  90.     public void testAdd100OfMax64ToExisting10() {
  91.         TileEntityChest nmsinv = new TileEntityChest();
  92.         Inventory bukkitinv = new CraftInventory(nmsinv);
  93.         bukkitinv.setItem(0, new ItemStack(Material.DIRT, 10));
  94.         HashMap<Integer, ItemStack> leftover = bukkitinv.addItem(new ItemStack(Material.DIRT, 100));
  95.  
  96.         ItemStack[] expected = emptyChest.clone();
  97.         expected[0] = new ItemStack(Material.DIRT, 64);
  98.         expected[1] = new ItemStack(Material.DIRT, 46);
  99.  
  100.         assertThat(bukkitinv.getContents(), is(expected));
  101.         assertThat(leftover, is(Collections.EMPTY_MAP));
  102.     }
  103.    
  104.     @Test
  105.     public void testAddSplit64OfMax64ToExisting10() {
  106.         TileEntityChest nmsinv = new TileEntityChest();
  107.         Inventory bukkitinv = new CraftInventory(nmsinv);
  108.         bukkitinv.setItem(0, new ItemStack(Material.DIRT, 10));
  109.         HashMap<Integer, ItemStack> leftover = bukkitinv.addItemSplit(new ItemStack(Material.DIRT, 64));
  110.  
  111.         ItemStack[] expected = emptyChest.clone();
  112.         expected[0] = new ItemStack(Material.DIRT, 64);
  113.         expected[1] = new ItemStack(Material.DIRT, 10);
  114.  
  115.         assertThat(bukkitinv.getContents(), is(expected));
  116.         assertThat(leftover, is(Collections.EMPTY_MAP));
  117.     }
  118.    
  119.     @Test
  120.     public void testAddSplit100OfMax64ToExisting10() {
  121.         TileEntityChest nmsinv = new TileEntityChest();
  122.         Inventory bukkitinv = new CraftInventory(nmsinv);
  123.         bukkitinv.setItem(0, new ItemStack(Material.DIRT, 10));
  124.         HashMap<Integer, ItemStack> leftover = bukkitinv.addItemSplit(new ItemStack(Material.DIRT, 100));
  125.  
  126.         ItemStack[] expected = emptyChest.clone();
  127.         expected[0] = new ItemStack(Material.DIRT, 64);
  128.         expected[1] = new ItemStack(Material.DIRT, 46);
  129.  
  130.         assertThat(bukkitinv.getContents(), is(expected));
  131.         assertThat(leftover, is(Collections.EMPTY_MAP));
  132.     }
  133.    
  134.     @Test
  135.     public void testAdd64OfMax16() {
  136.         TileEntityChest nmsinv = new TileEntityChest();
  137.         Inventory bukkitinv = new CraftInventory(nmsinv);
  138.         bukkitinv.setItem(0, new ItemStack(Material.DIRT, 10));
  139.         HashMap<Integer, ItemStack> leftover = bukkitinv.addItem(new ItemStack(Material.DIRT, 100));
  140.  
  141.         ItemStack[] expected = emptyChest.clone();
  142.         expected[0] = new ItemStack(Material.DIRT, 64);
  143.         expected[1] = new ItemStack(Material.DIRT, 46);
  144.  
  145.         assertThat(bukkitinv.getContents(), is(expected));
  146.         assertThat(leftover, is(Collections.EMPTY_MAP));
  147.     }
  148.  
  149.     @Test
  150.     public void testAdd100OfMax16() {
  151.         TileEntityChest nmsinv = new TileEntityChest();
  152.         Inventory bukkitinv = new CraftInventory(nmsinv);
  153.         HashMap<Integer, ItemStack> leftover = bukkitinv.addItem(new ItemStack(Material.ENDER_PEARL, 100));
  154.  
  155.         ItemStack[] expected = emptyChest.clone();
  156.         expected[0] = new ItemStack(Material.ENDER_PEARL, 64);
  157.         expected[1] = new ItemStack(Material.ENDER_PEARL, 36);
  158.  
  159.         assertThat(bukkitinv.getContents(), is(expected));
  160.         assertThat(leftover, is(Collections.EMPTY_MAP));
  161.     }
  162.  
  163.     @Test
  164.     public void testAddSplit64OfMax16() {
  165.         TileEntityChest nmsinv = new TileEntityChest();
  166.         Inventory bukkitinv = new CraftInventory(nmsinv);
  167.         HashMap<Integer, ItemStack> leftover = bukkitinv.addItemSplit(new ItemStack(Material.ENDER_PEARL, 64));
  168.  
  169.         ItemStack[] expected = emptyChest.clone();
  170.         expected[0] = new ItemStack(Material.ENDER_PEARL, 16);
  171.         expected[1] = new ItemStack(Material.ENDER_PEARL, 16);
  172.         expected[2] = new ItemStack(Material.ENDER_PEARL, 16);
  173.         expected[3] = new ItemStack(Material.ENDER_PEARL, 16);
  174.  
  175.         assertThat(bukkitinv.getContents(), is(expected));
  176.         assertThat(leftover, is(Collections.EMPTY_MAP));
  177.     }
  178.  
  179.     @Test
  180.     public void testAddSplit100OfMax16() {
  181.         TileEntityChest nmsinv = new TileEntityChest();
  182.         Inventory bukkitinv = new CraftInventory(nmsinv);
  183.         HashMap<Integer, ItemStack> leftover = bukkitinv.addItemSplit(new ItemStack(Material.ENDER_PEARL, 100));
  184.  
  185.         ItemStack[] expected = emptyChest.clone();
  186.         expected[0] = new ItemStack(Material.ENDER_PEARL, 16);
  187.         expected[1] = new ItemStack(Material.ENDER_PEARL, 16);
  188.         expected[2] = new ItemStack(Material.ENDER_PEARL, 16);
  189.         expected[3] = new ItemStack(Material.ENDER_PEARL, 16);
  190.         expected[4] = new ItemStack(Material.ENDER_PEARL, 16);
  191.         expected[5] = new ItemStack(Material.ENDER_PEARL, 16);
  192.         expected[6] = new ItemStack(Material.ENDER_PEARL, 4);
  193.  
  194.         assertThat(bukkitinv.getContents(), is(expected));
  195.         assertThat(leftover, is(Collections.EMPTY_MAP));
  196.     }
  197.    
  198.     @Test
  199.     public void testAdd64OfMax16ToExisting10() {
  200.         TileEntityChest nmsinv = new TileEntityChest();
  201.         Inventory bukkitinv = new CraftInventory(nmsinv);
  202.         bukkitinv.setItem(0, new ItemStack(Material.ENDER_PEARL, 10));
  203.         HashMap<Integer, ItemStack> leftover = bukkitinv.addItem(new ItemStack(Material.ENDER_PEARL, 64));
  204.  
  205.         ItemStack[] expected = emptyChest.clone();
  206.         expected[0] = new ItemStack(Material.ENDER_PEARL, 64);
  207.         expected[1] = new ItemStack(Material.ENDER_PEARL, 10);
  208.  
  209.         assertThat(bukkitinv.getContents(), is(expected));
  210.         assertThat(leftover, is(Collections.EMPTY_MAP));
  211.     }
  212.    
  213.     @Test
  214.     public void testAdd100OfMax16ToExisting10() {
  215.         TileEntityChest nmsinv = new TileEntityChest();
  216.         Inventory bukkitinv = new CraftInventory(nmsinv);
  217.         bukkitinv.setItem(0, new ItemStack(Material.ENDER_PEARL, 10));
  218.         HashMap<Integer, ItemStack> leftover = bukkitinv.addItem(new ItemStack(Material.ENDER_PEARL, 100));
  219.  
  220.         ItemStack[] expected = emptyChest.clone();
  221.         expected[0] = new ItemStack(Material.ENDER_PEARL, 64);
  222.         expected[1] = new ItemStack(Material.ENDER_PEARL, 46);
  223.  
  224.         assertThat(bukkitinv.getContents(), is(expected));
  225.         assertThat(leftover, is(Collections.EMPTY_MAP));
  226.     }
  227.    
  228.     @Test
  229.     public void testAddSplit64OfMax16ToExisting10() {
  230.         TileEntityChest nmsinv = new TileEntityChest();
  231.         Inventory bukkitinv = new CraftInventory(nmsinv);
  232.         bukkitinv.setItem(0, new ItemStack(Material.ENDER_PEARL, 10));
  233.         HashMap<Integer, ItemStack> leftover = bukkitinv.addItemSplit(new ItemStack(Material.ENDER_PEARL, 64));
  234.  
  235.         ItemStack[] expected = emptyChest.clone();
  236.         expected[0] = new ItemStack(Material.ENDER_PEARL, 16);
  237.         expected[1] = new ItemStack(Material.ENDER_PEARL, 16);
  238.         expected[2] = new ItemStack(Material.ENDER_PEARL, 16);
  239.         expected[3] = new ItemStack(Material.ENDER_PEARL, 16);
  240.         expected[4] = new ItemStack(Material.ENDER_PEARL, 10);
  241.  
  242.         assertThat(bukkitinv.getContents(), is(expected));
  243.         assertThat(leftover, is(Collections.EMPTY_MAP));
  244.     }
  245.    
  246.     @Test
  247.     public void testAddSplit100OfMax16ToExisting10() {
  248.         TileEntityChest nmsinv = new TileEntityChest();
  249.         Inventory bukkitinv = new CraftInventory(nmsinv);
  250.         bukkitinv.setItem(0, new ItemStack(Material.ENDER_PEARL, 10));
  251.         HashMap<Integer, ItemStack> leftover = bukkitinv.addItemSplit(new ItemStack(Material.ENDER_PEARL, 100));
  252.  
  253.         ItemStack[] expected = emptyChest.clone();
  254.         expected[0] = new ItemStack(Material.ENDER_PEARL, 16);
  255.         expected[1] = new ItemStack(Material.ENDER_PEARL, 16);
  256.         expected[2] = new ItemStack(Material.ENDER_PEARL, 16);
  257.         expected[3] = new ItemStack(Material.ENDER_PEARL, 16);
  258.         expected[4] = new ItemStack(Material.ENDER_PEARL, 16);
  259.         expected[5] = new ItemStack(Material.ENDER_PEARL, 16);
  260.         expected[6] = new ItemStack(Material.ENDER_PEARL, 14);
  261.  
  262.         assertThat(bukkitinv.getContents(), is(expected));
  263.         assertThat(leftover, is(Collections.EMPTY_MAP));
  264.     }
  265. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement