Skip to content

Commit 0b6e88b

Browse files
committed
More tests for #126.
1 parent fd7e871 commit 0b6e88b

File tree

4 files changed

+94
-1
lines changed

4 files changed

+94
-1
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
package p;
2+
3+
import java.util.HashSet;
4+
import java.util.stream.*;
5+
6+
import edu.cuny.hunter.streamrefactoring.annotations.*;
7+
8+
class A {
9+
10+
static void m(Stream<Object> s) {
11+
s.sorted().distinct().count();
12+
}
13+
14+
@EntryPoint
15+
public static void main(String[] args) {
16+
m(new HashSet<Object>().stream());
17+
}
18+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
package p;
2+
3+
import java.util.HashSet;
4+
import java.util.stream.*;
5+
6+
import edu.cuny.hunter.streamrefactoring.annotations.*;
7+
8+
class A {
9+
10+
static Stream<Object> m() {
11+
Stream<Object> stream = new HashSet<>().stream();
12+
return stream;
13+
}
14+
15+
@EntryPoint
16+
public static void main(String[] args) {
17+
m().sorted().distinct().count();
18+
}
19+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
package p;
2+
3+
import java.util.HashSet;
4+
import java.util.stream.*;
5+
6+
import edu.cuny.hunter.streamrefactoring.annotations.*;
7+
8+
class A {
9+
10+
static Stream<Object> m() {
11+
return new HashSet<>().stream().sorted();
12+
}
13+
14+
@EntryPoint
15+
public static void main(String[] args) {
16+
m().distinct().count();
17+
}
18+
}

edu.cuny.hunter.streamrefactoring.tests/test cases/edu/cuny/hunter/streamrefactoring/ui/tests/ConvertStreamToParallelRefactoringTest.java

+39-1
Original file line numberDiff line numberDiff line change
@@ -509,7 +509,8 @@ public void testNonInternalAPI6() throws Exception {
509509
}
510510

511511
/**
512-
* This is a control to testNonInternalAPI4.
512+
* This is a control to testNonInternalAPI4. It's the intraprocedural version.
513+
* Related to #126.
513514
*/
514515
public void testNonInternalAPI7() throws Exception {
515516
helper(new StreamAnalysisExpectedResult("new HashSet<>().stream()",
@@ -519,6 +520,43 @@ public void testNonInternalAPI7() throws Exception {
519520
Collections.emptySet()));
520521
}
521522

523+
/**
524+
* Related to #126 and based on testNonInternalAPI4. Try calling the
525+
* transitioning method in the entry point method, which is where the terminal
526+
* operation is called.
527+
*/
528+
public void testNonInternalAPI8() throws Exception {
529+
helper(new StreamAnalysisExpectedResult("new HashSet<>().stream()",
530+
Collections.singleton(ExecutionMode.SEQUENTIAL), EnumSet.of(Ordering.ORDERED), false, true, false,
531+
EnumSet.of(TransformationAction.UNORDER, TransformationAction.CONVERT_TO_PARALLEL),
532+
PreconditionSuccess.P3, Refactoring.CONVERT_SEQUENTIAL_STREAM_TO_PARALLEL, RefactoringStatus.OK,
533+
Collections.emptySet()));
534+
}
535+
536+
/**
537+
* Related to #126. Like testNonInternalAPI4 but with no local variable.
538+
*/
539+
public void testNonInternalAPI9() throws Exception {
540+
HashSet<Ordering> orderings = new HashSet<>();
541+
orderings.add(Ordering.UNORDERED);
542+
orderings.add(Ordering.ORDERED);
543+
544+
helper(new StreamAnalysisExpectedResult("new HashSet<>().stream()",
545+
Collections.singleton(ExecutionMode.SEQUENTIAL), orderings, false, true, false, null, null, null,
546+
RefactoringStatus.ERROR, EnumSet.of(PreconditionFailure.INCONSISTENT_POSSIBLE_ORDERINGS)));
547+
}
548+
549+
/**
550+
* Related to #126. Suggested by @mbagherz.
551+
*/
552+
public void testNonInternalAPI10() throws Exception {
553+
helper(new StreamAnalysisExpectedResult("new HashSet<Object>().stream()",
554+
Collections.singleton(ExecutionMode.SEQUENTIAL), EnumSet.of(Ordering.ORDERED), false, true, false,
555+
EnumSet.of(TransformationAction.UNORDER, TransformationAction.CONVERT_TO_PARALLEL),
556+
PreconditionSuccess.P3, Refactoring.CONVERT_SEQUENTIAL_STREAM_TO_PARALLEL, RefactoringStatus.OK,
557+
Collections.emptySet()));
558+
}
559+
522560
public void testCollectionFromParameter() throws Exception {
523561
helper(new StreamAnalysisExpectedResult("h.parallelStream()", Collections.singleton(ExecutionMode.PARALLEL),
524562
Collections.singleton(Ordering.UNORDERED), false, true, false, null, null, null,

0 commit comments

Comments
 (0)