Skip to content
Merged
Changes from all commits
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
beb0116
fix spring config
Doha2012 Aug 3, 2017
9c74046
fix spring config
Doha2012 Aug 5, 2017
2ca9277
Merge remote-tracking branch 'eugenp/master'
Doha2012 Aug 5, 2017
af812ec
fix spring config
Doha2012 Aug 7, 2017
c4141ab
Merge remote-tracking branch 'eugenp/master'
Doha2012 Aug 7, 2017
df746c6
minor fix
Doha2012 Aug 9, 2017
069d7a3
Merge remote-tracking branch 'eugenp/master'
Doha2012 Aug 9, 2017
5e4c913
Merge remote-tracking branch 'eugenp/master'
Doha2012 Aug 10, 2017
1053180
fix spring-boot module
Doha2012 Aug 11, 2017
99bad7d
Merge remote-tracking branch 'eugenp/master'
Doha2012 Aug 11, 2017
fcbfecf
fix pom
Doha2012 Aug 11, 2017
08eb127
Merge remote-tracking branch 'eugenp/master'
Doha2012 Aug 19, 2017
b47a367
upgrade jackson
Doha2012 Aug 19, 2017
8fa09b2
minor fix
Doha2012 Aug 20, 2017
d76aa38
Merge remote-tracking branch 'eugenp/master'
Doha2012 Aug 20, 2017
3f1d94f
Merge remote-tracking branch 'eugenp/master'
Doha2012 Aug 23, 2017
c0b64d4
java concurrency
Doha2012 Aug 25, 2017
f4f8be1
cleanup
Doha2012 Aug 25, 2017
29d6807
Merge remote-tracking branch 'eugenp/master'
Doha2012 Aug 25, 2017
d2b90c6
merge
Doha2012 Aug 28, 2017
c9e275a
fix conflict
Doha2012 Aug 28, 2017
9044109
java 8
Doha2012 Aug 30, 2017
5a463b3
clean up
Doha2012 Aug 30, 2017
8c43cc2
add core-java-8 to main pom
Doha2012 Aug 30, 2017
8aa9a65
Merge remote-tracking branch 'eugenp/master'
Doha2012 Sep 20, 2017
3d164d0
rename kotlin to core-kotlin
Doha2012 Sep 20, 2017
9a70874
Merge remote-tracking branch 'eugenp/master'
Doha2012 Sep 30, 2017
e820fbb
update spring 5
Doha2012 Oct 2, 2017
dfc0a97
Merge remote-tracking branch 'eugenp/master'
Doha2012 Oct 2, 2017
691f929
cleanup pom
Doha2012 Oct 2, 2017
7b618af
Merge remote-tracking branch 'eugenp/master'
Doha2012 Oct 5, 2017
a4ca964
mockito exceptions
Doha2012 Oct 7, 2017
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
package org.baeldung.mockito;

import static org.mockito.ArgumentMatchers.anyString;
import static org.mockito.Mockito.doThrow;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;

import org.junit.Test;
import org.mockito.Mockito;

public class MockitoExceptionIntegrationTest {

@Test(expected = NullPointerException.class)
public void whenConfigNonVoidRetunMethodToThrowEx_thenExIsThrown() {
MyDictionary dictMock = mock(MyDictionary.class);
when(dictMock.getMeaning(anyString())).thenThrow(NullPointerException.class);

dictMock.getMeaning("word");
}

@Test(expected = IllegalStateException.class)
public void whenConfigVoidRetunMethodToThrowEx_thenExIsThrown() {
MyDictionary dictMock = mock(MyDictionary.class);
doThrow(IllegalStateException.class).when(dictMock)
.add(anyString(), anyString());

dictMock.add("word", "meaning");
}

@Test(expected = NullPointerException.class)
public void whenConfigNonVoidRetunMethodToThrowExWithNewExObj_thenExIsThrown() {
MyDictionary dictMock = mock(MyDictionary.class);
when(dictMock.getMeaning(anyString())).thenThrow(new NullPointerException("Error occurred"));

dictMock.getMeaning("word");
}

@Test(expected = IllegalStateException.class)
public void whenConfigVoidRetunMethodToThrowExWithNewExObj_thenExIsThrown() {
MyDictionary dictMock = mock(MyDictionary.class);
doThrow(new IllegalStateException("Error occurred")).when(dictMock)
.add(anyString(), anyString());

dictMock.add("word", "meaning");
}

// =====

@Test(expected = NullPointerException.class)
public void givenSpy_whenConfigNonVoidRetunMethodToThrowEx_thenExIsThrown() {
MyDictionary dict = new MyDictionary();
MyDictionary spy = Mockito.spy(dict);

when(spy.getMeaning(anyString())).thenThrow(NullPointerException.class);
spy.getMeaning("word");
}
}