<commit_before>#!/bin/bash

export SED_OPTIONS=-i
export FILES_PATTERN=*Test.java
# export FILES_PATTERN=Test.java
# echo "SED_OPTIONS = $SED_OPTIONS"

echo ''
echo "Converting JUnit assertions to AssertJ assertions on files matching pattern : $FILES_PATTERN"
echo ''
echo ' 1 - Replacing : assertEquals(0, myList.size()) ................. by : assertThat(myList).isEmpty()'
find . -name "$FILES_PATTERN" -exec sed $SED_OPTIONS 's/assertEquals(\(\".*\"\),[[:blank:]]*0,[[:blank:]]*\(.*\).size())/assertThat(\2).as(\1).isEmpty()/g' '{}' \;
find . -name "$FILES_PATTERN" -exec sed $SED_OPTIONS 's/assertEquals([[:blank:]]*0,[[:blank:]]*\(.*\).size())/assertThat(\1).isEmpty()/g' '{}' \;

echo ' 2 - Replacing : assertEquals(expectedSize, myList.size()) ...... by : assertThat(myList).hasSize(expectedSize)'
find . -name "$FILES_PATTERN" -exec sed $SED_OPTIONS 's/assertEquals(\(\".*\"\),[[:blank:]]*\([[:digit:]]*\),[[:blank:]]*\(.*\).size())/assertThat(\3).as(\1).hasSize(\2)/g' '{}' \;
find . -name "$FILES_PATTERN" -exec sed $SED_OPTIONS 's/assertEquals([[:blank:]]*\([[:digit:]]*\),[[:blank:]]*\(.*\).size())/assertThat(\2).hasSize(\1)/g' '{}' \;

echo ' 3 - Replacing : assertEquals(expectedDouble, actual, delta) .... by : assertThat(actual).isEqualTo(expectedDouble, offset(delta))'
find . -name "$FILES_PATTERN" -exec sed $SED_OPTIONS 's/assertEquals(\(\".*\"\),[[:blank:]]*\(.*\),[[:blank:]]*\(.*\),[[:blank:]]*\(.*\))/assertThat(\3).as(\1).isEqualTo(\2, offset(\4))/g' '{}' \;
# must be done before assertEquals("description", expected, actual) -> assertThat(actual).as("description").isEqualTo(expected) 
# will only replace triplet without double quote to avoid matching : assertEquals("description", expected, actual)
find . -name "$FILES_PATTERN" -exec sed $SED_OPTIONS 's/assertEquals([[:blank:]]*\([^"]*\),[[:blank:]]*\([^"]*\),[[:blank:]]*\([^"]*\))/assertThat(\2).isEqualTo(\1, offset(\3))/g' '{}' \;

echo ' 4 - Replacing : assertEquals(expected, actual) ................. by : assertThat(actual).isEqualTo(expected)'
find . -name "$FILES_PATTERN" -exec sed $SED_OPTIONS 's/assertEquals(\(\".*\"\),[[:blank:]]*\(.*\),[[:blank:]]*\([^,]*\))/assertThat(\3).as(\1).isEqualTo(\2)/g' '{}' \;
find . -name "$FILES_PATTERN" -exec sed $SED_OPTIONS 's/assertEquals([[:blank:]]*\(.*\),[[:blank:]]*\([^,]*\))/assertThat(\2).isEqualTo(\1)/g' '{}' \;

echo ' 5 - Replacing : assertArrayEquals(expectedArray, actual) ....... by : assertThat(actual).isEqualTo(expectedArray)'
find . -name "$FILES_PATTERN" -exec sed $SED_OPTIONS 's/assertArrayEquals(\(\".*\"\),[[:blank:]]*\(.*\),[[:blank:]]*\(.*\))/assertThat(\3).as(\1).isEqualTo(\2)/g' '{}' \;
find . -name "$FILES_PATTERN" -exec sed $SED_OPTIONS 's/assertArrayEquals([[:blank:]]*\(.*\),[[:blank:]]*\(.*\))/assertThat(\2).isEqualTo(\1)/g' '{}' \;

echo ' 6 - Replacing : assertNull(actual) ............................. by : assertThat(actual).isNull()'
find . -name "$FILES_PATTERN" -exec sed $SED_OPTIONS 's/assertNull(\(\".*\"\),[[:blank:]]*\(.*\))/assertThat(\2).as(\1).isNull()/g' '{}' \;<commit_msg>Minor simplifcation on script to convert JUnit assertions to AssertJ assertions<commit_after>#!/bin/bash

