View Javadoc
1   /*
2    * Copyright 2017 Andrew Rucker Jones.
3    *
4    * Licensed under the Apache License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    *
8    *      http://www.apache.org/licenses/LICENSE-2.0
9    *
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
15   */
16  package com.opencsv.bean.mocks;
17  
18  import com.opencsv.CSVReader;
19  import com.opencsv.bean.MappingStrategy;
20  import com.opencsv.exceptions.CsvBadConverterException;
21  import com.opencsv.exceptions.CsvBeanIntrospectionException;
22  import org.apache.commons.lang3.ArrayUtils;
23  
24  public class ErrorLineMappingStrategy<T> implements MappingStrategy<T> {
25      @Override
26      public void captureHeader(CSVReader reader) {
27      }
28  
29      @Override
30      public String[] generateHeader(T bean) {
31          return new String[0];
32      }
33      
34      @Override
35      public void setType(Class<? extends T> type) throws CsvBadConverterException {}
36  
37      @Override
38      public T populateNewBean(String[] line) throws CsvBeanIntrospectionException {
39         throw new CsvBeanIntrospectionException("This is a test exception.");
40      }
41  
42      @Override
43      public String[] transmuteBean(T bean) {
44          return ArrayUtils.EMPTY_STRING_ARRAY;
45      }
46  }