Skip to content
This repository has been archived by the owner on Jan 9, 2020. It is now read-only.

Commit

Permalink
Add some guards related to the PresenterLifeCycleLinker public methods
Browse files Browse the repository at this point in the history
  • Loading branch information
pedrovgs committed Mar 28, 2016
1 parent d2f2a2d commit 3534c6f
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,15 @@ public final class PresenterLifeCycleLinker {
private final Set<RosiePresenter> presenters = new HashSet<>();

public void initializeLifeCycle(Object source, RosiePresenter.View view) {
if (source == null) {
throw new IllegalArgumentException(
"The source instance used to initialize the presenters can't be null");
}
if (view == null) {
throw new IllegalArgumentException(
"The view instance used to initialize the presenters can't be null");
}

addAnnotatedPresenter(source);
setView(view);
initializePresenters();
Expand All @@ -42,6 +51,10 @@ public void initializePresenters() {
}

public void updatePresenters(RosiePresenter.View view) {
if (view == null) {
throw new IllegalArgumentException(
"The view instance used to update the presenters can't be null");
}
for (RosiePresenter presenter : presenters) {
presenter.setView(view);
presenter.update();
Expand All @@ -62,10 +75,17 @@ public void destroyPresenters() {
}

public void registerPresenter(RosiePresenter presenter) {
if (presenter == null) {
throw new IllegalArgumentException("The presenter instance to be registered can't be null");
}
presenters.add(presenter);
}

public void setView(RosiePresenter.View view) {
if (view == null) {
throw new IllegalArgumentException(
"The view instance used to configure the presenters can't be null");
}
for (RosiePresenter presenter : presenters) {
presenter.setView(view);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,35 @@ public void shouldThrowExceptionIfThereAnnotatedPresenterVisibilityIsPrivate() {
presenterLifeCycleLinker.initializeLifeCycle(source, anyView);
}

@Test(expected = IllegalArgumentException.class)
public void shouldNotAcceptNullSourcesToInitializeTheLifeCycle() {
PresenterLifeCycleLinker presenterLifeCycleLinker = givenAPresenterLifecycleLinker();

presenterLifeCycleLinker.initializeLifeCycle(null, anyView);
}

@Test(expected = IllegalArgumentException.class)
public void shouldNotAcceptNullViewsToInitializeTheLifeCycle() {
PresenterLifeCycleLinker presenterLifeCycleLinker = givenAPresenterLifecycleLinker();
Object source = givenAnyClassWithAnAnnotatedPresenter(anyPresenter1);

presenterLifeCycleLinker.initializeLifeCycle(source, null);
}

@Test(expected = IllegalArgumentException.class)
public void shouldNotAcceptNullViewsToConfigureThePresenters() {
PresenterLifeCycleLinker presenterLifeCycleLinker = givenAPresenterLifecycleLinker();

presenterLifeCycleLinker.setView(null);
}

@Test(expected = IllegalArgumentException.class)
public void shouldNotAcceptNullPresentersToRegister() {
PresenterLifeCycleLinker presenterLifeCycleLinker = givenAPresenterLifecycleLinker();

presenterLifeCycleLinker.registerPresenter(null);
}

private PresenterLifeCycleLinker givenAPresenterLifecycleLinker(RosiePresenter... presenters) {
PresenterLifeCycleLinker presenterLifeCycleLinker = new PresenterLifeCycleLinker();
for (RosiePresenter presenter : presenters) {
Expand Down

0 comments on commit 3534c6f

Please sign in to comment.