// Path: src/main/java/org/gbif/common/parsers/core/Parsable.java
// public interface Parsable<T> {
// 
//   /**
//    * Tries to parse the input and returns a {@link ParseResult} object.
//    * This should never return <code>null</code> as parse errors will be indicated in the returned object.
//    *
//    * @param input To parse
//    *
//    * @return The output result of the operation
//    */
//   ParseResult<T> parse(String input);
// }
// 
// Path: src/main/java/org/gbif/common/parsers/core/ParseResult.java
// public class ParseResult<T> {
// 
//   // the result code of the parse operation
//   public enum STATUS {
//     SUCCESS, FAIL, ERROR
//   }
// 
//   // the confidence of the result, applicable if status=SUCCESS
//   public enum CONFIDENCE {
//     DEFINITE, PROBABLE, POSSIBLE
//   }
// 
//   // the details of the response
//   protected final STATUS status;
//   protected final CONFIDENCE confidence;
//   protected final T payload;
//   protected final List<T> alternativePayloads;
//   protected final Throwable error;
// 
//   /**
//    * @param <T1>       The generic type of the payload
//    * @param confidence The confidence in the result
//    * @param payload    The payload of the parse result
//    *
//    * @return The new ParseResult which has no error and status of SUCCESS
//    */
//   public static <T1> ParseResult<T1> success(CONFIDENCE confidence, T1 payload) {
//     return new ParseResult<T1>(STATUS.SUCCESS, confidence, payload, null, null);
//   }
// 
//   /**
//    * @return A new parse response with only the status set to FAIL
//    */
//   public static <T1> ParseResult<T1> fail() {
//     return new ParseResult<T1>(STATUS.FAIL, null, null, null, null);
//   }
// 
//   /**
//    * @return A new parse response configured to indicate an error
//    */
//   public static <T1> ParseResult<T1> error() {
//     return new ParseResult<T1>(STATUS.ERROR, null, null, null, null);
//   }
// 
//   /**
//    * @param cause The cause of the error
//    *
//    * @return A new parse response configured with error and the cause
//    */
//   public static <T1> ParseResult<T1> error(Throwable cause) {
//     return new ParseResult<T1>(STATUS.ERROR, null, null, null, cause);
//   }
// 
//   /**
//    * Forces all fields to be provided
//    *
//    * @param status     The status of the response
//    * @param confidence The confidence in the result
//    * @param payload    The payload of the response
//    * @param error      The error in the response
//    */
//   public ParseResult(STATUS status, CONFIDENCE confidence, T payload, List<T> alternativePayloads, Throwable error) {
//     this.status = status;
//     this.confidence = confidence;
//     this.alternativePayloads = alternativePayloads;
//     this.payload = payload;
//     this.error = error;
//   }
// 
//   public STATUS getStatus() {
//     return status;
//   }
// 
//   public CONFIDENCE getConfidence() {
//     return confidence;
//   }
// 
//   public T getPayload() {
//     return payload;
//   }
// 
//   public List<T> getAlternativePayloads() {
//     return alternativePayloads;
//   }
// 
//   public Throwable getError() {
//     return error;
//   }
// 
//   /**
//    * Returns true if {@link #getStatus()} returns SUCCESS.
//    *
//    * @return true if the parse operation was successful.
//    */
//   public boolean isSuccessful() {
//     return status == STATUS.SUCCESS;
//   }
// 
//   @Override
//   public String toString() {
//     return new ToStringBuilder(this, ToStringStyle.SHORT_PREFIX_STYLE)
//       .append("status", getStatus())
//       .append("confidence", getConfidence())
//       .append("payload", getPayload())
//       .append("alternativePayloads", getAlternativePayloads())
//       .append("error", getError()).toString();
//   }
// }


