Closed
Description
Description
Failing assertions in Guava tests generated by Contest Estimator.
To Reproduce
- Run the 'utbot' project in IntelliJ Idea 2022.2.4
- Open
utbot-junit-contest/src/main/kotlin/org/utbot/contest/ContestEstimator.kt
- Change
javaHome
property to full local path to JDK 8 - In
fun main
change:projectFilter = listOf("guava-26.0")
- Run
fun main
- make sure to set JRE in Edit Configurations to JDK 8. - Wait tests are generated in
utbot-junit-contest/build/output/test/guava-26.0
- Check
CaseFormatTest.java
Expected behavior
Assertions in tests should be valid.
Actual behavior
- See StringConverterTest. There is the following test which assertFalse failsю
- 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);
}
- 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
Metadata
Metadata
Assignees
Type
Projects
Status
Done