openrewrite / rewrite-testing-frameworks

OpenRewrite recipes that perform common Java testing migration tasks.
Apache License 2.0
77 stars 72 forks source link

Edge case: junit5.StaticImports should respect existing `assertEquals` #459

Open koppor opened 10 months ago

koppor commented 10 months ago
    public static void assertEquals(List<Text> expected, List<Text> actual) {
        // Need to compare string values since Texts with the same string are not considered equal
        Assertions.assertEquals(expected.toString(), actual.toString());
        assertEquals(expected.toString(), actual.toString());

Assertions.assertEquals is rewritten to assertEquals (with a static import), which does not compile.

java: incompatible types: java.lang.String cannot be converted to java.util.List<javafx.scene.text.Text>

OK, this is an edge case. I will rename the method. Just want to bring it up if you are interested.

koppor commented 10 months ago

Maybe, I need it a little bit more for my test cases

    /**
     * Reads a bibtex database from the given InputStream. The list is compared with the given list.
     *
     * @param expectedInputStream the inputStream reading the entry from
     * @param actualEntries       a list containing a single entry to compare with
     */
    public static void assertEquals(InputStream expectedInputStream, List<BibEntry> actualEntries)
            throws IOException {
        assertNotNull(expectedInputStream);
        assertNotNull(actualEntries);
        // explicit reference of Assertions is needed here to disambiguate from the methods defined by this class
        List<BibEntry> expectedEntries = getListFromInputStream(expectedInputStream);
        Assertions.assertEquals(expectedEntries, actualEntries);
    }
koppor commented 10 months ago

Related issue https://github.com/openrewrite/rewrite-testing-frameworks/issues/258 - but not a duplicate, because the recipe is another one here.