Skip to content

Instantly share code, notes, and snippets.

@Module
public class MyAppModuleMock extends MyAppModule {
@Provides
@Singleton
@Override
MyAppNetworkService providesMyAppNetworkService() {
return new MyAppNetworkServiceMock();
}
@RunWith(AndroidJUnit4.class)
public class MainActivityTests {
@Rule
public ActivityTestRule<MainActivity> activityRule =
new ActivityTestRule<>(MainActivity.class);
@Before
public void init() {
public class MyAppNetworkServiceMock extends MyAppNetworkService {
@Override
public List<Object> getUsers() {
List<Object> objects = new ArrayList<>();
//Mocking
//.....................
objects.add(new Object());
public class MainActivity extends AppCompatActivity {
@Inject
MyAppNetworkService myAppNetworkService;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
@oznus
oznus / component.java
Created July 18, 2017 04:31
Mocking UI tests module and component
@Singleton
@Component(modules = {
MyAppModule.class})
public interface MyAppComponent {
void inject(MainActivity activity);
}
@oznus
oznus / mocking_ui_app.java
Last active July 18, 2017 04:23
Mocking UI Application
public class MyAppApplication extends Application {
MyAppComponent myAppComponent;
@Override
public void onCreate() {
super.onCreate();
myAppComponent = DaggerMyAppComponent.builder()
.myAppModule(new MyAppModule())
public class MainActivity extends AppCompatActivity {
ChatAdapter chatAdapter;
RecyclerView recyclerView;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
public class MainActivity extends AppCompatActivity {
ChatAdapter chatAdapter;
RecyclerView recyclerView;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
public class ChatAdapter extends RecyclerView.Adapter<ItemViewHolder> {
private final Context context;
public ChatAdapter(Context context) {
this.context = context;
}
protected List<Item> items = new ArrayList<>();
public class FetchingJsonActivity extends AppCompatActivity {
@Inject
UserService userService;
private UserView someView;
private CompositeSubscription compositeSubscription = new CompositeSubscription();
@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);