Last active
December 20, 2015 14:09
-
-
Save pavelshackih/6143998 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package org.sample; | |
import java.util.ArrayList; | |
import static org.hamcrest.CoreMatchers.equalTo; | |
import static org.mockito.Matchers.argThat; | |
import static org.mockito.Mockito.mock; | |
import static org.mockito.Mockito.verify; | |
public class Sample { | |
public static void main(String... args) { | |
MainActivity activity = mock(MainActivity.class); | |
MyRequest subject = new MyRequest(activity); | |
ArrayList<MyModel> list = new ArrayList<>(); | |
list.add(new MyModel(1)); | |
subject.makeRequest(); | |
verify(activity).handleSuccess(argThat(equalTo(list))); | |
} | |
static class MainActivity { | |
public void handleSuccess(ArrayList<MyModel> list) { | |
} | |
} | |
static class MyRequest { | |
MainActivity mainActivity; | |
MyRequest(MainActivity mainActivity) { | |
this.mainActivity = mainActivity; | |
} | |
void makeRequest() { | |
ArrayList<MyModel> list = new ArrayList<>(); | |
list.add(new MyModel(1)); | |
mainActivity.handleSuccess(list); | |
} | |
} | |
static class MyModel { | |
final int id; | |
MyModel(int id) { | |
this.id = id; | |
} | |
@Override | |
public boolean equals(Object o) { | |
System.out.println("Equals invoked: " + toString()); | |
if (this == o) return true; | |
if (o == null || getClass() != o.getClass()) return false; | |
MyModel myModel = (MyModel) o; | |
if (id != myModel.id) return false; | |
return true; | |
} | |
@Override | |
public int hashCode() { | |
return id; | |
} | |
@Override | |
public String toString() { | |
return "MyModel{" + | |
"id=" + id + | |
'}'; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment