Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
alisevych opened this issue Oct 3, 2023 · 0 comments · Fixed by #2641
Closed

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

alisevych opened this issue Oct 3, 2023 · 0 comments · Fixed by #2641
Assignees
Labels
comp-codegen Issue is related to code generator comp-spring Issue is related to Spring projects support ctg-bug Issue is a bug

Comments

@alisevych
Copy link
Member

alisevych commented Oct 3, 2023

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

@alisevych alisevych added ctg-bug Issue is a bug comp-codegen Issue is related to code generator comp-spring Issue is related to Spring projects support labels Oct 3, 2023
@alisevych alisevych added this to the October Release milestone Oct 3, 2023
@alisevych alisevych changed the title Incorrect assertNull is applied to a mocked method Incorrect assertNull is applied to the value returned from a mocked method Oct 3, 2023
@EgorkaKulikov EgorkaKulikov linked a pull request Oct 3, 2023 that will close this issue
6 tasks
@github-project-automation github-project-automation bot moved this from Todo to Done in UTBot Java Oct 4, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
comp-codegen Issue is related to code generator comp-spring Issue is related to Spring projects support ctg-bug Issue is a bug
Projects
Archived in project
Development

Successfully merging a pull request may close this issue.

2 participants