package com.elmakers.mine.bukkit.magic;

import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;

import org.bukkit.Material;
import org.bukkit.block.Block;
import org.junit.Test;
import org.mockito.Mockito;

import com.elmakers.mine.bukkit.api.magic.MaterialSet;
import com.elmakers.mine.bukkit.block.MaterialAndData;
import com.elmakers.mine.bukkit.utility.ConfigurationUtils;

public class MaterialSetsTest {
    @Test
    public void testTestBlock() {
        MaterialSet set = MaterialSets.unionBuilder()
                .add(Material.STONE)
                .build();

        assertTrue(set.testBlock(stone()));
        assertFalse(set.testBlock(dirt()));
    }

    @SuppressWarnings("deprecation")
    @Test
    public void testFromConfig() {
        MaterialAndData value = ConfigurationUtils.toMaterialAndData("stone|2");
        MaterialSet set = MaterialSets.unionBuilder()
                .add(value)
                .build();

        assertFalse(set.testBlock(stone()));
        assertFalse(set.testBlock(dirt()));

        Block correct = stone();
        Mockito.when(correct.getData()).thenReturn((byte) 2);
        assertTrue(set.testBlock(correct));
    }

    private Block dirt() {
        Block dirt = Mockito.mock(Block.class);
        Mockito.when(dirt.getType()).thenReturn(Material.DIRT);
        return dirt;
    }

    private Block stone() {
        Block dirt = Mockito.mock(Block.class);
        Mockito.when(dirt.getType()).thenReturn(Material.STONE);
        return dirt;
    }
}

@@ -181,16 +181,123 @@
 .Block;%0A
+import org.bukkit.configuration.ConfigurationSection;%0Aimport org.bukkit.configuration.MemoryConfiguration;%0A
 import o
@@ -1300,32 +1300,861 @@
 rrect));%0A    %7D%0A%0A
+    @Test%0A    public void testComplexSet() %7B%0A        SimpleMaterialSetManager manager = new SimpleMaterialSetManager();%0A        ConfigurationSection materialConfigs = new MemoryConfiguration();%0A        materialConfigs.set(%22transparent%22, %22air,water,lava,glass%22);%0A        materialConfigs.set(%22liquid%22, %22water,lava%22);%0A        manager.loadMaterials(materialConfigs);%0A%0A        // Should contain liquid but not air or glass%0A        MaterialSet set = manager.fromConfig(%22liquid,!transparent%22);%0A        assertFalse(set.testMaterial(Material.AIR));%0A        assertTrue(set.testMaterial(Material.WATER));%0A%0A        // Should contain none of the materials in either set%0A        set = manager.fromConfig(%22!transparent,liquid%22);%0A        assertFalse(set.testMaterial(Material.AIR));%0A        assertFalse(set.testMaterial(Material.WATER));%0A    %7D%0A%0A
     private Bloc

Add unit test for complex sets of materials