package com.remondis.remap.collections.nestedCollections;

import static org.assertj.core.api.Assertions.assertThat;

import java.util.Arrays;
import java.util.HashSet;
import java.util.List;
import java.util.Set;

import org.junit.Test;

import com.remondis.remap.Mapper;
import com.remondis.remap.Mapping;
import com.remondis.remap.basic.B;
import com.remondis.remap.basic.BResource;

public class NestedCollectionsTest {
  @Test
  public void shouldMapNestedCollections() {

    Mapper<B, BResource> bMapper = Mapping.from(B.class)
        .to(BResource.class)
        .mapper();
    Mapper<A, AResource> aMapper = Mapping.from(A.class)
        .to(AResource.class)
        .useMapper(bMapper)
        .mapper();

    String[] stringsArr = new String[] {
        "A", "B", "C", "D"
    };

    String b1String = "b1String";
    int b1Number = 101;
    Integer b1Integer = 201;
    B b1 = new B(b1String, b1Number, b1Integer);

    String b2String = "b2String";
    int b2Number = 331;
    Integer b2Integer = 441;
    B b2 = new B(b2String, b2Number, b2Integer);

    A a = new A();

    Set<B> firstList = new HashSet<>(Arrays.asList(b1));
    Set<B> secondList = new HashSet<>(Arrays.asList(b2));
    a.addNestedLists(firstList, secondList);

    AResource ar = aMapper.map(a);

    // Assert before mapping (paranoia check)
    List<Set<B>> nestedListsBefore = a.getNestedLists();
    assertThat(nestedListsBefore).isInstanceOf(List.class);
    assertThat(nestedListsBefore.iterator()
        .next()).isInstanceOf(Set.class);

    // Assert after mapping (collections should be nested with according to the destination types)
    Set<List<BResource>> nestedLists = ar.getNestedLists();
    assertThat(nestedLists).isInstanceOf(Set.class);
    assertThat(nestedLists.iterator()
        .next()).isInstanceOf(List.class);
  }

}

@@ -417,16 +417,49 @@
 sTest %7B%0A
+  @SuppressWarnings(%22unchecked%22)%0A
   @Test%0A
@@ -747,84 +747,8 @@
 );%0A%0A
-    String%5B%5D stringsArr = new String%5B%5D %7B%0A        %22A%22, %22B%22, %22C%22, %22D%22%0A    %7D;%0A%0A
     

Test Refactoring