Skip to content

Invalid StackOverflowError is detected in Spring controller test #2147

@alisevych

Description

@alisevych

Description

StackOverflowError is shown on Problems view for NamedEntity when generating tests for VisitController

To Reproduce

  1. Run the 'spring-petclinic' project in IntelliJ Idea 2023.1
  2. Use plugin to generate tests with following settings (other can be default):
  • Spring: No configuration
  • Mock everything outside the class
  • Do not mock static methods
  1. Wait Problems view is opened
  2. Select error for NamedEntity
  3. Click "View generated test"
  4. Run it

Expected behavior

No tests for NamedEntity are expected. Neither errors on Problems view.
Tests shown on Problems view should fail with expected exception.

Actual behavior

The test doesn't throw exception.

Visual proofs (screenshots, logs, images)

image

The following test method in VisitControllerTest s addressed

	///region OTHER: ERROR SUITE for method loadPetWithVisit(int, int, java.util.Map)

	@Test(expected = StackOverflowError.class)
	public void testLoadPetWithVisit1() {
		(when(ownerMock.getPet(any(Integer.class)))).thenReturn(petMock);
		(when(ownerRepositoryMock.findById(any()))).thenReturn(ownerMock);
		LinkedHashMap model = new LinkedHashMap();

		visitController.loadPetWithVisit(0, 0, model);
	}
	///endregion

image

Environment

Windows 10 Pro
IntelliJ IDEA 2023.1 Ultimate

Metadata

Metadata

Assignees

Labels

comp-sarifIssue is related to SARIF report or Problems tabcomp-springIssue is related to Spring projects supportctg-bugIssue is a bug

Type

No type

Projects

Status

Done

Relationships

None yet

Development

No branches or pull requests

Issue actions