Skip to content

UnusedMethod not recognize Junit MethodSource #5289

Description

@Pankraz76

need to avoid MethodSource

/Users/vincent.potucek/IdeaProjects/spotless/lib-extra/src/test/java/com/diffplug/spotless/extra/java/EclipseJdtFormatterStepTest.java:46: error: [UnusedMethod] Method 'formatWithVersion' is never used.
        private static Stream<String> formatWithVersion() {
                                      ^
    (see https://errorprone.info/bugpattern/UnusedMethod)
  Did you mean to remove this line?
/*
 * Copyright 2016-2024 DiffPlug
 *
 * 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 com.diffplug.spotless.extra.java;

import java.util.stream.Stream;

import org.junit.jupiter.api.Nested;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.MethodSource;

import com.diffplug.spotless.TestProvisioner;
import com.diffplug.spotless.extra.EquoBasedStepBuilder;
import com.diffplug.spotless.extra.eclipse.EquoResourceHarness;

class EclipseJdtFormatterStepTest extends EquoResourceHarness {
	private static EquoBasedStepBuilder createBuilder() {
		return EclipseJdtFormatterStep.createBuilder(TestProvisioner.mavenCentral());
	}

	public EclipseJdtFormatterStepTest() {
		super(createBuilder());
	}

	@ParameterizedTest
	@MethodSource
	void formatWithVersion(String version) throws Exception {
		harnessFor(version).test("test.java",
				"package p; class C{}",
				"package p;\nclass C {\n}");
	}

	private static Stream<String> formatWithVersion() {
		return Stream.of("4.9", EclipseJdtFormatterStep.defaultVersion());
	}

	/** New format interface requires source file information to distinguish module-info from compilation unit */
	@Nested
	class NewFormatInterface extends EquoResourceHarness {
		public NewFormatInterface() {
			super(createBuilder());
		}

		@Test
		void formatModuleInfo() throws Exception {
			harnessFor("4.11", createTestFile("java/eclipse/ModuleInfo.prefs"))
					.testResource("module-info.java", "java/eclipse/ModuleInfoUnformatted.test", "java/eclipse/ModuleInfoFormatted.test");
		}
	}
}

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions