Skip to content

Failing Assertions in tests on guava-26.0 generated by Contest Estimator #1672

Closed
@alisevych

Description

@alisevych

Description

Failing assertions in Guava tests generated by Contest Estimator.

To Reproduce

  1. Run the 'utbot' project in IntelliJ Idea 2022.2.4
  2. Open utbot-junit-contest/src/main/kotlin/org/utbot/contest/ContestEstimator.kt
  3. Change javaHome property to full local path to JDK 8
  4. In fun main change: projectFilter = listOf("guava-26.0")
  5. Run fun main - make sure to set JRE in Edit Configurations to JDK 8.
  6. Wait tests are generated in utbot-junit-contest/build/output/test/guava-26.0
  7. Check CaseFormatTest.java

Expected behavior

Assertions in tests should be valid.

Actual behavior

  1. See StringConverterTest. There is the following test which assertFalse failsю
  2. Also there is duplication asserts.

Visual proofs (screenshots, logs, images)

        @Test
        public void testEquals3() throws Exception  {
            Object stringConverter = createInstance("com.google.common.base.CaseFormat$StringConverter");
            CaseFormat anonymousCaseFormat = ((CaseFormat) createInstance("com.google.common.base.CaseFormat$1"));
            setField(stringConverter, "com.google.common.base.CaseFormat$StringConverter", "sourceFormat", anonymousCaseFormat);
            Object stringConverter1 = createInstance("com.google.common.base.CaseFormat$StringConverter");
            setField(stringConverter1, "com.google.common.base.CaseFormat$StringConverter", "sourceFormat", null);
            
            CaseFormat initialStringConverterSourceFormat = ((CaseFormat) getFieldValue(stringConverter, "com.google.common.base.CaseFormat$StringConverter", "sourceFormat"));
            
            Class stringConverterClazz = Class.forName("com.google.common.base.CaseFormat$StringConverter");
            Class stringConverter1Type = Class.forName("java.lang.Object");
            Method equalsMethod = stringConverterClazz.getDeclaredMethod("equals", stringConverter1Type);
            equalsMethod.setAccessible(true);
            java.lang.Object[] equalsMethodArguments = new java.lang.Object[1];
            equalsMethodArguments[0] = stringConverter1;
            boolean actual = ((Boolean) equalsMethod.invoke(stringConverter, equalsMethodArguments));
            
            assertFalse(actual);
            
            CaseFormat finalStringConverterSourceFormat = ((CaseFormat) getFieldValue(stringConverter, "com.google.common.base.CaseFormat$StringConverter", "sourceFormat"));
            
            assertFalse(initialStringConverterSourceFormat == finalStringConverterSourceFormat);
        }
  1. Duplicating asserts:
        @Test
        public void testDoForward5() throws Exception  {
            Object stringConverter = createInstance("com.google.common.base.CaseFormat$StringConverter");
            CaseFormat anonymousCaseFormat = ((CaseFormat) createInstance("com.google.common.base.CaseFormat$1"));
            Object none = createInstance("com.google.common.base.CharMatcher$None");
            setField(anonymousCaseFormat, "com.google.common.base.CaseFormat", "wordBoundary", none);
            setField(stringConverter, "com.google.common.base.CaseFormat$StringConverter", "sourceFormat", anonymousCaseFormat);
            CaseFormat anonymousCaseFormat1 = ((CaseFormat) createInstance("com.google.common.base.CaseFormat$3"));
            setField(stringConverter, "com.google.common.base.CaseFormat$StringConverter", "targetFormat", anonymousCaseFormat1);
            String string = "";
            
            CaseFormat initialStringConverterSourceFormat = ((CaseFormat) getFieldValue(stringConverter, "com.google.common.base.CaseFormat$StringConverter", "sourceFormat"));
            CaseFormat initialStringConverterTargetFormat = ((CaseFormat) getFieldValue(stringConverter, "com.google.common.base.CaseFormat$StringConverter", "targetFormat"));
            
            Class stringConverterClazz = Class.forName("com.google.common.base.CaseFormat$StringConverter");
            Class stringType = Class.forName("java.lang.String");
            Method doForwardMethod = stringConverterClazz.getDeclaredMethod("doForward", stringType);
            doForwardMethod.setAccessible(true);
            java.lang.Object[] doForwardMethodArguments = new java.lang.Object[1];
            doForwardMethodArguments[0] = string;
            String actual = ((String) doForwardMethod.invoke(stringConverter, doForwardMethodArguments));
            
            assertEquals(string, actual);
            
            CaseFormat finalStringConverterSourceFormat = ((CaseFormat) getFieldValue(stringConverter, "com.google.common.base.CaseFormat$StringConverter", "sourceFormat"));
            CaseFormat finalStringConverterTargetFormat = ((CaseFormat) getFieldValue(stringConverter, "com.google.common.base.CaseFormat$StringConverter", "targetFormat"));
            
            assertFalse(initialStringConverterSourceFormat == finalStringConverterSourceFormat);
            
            assertFalse(initialStringConverterTargetFormat == finalStringConverterTargetFormat);
        }

Environment

Windows 10 Pro
IntelliJ IDEA 2022.2.4
ContestEstimator run
JDK 8

Additional context

image

Metadata

Metadata

Assignees

Labels

comp-codegenIssue is related to code generatorcomp-contest-estimatorIssue is related to contest estimatorctg-bugIssue is a bug

Type

No type

Projects

Status

Done

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions