Skip to content

Commit

Permalink
Add tests related to AssertThrows
Browse files Browse the repository at this point in the history
  • Loading branch information
tsantalis committed Jan 17, 2025
1 parent 2df6c3e commit 94e8afb
Show file tree
Hide file tree
Showing 1,201 changed files with 150,679 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
package org.refactoringminer.test;

import gr.uom.java.xmi.decomposition.AbstractCodeMapping;
import gr.uom.java.xmi.decomposition.LeafExpression;
import gr.uom.java.xmi.diff.AssertThrowsRefactoring;
import org.apache.commons.io.IOUtils;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.CsvSource;
import org.refactoringminer.api.Refactoring;
import org.refactoringminer.api.RefactoringHandler;
import org.refactoringminer.rm1.GitHistoryRefactoringMinerImpl;

import java.io.File;
import java.io.FileReader;
import java.util.ArrayList;
import java.util.List;
import java.util.Set;
import java.util.function.Consumer;
import java.util.function.Supplier;
import java.util.stream.Collectors;

import static org.refactoringminer.utils.Assertions.assertHasSameElementsAs;

public class TestRelatedStatementMappingsTest {
public static final String REPOS = System.getProperty("user.dir") + "/src/test/resources/oracle/commits";
private static final String EXPECTED_PATH = System.getProperty("user.dir") + "/src/test/resources/mappings/";
private GitHistoryRefactoringMinerImpl miner;
private List<String> actual;
private List<String> expected;


@ParameterizedTest
@CsvSource({
//Migrate Expected Exception
"https://github.com/apache/camel.git, c30deabcaed4726bce4371d76257db63f2eba87c, camel-c30deabcaed4726bce4371d76257db63f2eba87c.txt",
"https://github.com/apache/commons-csv.git, e2f0a4d8a83a41eaa984086636a3712c682307ea, commons-csv-e2f0a4d8a83a41eaa984086636a3712c682307ea.txt",
"https://github.com/apache/jmeter.git, d5b5b2f38c3341cbb934693c17d0574a241ad4f9, jmeter-d5b5b2f38c3341cbb934693c17d0574a241ad4f9.txt",
"https://github.com/apache/plc4x.git, 4312eb178b6cb000ea8a3c78df70567182341331, plc4x-4312eb178b6cb000ea8a3c78df70567182341331.txt",
"https://github.com/eclipse/eclipse-collections.git, f26addbce8e843f208805aa22f45dcfb6f8177f7, eclipse-collections-f26addbce8e843f208805aa22f45dcfb6f8177f7.txt",
"https://github.com/EnMasseProject/enmasse.git, 5e0e683531b756ac62a497cca15ddb7211a34e24, enmasse-5e0e683531b756ac62a497cca15ddb7211a34e24.txt",
"https://github.com/apache/clerezza.git, d77dbe2085ffa89b2a933637c5432d113b7432b8, clerezza-d77dbe2085ffa89b2a933637c5432d113b7432b8.txt",
"https://github.com/iluwatar/java-design-patterns.git, 6694d742a370e0f181530734481284de8d5dd8ef, java-design-patterns-6694d742a370e0f181530734481284de8d5dd8ef.txt",
"https://github.com/LMAX-Exchange/disruptor.git, 340f23ef88a32ceb8341820c15bfd9537303219c, disruptor-340f23ef88a32ceb8341820c15bfd9537303219c.txt",
"https://github.com/neo4j/neo4j.git, b44c62bcdd6f7218bc97dae183ea0f6587bacd29, neo4j-b44c62bcdd6f7218bc97dae183ea0f6587bacd29.txt",
"https://github.com/RohanNagar/thunder.git, 48776d511a0152f7b9cbe4460c8967bdd5ec3dc4, thunder-48776d511a0152f7b9cbe4460c8967bdd5ec3dc4.txt",
"https://github.com/SAP/olingo-jpa-processor-v4.git, 5e77141293d32b015a92e48d099195840f2b2e87, olingo-jpa-processor-v4-5e77141293d32b015a92e48d099195840f2b2e87.txt",
"https://github.com/zalando/problem.git, 1b987b88ecb5cc2c8df58ac8eda188fb2d6f5998, problem-1b987b88ecb5cc2c8df58ac8eda188fb2d6f5998.txt",
//"https://github.com/apache/plc4x.git, 86da20c173ad291e5f3d5fe4c56f37d7f3c2c538, plc4x-86da20c173ad291e5f3d5fe4c56f37d7f3c2c538.txt", // FIXME: JUnit 5 to AssertJ expected exception not supported
//"https://github.com/assertj/assertj-swing.git, 033bdd7832ca9a9647c8f7b7ecaa985d3115b206, assertj-swing-033bdd7832ca9a9647c8f7b7ecaa985d3115b206.txt", // FIXME: TestNG to JUnit 4 expected exception not supported
//"https://github.com/alexruiz/fest-swing-1.x.git, 033bdd7832ca9a9647c8f7b7ecaa985d3115b206, fest-swing-1.x-033bdd7832ca9a9647c8f7b7ecaa985d3115b206.txt", // FIXME: TestNG to JUnit 4 expected exception not supported
//"https://github.com/apache/flink.git, 2c5bc580e6c10fb3a2724a945847b5cc6b28df27, flink-2c5bc580e6c10fb3a2724a945847b5cc6b28df27.txt", // FIXME: JUnit 4 to AssertJ expected exception not supported
//"https://github.com/apache/flink.git, 95c3499ea80d07c448c297e36fa5a1b5b4caea2b, flink-95c3499ea80d07c448c297e36fa5a1b5b4caea2b.txt", // FIXME: JUnit 4 to AssertJ expected exception not supported
//"https://github.com/apache/cassandra-java-driver.git, 7d962af9291f69f0da6115375efd5bd5224a2353, cassandra-java-driver-7d962af9291f69f0da6115375efd5bd5224a2353.txt", // FIXME: TestNG to JUnit 4 expected exception not supported
//"https://github.com/OpenGamma/Strata.git, e007f826c49075500def8638de8367960c054c19, Strata-e007f826c49075500def8638de8367960c054c19.txt", // FIXME: TestNG to AssertJ expected exception not supported
//"https://github.com/rapidoid/rapidoid.git, 8596c1d82e9f0a36f40cd7ec393c6829e697836d, rapidoid-8596c1d82e9f0a36f40cd7ec393c6829e697836d.txt", // FIXME: TestNG to JUnit 4 expected exception not supported
//"https://github.com/zanata/zanata-platform.git, 0297e0513ac1f487f1570b1cc38979a73ac97da8, zanata-platform-0297e0513ac1f487f1570b1cc38979a73ac97da8.txt", // FIXME: TestNG to JUnit 4 expected exception not supported
})
public void testAssertThrowsMappings(String url, String commit, String testResultFileName) throws Exception {
testRefactoringMappings(url, commit, testResultFileName, ref -> {
if (ref instanceof AssertThrowsRefactoring) {
AssertThrowsRefactoring assertThrowsRefactoring = (AssertThrowsRefactoring) ref;
Set<AbstractCodeMapping> mapper = assertThrowsRefactoring.getAssertThrowsMappings();
mapperInfo(mapper, assertThrowsRefactoring.getOperationBefore(), assertThrowsRefactoring.getOperationAfter());
}
});
}

@BeforeEach
void setUp() {
miner = new GitHistoryRefactoringMinerImpl();
actual = new ArrayList<>();
expected = new ArrayList<>();
}

private void testRefactoringMappings(String url, String commit, String testResultFileName, final Consumer<Refactoring> consumer) {
miner.detectAtCommitWithGitHubAPI(url, commit, new File(REPOS), new RefactoringHandler() {
@Override
public void handle(String commitId, List<Refactoring> refactorings) {
for (Refactoring ref : refactorings) {
consumer.accept(ref);
}
}
});
Supplier<String> lazyErrorMessage = () -> actual.stream().collect(Collectors.joining(System.lineSeparator()));
Assertions.assertDoesNotThrow(() -> {
expected.addAll(IOUtils.readLines(new FileReader(EXPECTED_PATH + testResultFileName)));
}, lazyErrorMessage);
assertHasSameElementsAs(expected, actual, lazyErrorMessage);
}

private <T> void mapperInfo(Set<AbstractCodeMapping> mappings, T operationBefore, T operationAfter) {
actual.add(operationBefore + " -> " + operationAfter);
for(AbstractCodeMapping mapping : mappings) {
if(mapping.getFragment1() instanceof LeafExpression && mapping.getFragment2() instanceof LeafExpression)
continue;
String line = mapping.getFragment1().getLocationInfo() + "==" + mapping.getFragment2().getLocationInfo();
actual.add(line);
}
}
}
30 changes: 30 additions & 0 deletions src/test/java/org/refactoringminer/utils/Assertions.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package org.refactoringminer.utils;

