Skip to content

Commit

Permalink
mockito#2974: reproduce NPE
Browse files Browse the repository at this point in the history
  • Loading branch information
jfrantzius committed Apr 16, 2023
1 parent 6ffd23e commit e40026f
Showing 1 changed file with 27 additions and 0 deletions.
Expand Up @@ -8,13 +8,15 @@
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertNull;
import static org.junit.jupiter.api.Assertions.assertSame;
import static org.mockito.MockitoAnnotations.*;

import java.sql.Time;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Date;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Set;
Expand Down Expand Up @@ -345,5 +347,30 @@ public void testMockExists() {

}

/**
* Verify regression https://github.com/mockito/mockito/issues/2974 is fixed.
*/
@Nested
public class RegressionNpe {
public abstract class Change {}
public class ChangeCollection<TChange extends Change> implements Iterable<TChange> {
private List<TChange> changes = new ArrayList<TChange>();
@Override
public Iterator<TChange> iterator() {
return null;
}
}

@Mock Change change0;

@InjectMocks ChangeCollection spiedImpl = new ChangeCollection();
@Mock(name = "changes") List<Change> innerList;

@Test
public void testNoNpe() {
assertSame(innerList, spiedImpl.changes);
}

}
}

0 comments on commit e40026f

Please sign in to comment.