/*
 * Licensed to the Apache Software Foundation (ASF) under one or more
 * contributor license agreements.  See the NOTICE file distributed with
 * this work for additional information regarding copyright ownership.
 * The ASF licenses this file to You 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.apache.solr.util;

import org.apache.solr.SolrTestCase;
import org.semver4j.SemverException;

public class TestSolrVersion extends SolrTestCase {
  private static final SolrVersion SOLR_9_0_1 = SolrVersion.valueOf("9.0.1");

  public void testToString() {
    assertEquals("9.0.0", SolrVersion.forIntegers(9, 0, 0).toString());
  }

  public void testVersionComponents() {
    SolrVersion v9_0_1_rc1 = SolrVersion.valueOf("9.0.1-rc1.0+b123");
    assertEquals("9.0.1-rc1.0+b123", v9_0_1_rc1.toString());
    assertEquals(9, v9_0_1_rc1.getMajorVersion());
    assertEquals(0, v9_0_1_rc1.getMinorVersion());
    assertEquals(1, v9_0_1_rc1.getPatchVersion());
    assertEquals("rc1.0", v9_0_1_rc1.getPrereleaseVersion());
  }

  public void testLatestInitialized() {
    assertTrue(SolrVersion.LATEST.greaterThanOrEqualTo(SolrVersion.valueOf("9.0.0")));
  }

  public void testForwardsCompatibility() {
    assertTrue(
        SolrVersion.valueOf("9.10.20").greaterThanOrEqualTo(SolrVersion.forIntegers(9, 0, 0)));
  }

  public void testParseExceptions() {
    expectThrows(SemverException.class, () -> SolrVersion.valueOf("SOLR_7_0_0"));
  }

  public void testSatisfies() {
    assertTrue(SOLR_9_0_1.satisfies("~9.0"));
    assertTrue(SOLR_9_0_1.satisfies("9.x"));
    assertTrue(SOLR_9_0_1.satisfies("9"));
    assertTrue(SOLR_9_0_1.satisfies("<=9"));
    assertTrue(SOLR_9_0_1.satisfies("<9.1"));
    assertFalse(SOLR_9_0_1.satisfies(">9.0"));
    assertFalse(SOLR_9_0_1.satisfies("8.x"));
    assertTrue(SOLR_9_0_1.satisfies("8 - 9"));
  }
}

@@ -826,16 +826,41 @@
 .util;%0A%0A
+import java.util.Locale;%0A
 import o
@@ -888,16 +888,85 @@
 stCase;%0A
+import org.apache.solr.SolrTestCaseJ4;%0Aimport org.junit.BeforeClass;%0A
 import o
@@ -1126,16 +1126,442 @@
 0.1%22);%0A%0A
+  @SuppressWarnings(%22AssertionFailureIgnored%22)%0A  @BeforeClass%0A  public static void beforeClass() %7B%0A    // Checks that semver4j works with configured locale */%0A    try %7B%0A      assertTrue(SOLR_9_0_1.satisfies(%22~9.0%22));%0A    %7D catch (AssertionError e) %7B%0A      SolrTestCaseJ4.assumeNoException(%0A          %22See SOLR-16467 - semver4j doesn't work with %22 + Locale.getDefault().toLanguageTag(),%0A          new Exception(e));%0A    %7D%0A  %7D%0A%0A
   public

Add check for working locale in TestSolrVersion (#1083)