Skip to content

Commit

Permalink
Protected from null argument
Browse files Browse the repository at this point in the history
Following neat feedback from Christian.

Issue #384
  • Loading branch information
mockitoguy committed Aug 13, 2016
1 parent 9842548 commit b459660
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 0 deletions.
Expand Up @@ -21,12 +21,20 @@ public void setStubbingListener(StubbingListener listener) {
}

public void addListener(MockitoListener listener) {
assertNotNull(listener);
if (listener instanceof MockCreationListener) {
mockingProgress().addListener(listener);
}
}

public void removeListener(MockitoListener listener) {
assertNotNull(listener);
mockingProgress().removeListener(listener);
}

private void assertNotNull(MockitoListener listener) {
if (listener == null) {
throw new IllegalArgumentException("listener cannot be null");
}
}
}
@@ -0,0 +1,19 @@
package org.mockito.internal.framework;

import org.junit.Test;
import org.mockitoutil.TestBase;

public class DefaultMockitoFrameworkTest extends TestBase {

DefaultMockitoFramework framework = new DefaultMockitoFramework();

@Test(expected = IllegalArgumentException.class)
public void prevents_adding_null_listener() {
framework.addListener(null);
}

@Test(expected = IllegalArgumentException.class)
public void prevents_removing_null_listener() {
framework.addListener(null);
}
}

0 comments on commit b459660

Please sign in to comment.