/*
* Copyright 2013 Objectos, Fábrica de Software LTDA.
*
* 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 br.com.objectos.comuns.io.xls;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.equalTo;
import java.io.File;
import java.net.URISyntaxException;
import java.net.URL;
import java.util.List;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.Test;
import br.com.objectos.comuns.io.Line;
import br.com.objectos.comuns.io.ParsedLines;
import com.google.common.collect.ImmutableList;
import com.google.common.io.Resources;
/**
* @author marcio.endo@objectos.com.br (Marcio Endo)
*/
@Test
public class StringXlsConverterTest {
private Line line;
@BeforeClass
public void setUp() throws URISyntaxException {
URL url = Resources.getResource(getClass(), "/xls/sheet.xls");
File file = new File(url.toURI());
ParsedLines parsedLines = XlsFile.parse(file)
.skipFirstLines(1)
.getLines();
List<Line> lines = ImmutableList.copyOf(parsedLines);
line = lines.get(0);
}
public void should_convert_string_column() {
String res = get(7);
assertThat(res, equalTo("abc"));
}
public void should_convert_numeric_long_column() {
String res = get(6);
assertThat(res, equalTo("123"));
}
public void should_convert_numeric_double_column() {
String res = get(2);
assertThat(res, equalTo("1.23"));
}
private String get(int index) {
return line.column(index).get(String.class);
}
}