SolrSailDeprecationTest.java

/*******************************************************************************
 * Copyright (c) 2025 Eclipse RDF4J contributors.
 *
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Distribution License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/org/documents/edl-v10.php.
 *
 * SPDX-License-Identifier: BSD-3-Clause
 *******************************************************************************/
// Some portions generated by Codex
package org.eclipse.rdf4j.sail.solr;

import static org.junit.jupiter.api.Assertions.assertTrue;

import java.lang.reflect.Modifier;
import java.util.List;
import java.util.stream.Collectors;

import org.eclipse.rdf4j.sail.solr.config.SolrSailConfig;
import org.eclipse.rdf4j.sail.solr.config.SolrSailFactory;
import org.junit.jupiter.api.Test;

class SolrSailDeprecationTest {

	private static final List<Class<?>> SOLR_CLASSES = List.of(
			SolrBulkUpdater.class, SolrClientFactory.class, SolrDocumentDistance.class, SolrDocumentResult.class,
			SolrDocumentScore.class, SolrIndex.class, SolrSearchDocument.class, SolrSearchQuery.class, SolrUtil.class,
			SolrSailConfig.class, SolrSailFactory.class,
			org.eclipse.rdf4j.sail.solr.client.cloud.Factory.class,
			org.eclipse.rdf4j.sail.solr.client.http.Factory.class,
			org.eclipse.rdf4j.sail.solr.client.embedded.Factory.class);

	@Test
	void allSolrClassesAreDeprecatedForRemovalOrNonPublic() {
		List<String> violations = SOLR_CLASSES.stream()
				.filter(SolrSailDeprecationTest::isPublicAndNotDeprecatedForRemoval)
				.map(Class::getName)
				.collect(Collectors.toList());

		assertTrue(violations.isEmpty(),
				"Expected all Solr classes to be deprecated for removal or non-public, but found: " + violations);
	}

	private static boolean isPublicAndNotDeprecatedForRemoval(Class<?> clazz) {
		int modifiers = clazz.getModifiers();
		if (!Modifier.isPublic(modifiers)) {
			return false;
		}

		Deprecated deprecated = clazz.getAnnotation(Deprecated.class);
		return deprecated == null || !deprecated.forRemoval();
	}
}