package models;

import com.neovisionaries.i18n.CountryCode;
import common.models.CommonDataBuilder;
import common.models.UserContext;
import io.sphere.sdk.models.LocalizedStrings;
import io.sphere.sdk.products.*;
import io.sphere.sdk.producttypes.ProductType;
import io.sphere.sdk.producttypes.ProductTypeBuilder;
import org.junit.Test;
import play.i18n.Lang;

import java.util.Arrays;
import java.util.List;

import static java.util.Collections.emptyList;
import static org.fest.assertions.Assertions.assertThat;

public class CommonDataTest {

    @Test
    public void hasProvidedProductList() {
        List<Product> productList = Arrays.asList(defaultProduct());
        CommonDataBuilder builder = CommonDataBuilder.of(defaultContext(), emptyList()).products(productList);
        assertThat(builder.build().products()).isEqualTo(productList);
    }

    @Test
    public void hasEmptyProductListWhenNoneProvided() {
        CommonDataBuilder builder = CommonDataBuilder.of(defaultContext(), emptyList());
        assertThat(builder.build().products()).isEmpty();
    }

    private UserContext defaultContext() {
        return UserContext.of(Lang.forCode("de"), CountryCode.DE);
    }

    private Product defaultProduct() {
        ProductType productType = ProductTypeBuilder.of("id", "product-type", "", emptyList()).build();
        LocalizedStrings locString = LocalizedStrings.ofEnglishLocale("text");
        ProductVariant variant = ProductVariantBuilder.of(1).build();
        ProductData productData = ProductDataBuilder.of(locString, locString, variant).build();
        ProductCatalogData catalogData = ProductCatalogDataBuilder.ofStaged(productData).build();
        return ProductBuilder.of(productType, catalogData).build();
    }
}

@@ -404,16 +404,83 @@
 .List;%0A%0A
+import static io.sphere.sdk.products.ProductProjectionType.STAGED;%0A
 import s
@@ -514,24 +514,24 @@
 .emptyList;%0A
-
 import stati
@@ -680,16 +680,26 @@
 %3CProduct
+Projection
 %3E produc
@@ -1284,16 +1284,26 @@
  Product
+Projection
  default
@@ -1753,32 +1753,32 @@
 tData).build();%0A
-
         return P
@@ -1823,22 +1823,49 @@
 ata).build()
+.toProjection(STAGED).get()
 ;%0A    %7D%0A%7D%0A

Fix test.