Skip to content

@TempDir field in super class skipped when it has same name as a @TempDir field in subclass #3532

Closed

Description

Overview

After fixing #3498, I realized that the same types of bugs exist for finding fields in a type hierarchy.

The fix for fields should be analogous to the fix for methods: apply field predicate before searching type hierarchy.

Example

SuperclassTempDirTests passes, but SubclassTempDirTests fails unless you rename one of the @TempDir fields to something other than tempDir.

package demo.a;

import static org.assertj.core.api.Assertions.assertThat;

import java.nio.file.Path;

import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.io.TempDir;

public class SuperclassTempDirTests {

	@TempDir
	static Path tempDir;

	protected static Path getStaticTempDir() {
		return tempDir;
	}

	@Test
	void superTest() {
		assertThat(getStaticTempDir()).exists();
	}

}
package demo.b;

import static org.assertj.core.api.Assertions.assertThat;

import java.nio.file.Path;

import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.io.TempDir;

import demo.a.SuperclassTempDirTests;

class SubclassTempDirTests extends SuperclassTempDirTests {

	@TempDir
	Path tempDir;

	Path getInstanceTempDir() {
		return this.tempDir;
	}

	@Test
	void subTest() {
		assertThat(getInstanceTempDir()).exists();
		assertThat(getStaticTempDir()).exists();
	}

}

Related Issues

Deliverables

  • Apply field predicate before searching type hierarchy.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions