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.bukkit.configuration.ConfigurationSection;
import org.bukkit.configuration.MemoryConfiguration;
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));
    }

    @Test
    public void testNegatedSet() {
        SimpleMaterialSetManager manager = new SimpleMaterialSetManager();
        ConfigurationSection materialConfigs = new MemoryConfiguration();
        materialConfigs.set("solid", "!air,water,lava,glass");
        manager.loadMaterials(materialConfigs);

        // Should contain none of the materials in the negated solid list
        MaterialSet set = manager.getMaterialSet("solid");
        assertFalse(set.testMaterial(Material.AIR));
        assertFalse(set.testMaterial(Material.WATER));
    }

    @Test
    public void testComplexSet() {
        SimpleMaterialSetManager manager = new SimpleMaterialSetManager();
        ConfigurationSection materialConfigs = new MemoryConfiguration();
        materialConfigs.set("transparent", "air,water,lava,glass");
        materialConfigs.set("liquid", "water,lava");
        manager.loadMaterials(materialConfigs);

        // Should contain liquid but not air or glass
        MaterialSet set = manager.fromConfig("liquid,!transparent");
        assertFalse(set.testMaterial(Material.AIR));
        assertTrue(set.testMaterial(Material.WATER));

        // Should contain none of the materials in either set
        set = manager.fromConfig("!transparent,liquid");
        assertFalse(set.testMaterial(Material.AIR));
        assertFalse(set.testMaterial(Material.WATER));
    }

    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;
    }
}

@@ -1854,32 +1854,1148 @@
 WATER));%0A    %7D%0A%0A
+    @Test%0A    public void testWildcardSets() %7B%0A        SimpleMaterialSetManager manager = new SimpleMaterialSetManager();%0A        ConfigurationSection materialConfigs = new MemoryConfiguration();%0A        materialConfigs.set(%22all%22, %22*%22);%0A        materialConfigs.set(%22alsoall%22, %22*,stone%22);%0A        materialConfigs.set(%22alwaysall%22, %22stone,*,!all%22);%0A        materialConfigs.set(%22nothing%22, %22!*%22);%0A        materialConfigs.set(%22alsonothing%22, %22!all%22);%0A        manager.loadMaterials(materialConfigs);%0A%0A        // Should contain everything, just testing for air.%0A        MaterialSet set = manager.getMaterialSet(%22all%22);%0A        assertTrue(set.testMaterial(Material.AIR));%0A        set = manager.getMaterialSet(%22alsoall%22);%0A        assertTrue(set.testMaterial(Material.AIR));%0A        set = manager.getMaterialSet(%22alwaysall%22);%0A        assertTrue(set.testMaterial(Material.AIR));%0A%0A        // Should contain nothing%0A        set = manager.getMaterialSet(%22nothing%22);%0A        assertFalse(set.testMaterial(Material.AIR));%0A        set = manager.getMaterialSet(%22alsonothing%22);%0A        assertFalse(set.testMaterial(Material.AIR));%0A    %7D%0A%0A
     @Test%0A    pu

Add unit tests for wildcard material behaviors