/*
 * Copyright 2011-2015 the original author or authors.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package com.github.camaral.sheeco.processor;

import java.util.List;

import org.testng.Assert;

import org.testng.annotations.Test;

import com.github.camaral.sheeco.annotation.SpreadsheetAttribute;
import com.github.camaral.sheeco.annotation.SpreadsheetElement;
import com.github.camaral.sheeco.annotation.SpreadsheetPayload;
import com.github.camaral.sheeco.processor.Element;
import com.github.camaral.sheeco.processor.ElementScanner;
import com.github.camaral.sheeco.samples.domain.Cat;
import com.github.camaral.sheeco.samples.domain.Fur;

/**
 * @author caio.amaral
 * 
 */
public class ElementScannerTest {
	@Test
	public void testElements() {
		final List<Element> elements = ElementScanner.scan(Cat.class);
		Assert.assertEquals(elements.size(), 2);

		Assert.assertEquals(elements.get(0).getPayload().getPayloadClass(),
				Fur.class);
		Assert.assertEquals(elements.get(0).getFirstColumnIndex(), 3);
		Assert.assertEquals(elements.get(1).getPayload().getPayloadClass(),
				Fur.class);
		Assert.assertEquals(elements.get(1).getFirstColumnIndex(), 5);
	}

	@Test
	public void testNoElement() {
		Assert.assertTrue(ElementScanner.scan(Fur.class).isEmpty());
	}

	@Test
	public void testNotPayload() {
		Assert.assertTrue(ElementScanner.scan(String.class).isEmpty());
	}

	@Test(expectedExceptions = AssertionError.class)
	public void testMoreThanOneList() {
		ElementScanner.scan(InvalidTwoList.class);
	}
}

@SpreadsheetPayload(name = "InvalidPayload")
class InvalidTwoList {
	@SpreadsheetElement(index = 0)
	private List<B> b1;

	@SpreadsheetElement(index = 0)
	private List<B> b2;
}

@SpreadsheetPayload(name = "B")
class B {
	@SpreadsheetAttribute(index = 0)
	private Integer b;
}

@@ -2150,13 +2150,26 @@
 ist%3C
-B%3E b1
+DummyPayload%3E list
 ;%0A%0A%09
@@ -2217,14 +2217,203 @@
 ist%3C
-B%3E b2;
+DummyPayload%3E cannotDeclareAnotherList;%0A%0A%09public List%3CDummyPayload%3E getList() %7B%0A%09%09return list;%0A%09%7D%0A%0A%09public List%3CDummyPayload%3E getCannotDeclareAnotherList() %7B%0A%09%09return cannotDeclareAnotherList;%0A%09%7D
 %0A%7D%0A%0A
@@ -2450,17 +2450,28 @@
 )%0Aclass 
-B
+DummyPayload
  %7B%0A%09@Spr
@@ -2520,9 +2520,77 @@
 ger 
-b;
+dummyField;%0A%0A%09public Integer getDummyField() %7B%0A%09%09return dummyField;%0A%09%7D
 %0A%7D%0A

Improve names on test