/*
 *  @author Ranides Atterwim <ranides@gmail.com>
 *  @copyright Ranides Atterwim
 *  @license WTFPL
 *  @url http://ranides.net/projects/assira
 */
package net.ranides.assira.collection.list;

import java.util.Arrays;
import java.util.List;
import java.util.Locale;
import org.junit.Test;
import static org.junit.Assert.*;

/**
 *
 * @author ranides
 */
public class ListAdapterTest {

    public ListAdapterTest() { }


    @Test
    public void testDynamic() {
        List<Integer> numList = Arrays.asList( 0x43, 0x45, 0x99, 0x22F0 );
        List<String> hexList = new ListAdapter<String,Integer>(numList) {
            @Override
            public String apply(Integer source) {
                return Integer.toHexString(source).toUpperCase(Locale.ROOT);
            }
        };
        numList.set(1, 0x54);
        numList.set(2, 0x66);

        // żywa lista się zmieniła ?
        assertEquals(hexList, Arrays.asList("43","54","66","22F0"));
    }


    @Test
    public void testCopy() {
        List<Integer> numList = Arrays.asList( 0x43, 0x45, 0x99, 0x22F0 );
        ListAdapter<String, Integer> hexList = new ListAdapter<String, Integer>(numList) {
            @Override
            public String apply(Integer source) {
                return Integer.toHexString(source).toUpperCase(Locale.ROOT);
            }
        };

        List<String> appList = hexList.apply();
        numList.set(1, 0x54);
        numList.set(2, 0x66);

        // żywa lista się zmieniła ?
        assertEquals(hexList, Arrays.asList("43","54","66","22F0"));
        // skopiowana lista pozostaje zamrożona ?
        assertEquals(appList, Arrays.asList("43","45","99","22F0"));

    }

}
