Skip to content

Incorrect assertNull is applied to the value returned from a mocked method #2639

Closed
@alisevych

Description

@alisevych

Description

assertNull is applied to the method returned value, while it's method is mocked.
assertEquals to exact value is expected.

To Reproduce

  1. Install -IU- UnitTestBot plugin in IntelliJ IDEA
  2. Open spring-petclinic
  3. Set Fuzzing 100% mode
  4. Generate Unit tests for PetTypeFormatter with PetClinicApplication configuration
  5. Run the tests

Expected behavior

Method PetType$getName() is mocked with exact return value.
assertEquals for the actualName is expected.

Actual behavior

There is failing assertNull for actualName in successful test.

Screenshots, logs

	@Test
	@DisplayName("parse: text = 'XZ', locale = Locale(String, String, String)")
	public void testParseWithNonEmptyString() throws ParseException {
		ArrayList arrayList = new ArrayList();
		PetType petTypeMock = mock(PetType.class);
		(when(petTypeMock.getName())).thenReturn("XZ");
		arrayList.add(petTypeMock);
		(when(ownerRepositoryMock.findPetTypes())).thenReturn(arrayList);
		Locale locale = new Locale("\n\t\r", "#$\\\"'", "#$\\\"'");

		PetType actual = petTypeFormatter.parse("XZ", locale);

		String actualName = actual.getName();
		assertNull(actualName);

		Integer actualId = actual.getId();
		assertNull(actualId);
	}

image

Environment

IntelliJ IDEA version - Community 2023.2
Project - Maven
JDK - 17

Metadata

Metadata

Assignees

Labels

comp-codegenIssue is related to code generatorcomp-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