Package org.assertj.core.extractor

Source Code of org.assertj.core.extractor.ByNameMultipleExtractor

package org.assertj.core.extractor;

import java.util.ArrayList;
import java.util.List;

import org.assertj.core.api.iterable.Extractor;
import org.assertj.core.groups.Tuple;

class ByNameMultipleExtractor<T> implements Extractor<T, Tuple>{

  private final String[] fieldsOrProperties;

  ByNameMultipleExtractor(String... fieldsOrProperties) {
    this.fieldsOrProperties = fieldsOrProperties;
  }

  @Override
  public Tuple extract(T input) {
    if (fieldsOrProperties == null)
      throw new IllegalArgumentException("The names of the fields/properties to read should not be null");
    if (fieldsOrProperties.length == 0)
      throw new IllegalArgumentException("The names of the fields/properties to read should not be empty");
    if (input == null)
      throw new IllegalArgumentException("The object to extract fields/properties from should not be null");

    List<Extractor<T, Object>> extractors = buildExtractors();
    List<Object> values = extractValues(input, extractors);
   
    return new Tuple(values.toArray());
  }

  private List<Object> extractValues(T input, List<Extractor<T, Object>> singleExtractors) {
    List<Object> values = new ArrayList<Object>();
   
    for (Extractor<T, Object> extractor : singleExtractors) {
      values.add(extractor.extract(input));
    }
    return values;
  }

  private List<Extractor<T, Object>> buildExtractors() {
    List<Extractor<T, Object>> result = new ArrayList<Extractor<T,Object>>();
   
    for (String name : fieldsOrProperties) {
      result.add(new ByNameSingleExtractor<T>(name));
    }
   
    return result;
  }

}
TOP

Related Classes of org.assertj.core.extractor.ByNameMultipleExtractor

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.