export SED_OPTIONS=-i
export FILES_PATTERN=*Test.java
# export FILES_PATTERN=Test.java
# echo "SED_OPTIONS = $SED_OPTIONS"

echo ''
echo "Converting JUnit assertions to AssertJ assertions on files matching pattern : $FILES_PATTERN"
echo ''
echo ' 1 - Replacing : assertEquals(0, myList.size()) ................. by : assertThat(myList).isEmpty()'
find . -name "$FILES_PATTERN" -exec sed $SED_OPTIONS 's/assertEquals(\(\".*\"\),[[:blank:]]*0,[[:blank:]]*\(.*\).size())/assertThat(\2).as(\1).isEmpty()/g' '{}' \;
find . -name "$FILES_PATTERN" -exec sed $SED_OPTIONS 's/assertEquals([[:blank:]]*0,[[:blank:]]*\(.*\).size())/assertThat(\1).isEmpty()/g' '{}' \;

echo ' 2 - Replacing : assertEquals(expectedSize, myList.size()) ...... by : assertThat(myList).hasSize(expectedSize)'
find . -name "$FILES_PATTERN" -exec sed $SED_OPTIONS 's/assertEquals(\(\".*\"\),[[:blank:]]*\([[:digit:]]*\),[[:blank:]]*\(.*\).size())/assertThat(\3).as(\1).hasSize(\2)/g' '{}' \;
find . -name "$FILES_PATTERN" -exec sed $SED_OPTIONS 's/assertEquals([[:blank:]]*\([[:digit:]]*\),[[:blank:]]*\(.*\).size())/assertThat(\2).hasSize(\1)/g' '{}' \;

echo ' 3 - Replacing : assertEquals(expectedDouble, actual, delta) .... by : assertThat(actual).isEqualTo(expectedDouble, offset(delta))'
find . -name "$FILES_PATTERN" -exec sed $SED_OPTIONS 's/assertEquals(\(\".*\"\),[[:blank:]]*\(.*\),[[:blank:]]*\(.*\),[[:blank:]]*\(.*\))/assertThat(\3).as(\1).isEqualTo(\2, offset(\4))/g' '{}' \;
# must be done before assertEquals("description", expected, actual) -> assertThat(actual).as("description").isEqualTo(expected) 
# will only replace triplet without double quote to avoid matching : assertEquals("description", expected, actual)
find . -name "$FILES_PATTERN" -exec sed $SED_OPTIONS 's/assertEquals([[:blank:]]*\([^"]*\),[[:blank:]]*\([^"]*\),[[:blank:]]*\([^"]*\))/assertThat(\2).isEqualTo(\1, offset(\3))/g' '{}' \;

echo ' 4 - Replacing : assertEquals(expected, actual) ................. by : assertThat(actual).isEqualTo(expected)'
find . -name "$FILES_PATTERN" -exec sed $SED_OPTIONS 's/assertEquals(\(\".*\"\),[[:blank:]]*\(.*\),[[:blank:]]*\(.*\))/assertThat(\3).as(\1).isEqualTo(\2)/g' '{}' \;
find . -name "$FILES_PATTERN" -exec sed $SED_OPTIONS 's/assertEquals([[:blank:]]*\(.*\),[[:blank:]]*\(.*\))/assertThat(\2).isEqualTo(\1)/g' '{}' \;

echo ' 5 - Replacing : assertArrayEquals(expectedArray, actual) ....... by : assertThat(actual).isEqualTo(expectedArray)'
find . -name "$FILES_PATTERN" -exec sed $SED_OPTIONS 's/assertArrayEquals(\(\".*\"\),[[:blank:]]*\(.*\),[[:blank:]]*\(.*\))/assertThat(\3).as(\1).isEqualTo(\2)/g' '{}' \;
find . -name "$FILES_PATTERN" -exec sed $SED_OPTIONS 's/assertArrayEquals([[:blank:]]*\(.*\),[[:blank:]]*\(.*\))/assertThat(\2).isEqualTo(\1)/g' '{}' \;

echo ' 6 - Replacing : assertNull(actual) ............................. by : assertThat(actual).isNull()'
find . -name "$FILES_PATTERN" -exec sed $SED_OPTIONS 's/assertNull(\(\".*\"\),[[:blank:]]*\(.*\))/assertThat(\2).as(\1).isNull()/g' '{}' \;
{'fraction_non_alphanumeric': 0.30647249190938514, 'fraction_numerical': 0.011650485436893204, 'mean_word_length': 4.455428067078553, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5523515', 'n_tokens_mistral': 2287, 'n_tokens_neox': 2225, 'n_words': 344}