Skip to content

Instantly share code, notes, and snippets.

👀
Forever coding

Mitch Tabian mitchtabian

Block or report user

Report or block mitchtabian

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
View NoteViewModel.java
public class NoteViewModel extends ViewModel {
private static final String TAG = "NoteViewModel";
// inject
private final NoteRepository noteRepository;
// vars
private MutableLiveData<Note> note = new MutableLiveData<>();
View MockitoExtension.java
import org.junit.jupiter.api.extension.ExtensionContext;
import org.junit.jupiter.api.extension.ExtensionContext.Namespace;
import org.junit.jupiter.api.extension.ExtensionContext.Store;
import org.junit.jupiter.api.extension.ParameterContext;
import org.junit.jupiter.api.extension.ParameterResolver;
import org.junit.jupiter.api.extension.TestInstancePostProcessor;
import org.mockito.Mock;
import org.mockito.MockitoAnnotations;
import java.lang.reflect.Parameter;
View ApiServiceNotifierTest.java
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.RepeatedTest;
import org.junit.jupiter.api.RepetitionInfo;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.function.Executable;
import static org.junit.jupiter.api.Assertions.*;
@DisplayName("Api Service Test")
@mitchtabian
mitchtabian / ApiService.java
Last active Apr 30, 2019
example: Unit Testing Stubs (Mock Services) - NOT using Mockito
View ApiService.java
// main package
public interface ApiService {
void createNewUser(User user);
}
@mitchtabian
mitchtabian / Right.java
Created Apr 30, 2019
assertAll example
View Right.java
@Test
@DisplayName("Subtracting two numbers")
public void testSubtract1(){
assertAll(
new Executable() {
@Override
public void execute() throws Throwable {
assertEquals(3, calculator.subtract(6, 3));
}
},
View AppModule.java
@Singleton
@Provides
static User someUser(){
return new User();
}
@mitchtabian
mitchtabian / AppComponent.java
Created Apr 15, 2019
Old way to make app component
View AppComponent.java
@Component
public interface AppComponent {
void inject(BaseApplication application);
}
@mitchtabian
mitchtabian / AppInjector.java
Last active Apr 6, 2019
Scope example with an @singleton User object and @LoginScope User object
View AppInjector.java
@Override
public void onActivityDestroyed(Activity activity) {
if(activity instanceof LoginActivity){
loginComponent = null;
}
}
private void handleActivity(Activity activity){
if(activity instanceof HasSupportFragmentInjector){
@mitchtabian
mitchtabian / AppComponent.java
Created Apr 5, 2019
Example of making use of the Application context using @Component.Builder in AppComponent class (new way)
View AppComponent.java
@Singleton
@Component(
modules = {
AndroidInjectionModule.class,
AppModule.class,
ActivityBuildersModule.class
})
public interface AppComponent extends AndroidInjector<BaseApplication> {
@Component.Builder
@mitchtabian
mitchtabian / AppComponent.java
Last active Apr 5, 2019
Example of NOT making use of @Component.Builder and @BindsInstance (this is the old way)
View AppComponent.java
@Singleton
@Component(
modules = {
AndroidInjectionModule.class,
AppModule.class,
ActivityBuildersModule.class
})
public interface AppComponent extends AndroidInjector<BaseApplication> {
}
You can’t perform that action at this time.