import org.gbif.common.parsers.core.Parsable;
import org.gbif.common.parsers.core.ParseResult;
import java.io.BufferedReader;
import java.io.IOException;
import java.util.Objects;
import org.apache.commons.lang3.StringUtils;
import org.junit.jupiter.api.BeforeEach;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNotNull;
/*
 * 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 org.gbif.common.parsers;





public abstract class ParserTestBase<T> implements LineProcessor<ParserTestBase.BatchParseResult>  {
  protected final Parsable<T> parser;
  private BatchParseResult batchResult;

  public static class BatchParseResult {
    public int total;
    public int failed;
  }

  @BeforeEach
  public void setupBatch() {
    batchResult = new BatchParseResult();
  }

  public ParserTestBase(Parsable<T> parser) {
    this.parser = parser;
  }

  protected void assertParseFailure(String input) {
    ParseResult<T> parsed = parser.parse(input);
    assertEquals(ParseResult.STATUS.FAIL, parsed.getStatus(), "Expected " + input + " to fail but got " + parsed.getPayload() + " instead");
  }

  protected void assertParseSuccess(T expected, String input) {
    assertParseSuccess(expected, ParseResult.CONFIDENCE.DEFINITE, input);
  }

  protected void assertParseSuccess(T expected, ParseResult.CONFIDENCE confidence, String input) {
// Path: src/main/java/org/gbif/common/parsers/core/Parsable.java
// public interface Parsable<T> {
// 
//   /**
//    * Tries to parse the input and returns a {@link ParseResult} object.
//    * This should never return <code>null</code> as parse errors will be indicated in the returned object.
//    *
//    * @param input To parse
//    *
//    * @return The output result of the operation
//    */
//   ParseResult<T> parse(String input);
// }
// 
// Path: src/main/java/org/gbif/common/parsers/core/ParseResult.java
// public class ParseResult<T> {
// 
//   // the result code of the parse operation
//   public enum STATUS {
//     SUCCESS, FAIL, ERROR
//   }
// 
//   // the confidence of the result, applicable if status=SUCCESS
//   public enum CONFIDENCE {
//     DEFINITE, PROBABLE, POSSIBLE
//   }
// 
//   // the details of the response
//   protected final STATUS status;
//   protected final CONFIDENCE confidence;
//   protected final T payload;
//   protected final List<T> alternativePayloads;
//   protected final Throwable error;
// 
//   /**
//    * @param <T1>       The generic type of the payload
//    * @param confidence The confidence in the result
//    * @param payload    The payload of the parse result
//    *
//    * @return The new ParseResult which has no error and status of SUCCESS
//    */
//   public static <T1> ParseResult<T1> success(CONFIDENCE confidence, T1 payload) {
//     return new ParseResult<T1>(STATUS.SUCCESS, confidence, payload, null, null);
//   }
// 
//   /**
//    * @return A new parse response with only the status set to FAIL
//    */
//   public static <T1> ParseResult<T1> fail() {
//     return new ParseResult<T1>(STATUS.FAIL, null, null, null, null);
//   }
// 
//   /**
//    * @return A new parse response configured to indicate an error
//    */
//   public static <T1> ParseResult<T1> error() {
//     return new ParseResult<T1>(STATUS.ERROR, null, null, null, null);
//   }
// 
//   /**
//    * @param cause The cause of the error
//    *
//    * @return A new parse response configured with error and the cause
//    */
//   public static <T1> ParseResult<T1> error(Throwable cause) {
//     return new ParseResult<T1>(STATUS.ERROR, null, null, null, cause);
//   }
// 
//   /**
//    * Forces all fields to be provided
//    *
//    * @param status     The status of the response
//    * @param confidence The confidence in the result
//    * @param payload    The payload of the response
//    * @param error      The error in the response
//    */
//   public ParseResult(STATUS status, CONFIDENCE confidence, T payload, List<T> alternativePayloads, Throwable error) {
//     this.status = status;
//     this.confidence = confidence;
//     this.alternativePayloads = alternativePayloads;
//     this.payload = payload;
//     this.error = error;
//   }
// 
//   public STATUS getStatus() {
//     return status;
//   }
// 
//   public CONFIDENCE getConfidence() {
//     return confidence;
//   }
// 
//   public T getPayload() {
//     return payload;
//   }
// 
//   public List<T> getAlternativePayloads() {
//     return alternativePayloads;
//   }
// 
//   public Throwable getError() {
//     return error;
//   }
// 
//   /**
//    * Returns true if {@link #getStatus()} returns SUCCESS.
//    *
//    * @return true if the parse operation was successful.
//    */
//   public boolean isSuccessful() {
//     return status == STATUS.SUCCESS;
//   }
// 
//   @Override
//   public String toString() {
//     return new ToStringBuilder(this, ToStringStyle.SHORT_PREFIX_STYLE)
//       .append("status", getStatus())
//       .append("confidence", getConfidence())
//       .append("payload", getPayload())
//       .append("alternativePayloads", getAlternativePayloads())
//       .append("error", getError()).toString();
//   }
// }


// Path: src/test/java/org/gbif/common/parsers/ParserTestBase.java
import org.gbif.common.parsers.core.Parsable;
import org.gbif.common.parsers.core.ParseResult;
import java.io.BufferedReader;
import java.io.IOException;
import java.util.Objects;
import org.apache.commons.lang3.StringUtils;
import org.junit.jupiter.api.BeforeEach;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNotNull;

/*
 * 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 org.gbif.common.parsers;





public abstract class ParserTestBase<T> implements LineProcessor<ParserTestBase.BatchParseResult>  {
  protected final Parsable<T> parser;
  private BatchParseResult batchResult;

  public static class BatchParseResult {
    public int total;
    public int failed;
  }

  @BeforeEach
  public void setupBatch() {
    batchResult = new BatchParseResult();
  }

  public ParserTestBase(Parsable<T> parser) {
    this.parser = parser;
  }

  protected void assertParseFailure(String input) {
    ParseResult<T> parsed = parser.parse(input);
    assertEquals(ParseResult.STATUS.FAIL, parsed.getStatus(), "Expected " + input + " to fail but got " + parsed.getPayload() + " instead");
  }

  protected void assertParseSuccess(T expected, String input) {
    assertParseSuccess(expected, ParseResult.CONFIDENCE.DEFINITE, input);
  }

  protected void assertParseSuccess(T expected, ParseResult.CONFIDENCE confidence, String input) {
    ParseResult<T> parsed = parser.parse(input);