package org.ccci.gto.android.common.jsonapi;

import org.ccci.gto.android.common.jsonapi.JsonApiConverter.Includes;
import org.junit.Test;

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

public class IncludesTest {
    @Test
    public void verifyIncludeAll() throws Exception {
        final Includes includes = new Includes((String[]) null);

        assertTrue(includes.include("ajslkdf"));
        assertTrue(includes.include("whe"));
    }

    @Test
    public void verifyIncludeSimple() throws Exception {
        final Includes includes = new Includes("a", "b");

        assertTrue(includes.include("a"));
        assertTrue(includes.include("b"));
        assertFalse(includes.include("c"));
    }

    @Test
    public void verifyIncludeImplicit() throws Exception {
        final Includes includes = new Includes("a.b", "bc", "d.e");

        assertTrue(includes.include("a"));
        assertFalse(includes.include("b"));
        assertTrue(includes.include("d"));
    }

    @Test
    public void verifyDescendantIncludeAll() {
        final Includes includes = new Includes((String[]) null);

        assertTrue(includes.include("ajslkdf"));
        assertTrue(includes.include("whe"));
        assertTrue(includes.descendant("akjsdflj").include("h5h"));
    }

    @Test
    public void verifyDescendantImplict() throws Exception {
        final Includes includes = new Includes("a.b.c", "de.f.g");

        assertTrue(includes.include("a"));
        assertTrue(includes.descendant("a").include("b"));
        assertTrue(includes.descendant("a").descendant("b").include("c"));
        assertFalse(includes.descendant("a").descendant("h").include("c"));
    }
}

@@ -133,16 +133,46 @@
 .Test;%0A%0A
+import java.util.Collection;%0A%0A
 import s
@@ -1737,11 +1737,1568 @@
 );%0A    %7D
+%0A%0A    @Test%0A    public void verifyMerge() throws Exception %7B%0A        final Includes includes = new Includes(%22a.b.c%22).merge(new Includes(%22de.f.g%22));%0A%0A        assertTrue(includes.include(%22a%22));%0A        assertTrue(includes.descendant(%22a%22).include(%22b%22));%0A        assertTrue(includes.descendant(%22a%22).descendant(%22b%22).include(%22c%22));%0A        assertTrue(includes.include(%22de%22));%0A        assertTrue(includes.descendant(%22de%22).include(%22f%22));%0A        assertTrue(includes.descendant(%22de%22).descendant(%22f%22).include(%22g%22));%0A        assertFalse(includes.descendant(%22a%22).descendant(%22h%22).include(%22c%22));%0A    %7D%0A%0A    @Test%0A    public void verifyMergeNull() %7B%0A        final Includes includes = new Includes(%22a.b.c%22, %22de.f.g%22).merge(null);%0A%0A        assertTrue(includes.include(%22a%22));%0A        assertTrue(includes.descendant(%22a%22).include(%22b%22));%0A        assertTrue(includes.descendant(%22a%22).descendant(%22b%22).include(%22c%22));%0A        assertFalse(includes.descendant(%22a%22).descendant(%22h%22).include(%22c%22));%0A    %7D%0A%0A    @Test%0A    public void testMergeIncludeAll() %7B%0A        final Includes includes1 = new Includes((Collection%3CString%3E) null).merge(new Includes());%0A        assertTrue(includes1.include(%22ajslkdf%22));%0A        assertTrue(includes1.include(%22whe%22));%0A        assertTrue(includes1.descendant(%22akjsdflj%22).include(%22h5h%22));%0A%0A        final Includes includes2 = new Includes().merge(new Includes((Collection%3CString%3E) null));%0A        assertTrue(includes2.include(%22ajslkdf%22));%0A        assertTrue(includes2.include(%22whe%22));%0A        assertTrue(includes2.descendant(%22akjsdflj%22).include(%22h5h%22));%0A    %7D
 %0A%7D%0A

test includes merge functionality