Skip to content

Commit c0a7a90

Browse files
committed
Stream method fixes
1 parent 759f676 commit c0a7a90

File tree

4 files changed

+32
-10
lines changed

4 files changed

+32
-10
lines changed

README.md

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -50,12 +50,6 @@ List<Opportunity> largeOpportunities = SObjectCollection.of(opportunities)
5050
.asList();
5151
```
5252

53-
### Debug
54-
55-
```apex
56-
SObjectCollection.of(opportunities).forEach(Fn.Debug);
57-
```
58-
5953
### Group
6054

6155
```apex

force-app/main/default/classes/stream/SObjectStreamFilter.cls

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ public with sharing class SObjectStreamFilter extends SObjectStream {
1414
SObject nextRecord = recordsIterator.next();
1515
if (predicate.call(nextRecord)) {
1616
next = nextRecord;
17-
hasNext = true;
1817
return true;
1918
}
2019
}
@@ -30,7 +29,7 @@ public with sharing class SObjectStreamFilter extends SObjectStream {
3029

3130
public virtual override SObject next() {
3231
if (hasNext == null) {
33-
tryAdvance();
32+
hasNext = tryAdvance();
3433
}
3534
if (hasNext) {
3635
SObject nextRecord = next;

force-app/main/default/classes/stream/SObjectStreamRemove.cls

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ public with sharing class SObjectStreamRemove extends SObjectStream {
1414
SObject nextRecord = recordsIterator.next();
1515
if (!predicate.call(nextRecord)) {
1616
next = nextRecord;
17-
hasNext = true;
1817
return true;
1918
}
2019
}
@@ -30,7 +29,7 @@ public with sharing class SObjectStreamRemove extends SObjectStream {
3029

3130
public virtual override SObject next() {
3231
if (hasNext == null) {
33-
tryAdvance();
32+
hasNext = tryAdvance();
3433
}
3534
if (hasNext) {
3635
SObject nextRecord = next;

force-app/main/default/classes/test/stream/SObjectStreamTest.cls

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,36 @@ private class SObjectStreamTest {
1919
System.Assert.areEqual(accounts[2], filtered[1]);
2020
}
2121

22+
@IsTest
23+
private static void filterThrowsExceptionWhenNextIsCalledAndHasNextIsFalse() {
24+
List<Account> accounts = new List<Account>{
25+
new Account(Name = 'Wrong', AnnualRevenue = 100)
26+
};
27+
Iterator<SObject> iter = SObjectStream.of(accounts).filter(Fn.Match.field(Account.Name).equals('Ok'));
28+
29+
try {
30+
iter.next();
31+
System.Assert.fail();
32+
} catch (NoSuchElementException e) {
33+
System.Assert.isTrue(true);
34+
}
35+
}
36+
37+
@IsTest
38+
private static void removeThrowsExceptionWhenNextIsCalledAndHasNextIsFalse() {
39+
List<Account> accounts = new List<Account>{
40+
new Account(Name = 'Ok', AnnualRevenue = 100)
41+
};
42+
Iterator<SObject> iter = SObjectStream.of(accounts).remove(Fn.Match.field(Account.Name).equals('Ok'));
43+
44+
try {
45+
iter.next();
46+
System.Assert.fail();
47+
} catch (NoSuchElementException e) {
48+
System.Assert.isTrue(true);
49+
}
50+
}
51+
2252
@IsTest
2353
private static void testFilterChaining() {
2454
List<Account> accounts = new List<Account>{

0 commit comments

Comments
 (0)