import java.util.LinkedHashSet;
import java.util.List;
import java.util.function.Supplier;
import java.util.stream.Collectors;

public class Assertions {
public static void assertHasSameElementsAs(List<String> expected, List<String> actual, Supplier<String> lazyErrorMessage) {
var expectedSet = new LinkedHashSet<>(expected);
var actualSet = new LinkedHashSet<>(actual);
org.junit.jupiter.api.Assertions.assertAll(
() -> org.junit.jupiter.api.Assertions.assertEquals(expected.size(), actual.size(), () ->
"Expected size (" + expected.size() + ") != actual size (" + actual.size() + "):"
+ System.lineSeparator() + lazyErrorMessage.get() + System.lineSeparator()),
() -> org.junit.jupiter.api.Assertions.assertTrue(actualSet.containsAll(expectedSet), () -> System.lineSeparator() + expectedSet.stream()
.filter((String s) -> !actualSet.contains(s))
.map((String s) -> "+" + s)
.map((String s) -> s + System.lineSeparator())
.collect(Collectors.joining())),
() -> org.junit.jupiter.api.Assertions.assertTrue(expectedSet.containsAll(actualSet), () -> System.lineSeparator() + actualSet.stream()
.filter((String s) -> !expectedSet.contains(s))
.map((String s) -> "-" + s)
.map((String s) -> s + System.lineSeparator())
.collect(Collectors.joining())));
}
public static void assertHasSameElementsAs(List<String> expected, List<String> actual) {
assertHasSameElementsAs(expected, actual, () -> "");
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
public testBodyOgnlExpression() : void -> public testBodyOgnlExpression() : void
line range:187-187==line range:187-187
public testBodyOgnlExpression() : void -> public testBodyOgnlExpression() : void
line range:195-195==line range:190-190
public httpDisableStreamCache() : void -> public httpDisableStreamCache() : void
line range:79-79==line range:78-78
public testTransferExeption() : void -> public testTransferException() : void
line range:62-62==line range:62-62
public testBadConfiguration() : void -> public testBadConfiguration() : void
line range:110-110==line range:113-113
public testNoResponseDisconnectOnNoReplyFalse() : void -> public testNoResponseDisconnectOnNoReplyFalse() : void
line range:45-45==line range:45-45
public testNoResponse() : void -> public testNoResponse() : void
line range:50-50==line range:51-51
public testBadConfiguration() : void -> public testBadConfiguration() : void
line range:81-81==line range:82-82
public testWriteByteArraySliceWithNegativeLength() : void -> public testWriteByteArraySliceWithNegativeLength() : void
line range:258-258==line range:258-258
public testWriteByteArraySliceWithLengthGreaterThanAvailable() : void -> public testWriteByteArraySliceWithLengthGreaterThanAvailable() : void
line range:275-275==line range:273-273
public testWriteByteArraySliceWithLengthGreaterThanAvailable() : void -> public testWriteByteArraySliceWithLengthGreaterThanAvailable() : void
line range:283-283==line range:280-280
public testWriteByteArraySliceWithLengthGreaterThanAvailable() : void -> public testWriteByteArraySliceWithLengthGreaterThanAvailable() : void
line range:292-292==line range:287-287
public testKeepingTimeoutHeader() : void -> public testKeepingTimeoutHeader() : void
line range:60-60==line range:61-61
public testFail() : void -> public testFail() : void
line range:41-48==line range:51-51
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
public unavailableConvertor() : void -> public unavailableConvertor() : void
line range:42-42==line range:49-49
public testAcessGraph() : void -> public testAcessGraph() : void
line range:115-115==line range:127-127
public testNoWildCard() : void -> public testNoWildCard() : void
line range:120-120==line range:133-133
public testAllowedArea() : void -> public testAllowedArea() : void
line range:125-125==line range:139-139
public testAcessForbiddenGraph() : void -> public testAcessForbiddenGraph() : void
line range:130-130==line range:145-145
public testCustomPermissions() : void -> public testCustomPermissions() : void
line range:141-141==line range:158-158
public testCustomPermissionsIncorrect() : void -> public testCustomPermissionsIncorrect() : void
line range:152-152==line range:171-171
public testCreateMGraph() : void -> public testCreateMGraph() : void
line range:168-168==line range:189-189
public testCreateMGraphWithoutWritePermission() : void -> public testCreateMGraphWithoutWritePermission() : void
line range:172-172==line range:195-195
public testAddTripleToMGraph() : void -> public testAddTripleToMGraph() : void
line range:178-178==line range:202-202
public executeSparqlQueryNoEngineWithString() : void -> public executeSparqlQueryNoEngineWithString() : void
line range:145-145==line range:153-153
public executeSparqlQueryNoEngineWithQuery() : void -> public executeSparqlQueryNoEngineWithQuery() : void
line range:154-154==line range:163-163
public executeSparqlQueryNoEngineWithSelectQuery() : void -> public executeSparqlQueryNoEngineWithSelectQuery() : void
line range:163-163==line range:173-173
public executeSparqlQueryNoEngineWithAskQuery() : void -> public executeSparqlQueryNoEngineWithAskQuery() : void
line range:172-172==line range:183-183
public executeSparqlQueryNoEngineWithDescribeQuery() : void -> public executeSparqlQueryNoEngineWithDescribeQuery() : void
line range:181-182==line range:193-193
public executeSparqlQueryNoEngineWithConstructQuery() : void -> public executeSparqlQueryNoEngineWithConstructQuery() : void
line range:191-192==line range:203-203
public testInvalidQuery() : void -> public testInvalidQuery() : void
line range:98-98==line range:107-107
public removeIncompleteSubGraph() : void -> public removeIncompleteSubGraph() : void
line range:85-85==line range:92-92
public removeInvalidSubGraph() : void -> public removeInvalidSubGraph() : void
line range:101-101==line range:109-109
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
public testNotNullNull() : void -> public testNotNullNull() : void
line range:33-33==line range:35-35
public testDelimiterSameAsCommentStartThrowsException() : void -> public testDelimiterSameAsCommentStartThrowsException() : void
line range:77-77==line range:78-78
public testDelimiterSameAsEscapeThrowsException() : void -> public testDelimiterSameAsEscapeThrowsException() : void
line range:82-82==line range:83-83
public testDuplicateHeaderElementsFalse() : void -> public testDuplicateHeaderElementsFalse() : void
line range:95-95==line range:98-98
public testEscapeSameAsCommentStartThrowsException() : void -> public testEscapeSameAsCommentStartThrowsException() : void
line range:525-525==line range:528-528
public testEscapeSameAsCommentStartThrowsExceptionForWrapperType() : void -> public testEscapeSameAsCommentStartThrowsExceptionForWrapperType() : void
line range:531-531==line range:536-536
public testQuoteCharSameAsCommentStartThrowsException() : void -> public testQuoteCharSameAsCommentStartThrowsException() : void
line range:664-664==line range:669-669
public testQuoteCharSameAsCommentStartThrowsExceptionForWrapperType() : void -> public testQuoteCharSameAsCommentStartThrowsExceptionForWrapperType() : void
line range:670-670==line range:677-677
public testQuoteCharSameAsDelimiterThrowsException() : void -> public testQuoteCharSameAsDelimiterThrowsException() : void
line range:675-675==line range:682-682
public testQuotePolicyNoneWithoutEscapeThrowsException() : void -> public testQuotePolicyNoneWithoutEscapeThrowsException() : void
line range:680-680==line range:687-687
public testWithCommentStartCRThrowsException() : void -> public testWithCommentStartCRThrowsException() : void
line range:896-896==line range:903-903
public testWithDelimiterLFThrowsException() : void -> public testWithDelimiterLFThrowsException() : void
line range:907-907==line range:914-914
public testWithEscapeCRThrowsExceptions() : void -> public testWithEscapeCRThrowsExceptions() : void
line range:924-924==line range:931-931
public testWithQuoteLFThrowsException() : void -> public testWithQuoteLFThrowsException() : void
line range:1143-1143==line range:1150-1150
public testClose() : void -> public testClose() : void
line range:255-255==line range:255-255
public testDuplicateHeadersNotAllowed() : void -> public testDuplicateHeadersNotAllowed() : void
line range:297-298==line range:299-300
public testHeadersMissingException() : void -> public testHeadersMissingException() : void
line range:722-722==line range:724-724
public testInvalidFormat() : void -> public testInvalidFormat() : void
line range:749-749==line range:751-751
public testNewCSVParserNullReaderFormat() : void -> public testNewCSVParserNullReaderFormat() : void
line range:926-926==line range:925-925
public testNewCSVParserReaderNullFormat() : void -> public testNewCSVParserReaderNullFormat() : void
line range:933-933==line range:930-930
public testParseFileNullFormat() : void -> public testParseFileNullFormat() : void
line range:980-980==line range:977-977
public testParseNullFileFormat() : void -> public testParseNullFileFormat() : void
line range:987-987==line range:984-984
public testParseNullPathFormat() : void -> public testParseNullPathFormat() : void
line range:994-994==line range:991-991
public testParseNullStringFormat() : void -> public testParseNullStringFormat() : void
line range:1001-1001==line range:996-996
public testParseNullUrlCharsetFormat() : void -> public testParseNullUrlCharsetFormat() : void
line range:1008-1008==line range:1003-1003
public testParserUrlNullCharsetFormat() : void -> public testParserUrlNullCharsetFormat() : void
line range:1015-1015==line range:1010-1010
public testParseStringNullFormat() : void -> public testParseStringNullFormat() : void
line range:1022-1022==line range:1015-1015
public testParseUrlCharsetNullFormat() : void -> public testParseUrlCharsetNullFormat() : void
line range:1029-1029==line range:1022-1022
public testInvalidFormat() : void -> public testInvalidFormat() : void
line range:583-583==line range:583-583
public testNewCsvPrinterAppendableNullFormat() : void -> public testNewCsvPrinterAppendableNullFormat() : void
line range:884-884==line range:881-881
public testNewCsvPrinterNullAppendableFormat() : void -> public testNewCsvPrinterNullAppendableFormat() : void
line range:891-891==line range:886-886
public testGetStringInconsistentRecord() : void -> public testGetStringInconsistentRecord() : void
line range:79-79==line range:79-79
public testGetStringNoHeader() : void -> public testGetStringNoHeader() : void
line range:84-84==line range:84-84
public testGetUnmappedEnum() : void -> public testGetUnmappedEnum() : void
line range:89-89==line range:89-89
public testGetUnmappedName() : void -> public testGetUnmappedName() : void
line range:94-94==line range:94-94
public testGetUnmappedNegativeInt() : void -> public testGetUnmappedNegativeInt() : void
line range:99-99==line range:99-99
public testGetUnmappedPositiveInt() : void -> public testGetUnmappedPositiveInt() : void
line range:104-104==line range:104-104
public testEscapingAtEOF() : void -> public testEscapingAtEOF() : void
line range:388-388==line range:389-389
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
public shouldHandleFatalException() : void -> public shouldHandleFatalException() : void
line range:35-35==line range:34-34
public shouldTimeoutWaitFor() : void -> public shouldTimeoutWaitFor() : void
line range:27-27==line range:24-24
public shouldThrowExceptionIfBufferIsFull() : void -> public shouldThrowExceptionIfBufferIsFull() : void
line range:154-154==line range:144-144
public shouldInterruptDuringBusySpin() : void -> public shouldInterruptDuringBusySpin() : void
line range:112-112==line range:109-109
line range:107-122==line range:108-109
public shouldTryNext(sequencer Sequencer) : void -> public shouldTryNext(sequencer Sequencer) : void
line range:250-250==line range:247-247
public shouldTimeoutWaitFor() : void -> public shouldTimeoutWaitFor() : void
line range:28-28==line range:25-25
Loading

0 comments on commit 94e8afb

Please sign in to comment.