Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Incomplete expected is created for classes from Java standard library #2573

Open
Assignees
Labels
comp-codegenIssue is related to code generator comp-instrumented-processIssue is related to Instrumented process ctg-bugIssue is a bug
@IlyaMuravjov

Description

Description

No fields of expected are set, leading to equals overridden equals returning false or crashing and assertEquals(expected, actual) failing.

To Reproduce

Generate tests for the following class

public class JavaUtils {
 public static Date getEpochStart() {
 return Date.from(Instant.EPOCH);
 }
 public static File getSomeFile() {
 return new File("file.txt");
 }
 public static BigInteger getSomeBigInteger() {
 return BigInteger.ZERO;
 }
}

Expected behavior

One passing test per method.

Actual behavior

One failing (at runtime) test per method.

public final class JavaUtilsTest {
 ///region Test suites for executable org.example.JavaUtils.getEpochStart
 ///region SYMBOLIC EXECUTION: SUCCESSFUL EXECUTIONS for method getEpochStart()
 /**
 * @utbot.classUnderTest {@link JavaUtils}
 * @utbot.methodUnderTest {@link JavaUtils#getEpochStart()}
 * @utbot.invokes {@link Date#from(java.time.Instant)}
 */
 @Test
 @DisplayName("getEpochStart: -> DateFrom")
 public void testGetEpochStart_DateFrom() {
 Date actual = JavaUtils.getEpochStart();
 Date expected = new Date();
 // java.util.Date has overridden equals method
 assertEquals(expected, actual);
 }
 ///endregion
 ///endregion
 ///region Test suites for executable org.example.JavaUtils.getSomeBigInteger
 ///region SYMBOLIC EXECUTION: SUCCESSFUL EXECUTIONS for method getSomeBigInteger()
 /**
 * @utbot.classUnderTest {@link JavaUtils}
 * @utbot.methodUnderTest {@link JavaUtils#getSomeBigInteger()}
 * @utbot.returnsFrom {@code return BigInteger.ZERO;}
 */
 @Test
 @DisplayName("getSomeBigInteger: -> return BigInteger.ZERO")
 public void testGetSomeBigInteger_ReturnBigIntegerZERO() throws Exception {
 BigInteger actual = JavaUtils.getSomeBigInteger();
 BigInteger expected = ((BigInteger) createInstance("java.math.BigInteger"));
 // java.math.BigInteger has overridden equals method
 assertEquals(expected, actual);
 }
 ///endregion
 ///endregion
 ///region Test suites for executable org.example.JavaUtils.getSomeFile
 ///region OTHER: SUCCESSFUL EXECUTIONS for method getSomeFile()
 @Test
 public void testGetSomeFile1() throws Exception {
 File actual = JavaUtils.getSomeFile();
 File expected = ((File) createInstance("java.io.File"));
 // java.io.File has overridden equals method
 assertEquals(expected, actual);
 }
 ///endregion
 ///endregion
}

Errors:

org.opentest4j.AssertionFailedError: expected: <Thu Aug 31 15:45:57 MSK 2023> but was: <Thu Jan 01 03:00:00 MSK 1970>
	at org.junit.jupiter.api.AssertionFailureBuilder.build(AssertionFailureBuilder.java:151)
	at org.junit.jupiter.api.AssertionFailureBuilder.buildAndThrow(AssertionFailureBuilder.java:132)
	at org.junit.jupiter.api.AssertEquals.failNotEqual(AssertEquals.java:197)
	at org.junit.jupiter.api.AssertEquals.assertEquals(AssertEquals.java:182)
	at org.junit.jupiter.api.AssertEquals.assertEquals(AssertEquals.java:177)
	at org.junit.jupiter.api.Assertions.assertEquals(Assertions.java:1142)
	at org.example.JavaUtilsTest.testGetEpochStart_DateFrom(JavaUtilsTest.java:31)
java.lang.NullPointerException
	at java.base/java.io.WinNTFileSystem.compare(WinNTFileSystem.java:698)
	at java.base/java.io.File.compareTo(File.java:2198)
	at java.base/java.io.File.equals(File.java:2217)
	at org.junit.jupiter.api.AssertionUtils.objectsAreEqual(AssertionUtils.java:110)
	at org.junit.jupiter.api.AssertEquals.assertEquals(AssertEquals.java:181)
	at org.junit.jupiter.api.AssertEquals.assertEquals(AssertEquals.java:177)
	at org.junit.jupiter.api.Assertions.assertEquals(Assertions.java:1142)
	at org.example.JavaUtilsTest.testGetSomeFile1(JavaUtilsTest.java:71)
java.lang.NullPointerException
	at java.base/java.math.BigInteger.equals(BigInteger.java:3865)
	at org.junit.jupiter.api.AssertionUtils.objectsAreEqual(AssertionUtils.java:110)
	at org.junit.jupiter.api.AssertEquals.assertEquals(AssertEquals.java:181)
	at org.junit.jupiter.api.AssertEquals.assertEquals(AssertEquals.java:177)
	at org.junit.jupiter.api.Assertions.assertEquals(Assertions.java:1142)
	at org.example.JavaUtilsTest.testGetSomeBigInteger_ReturnBigIntegerZERO(JavaUtilsTest.java:54)

Metadata

Metadata

Labels

comp-codegenIssue is related to code generator comp-instrumented-processIssue is related to Instrumented process ctg-bugIssue is a bug

Type

No type

Projects

Status

Todo

Milestone

No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      AltStyle によって変換されたページ (->オリジナル) /