001/*
002 * Licensed to the Apache Software Foundation (ASF) under one or more
003 * contributor license agreements.  See the NOTICE file distributed with
004 * this work for additional information regarding copyright ownership.
005 * The ASF licenses this file to You under the Apache License, Version 2.0
006 * (the "License"); you may not use this file except in compliance with
007 * the License.  You may obtain a copy of the License at
008 *
009 *      http://www.apache.org/licenses/LICENSE-2.0
010 *
011 * Unless required by applicable law or agreed to in writing, software
012 * distributed under the License is distributed on an "AS IS" BASIS,
013 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014 * See the License for the specific language governing permissions and
015 * limitations under the License.
016 */
017package org.apache.juneau.terminal.report;
018
019/**
020 * Picks a {@link ReportReader} by report kind.
021 *
022 * <p>
023 * The kinds are <c>surefire</c>, <c>junitxml</c>, <c>pytest</c>, <c>jest-json</c> and <c>playwright-json</c>.  The
024 * parent kind <c>junitxml</c> yields the framework key <c>junit-xml</c>; a host that knows the file came from pytest
025 * asks for <c>pytest</c>, which yields the key <c>pytest</c>.  Readers are stateless, so each kind shares one instance.
026 */
027public final class ReportReaders {
028
029   private static final ReportReader SUREFIRE = new SurefireReportReader();
030   private static final ReportReader JUNIT_XML = new JUnitXmlReportReader();
031   private static final ReportReader PYTEST = new JUnitXmlReportReader("pytest");
032   private static final ReportReader JEST = new JestJsonReportReader();
033   private static final ReportReader PLAYWRIGHT = new PlaywrightJsonReportReader();
034
035   private ReportReaders() {}
036
037   /**
038    * Returns the reader for a report kind.
039    *
040    * @param kind The kind.  May be <jk>null</jk>.
041    * @return The reader, or <jk>null</jk> if the kind is unknown.
042    */
043   public static ReportReader forKind(String kind) {
044      if (kind == null)
045         return null;
046      return switch (kind) {
047         case "surefire" -> SUREFIRE;
048         case "junitxml" -> JUNIT_XML;
049         case "pytest" -> PYTEST;
050         case "jest-json" -> JEST;
051         case "playwright-json" -> PLAYWRIGHT;
052         default -> null;
053      };
054   }
055}