Skip to content
This repository has been archived by the owner on Aug 10, 2022. It is now read-only.

Commit

Permalink
Tweaking testing mocks
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexanderEggers committed Feb 22, 2018
1 parent 755bd33 commit 4850662
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 1 deletion.
18 changes: 17 additions & 1 deletion testing/src/main/java/org/hitogo/core/HitogoMock.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,13 @@

public class HitogoMock {

public static <T extends Hitogo> T getMock(Hitogo hitogo) {
return getMock(hitogo, DialogAlertBuilderMock.getMock(),PopupAlertBuilderMock.getMock(),
SnackbarAlertBuilderMock.getMock(), ToastAlertBuilderMock.getMock(),
ViewAlertBuilderMock.getMock(), CloseButtonBuilderMock.getMock(),
TextButtonBuilderMock.getMock(), ViewButtonBuilderMock.getMock());
}

public static Hitogo getMock() {
return getMock(DialogAlertBuilderMock.getMock(),PopupAlertBuilderMock.getMock(),
SnackbarAlertBuilderMock.getMock(), ToastAlertBuilderMock.getMock(),
Expand All @@ -36,6 +43,15 @@ public static Hitogo getMock(DialogAlertBuilder dialogAlertBuilder, PopupAlertBu
TextButtonBuilder textButtonBuilderMock, ViewButtonBuilder viewButtonBuilderMock) {

Hitogo hitogo = mock(Hitogo.class);
return getMock(hitogo, dialogAlertBuilder, popupAlertBuilder, snackbarAlertBuilder, toastAlertBuilder,
viewAlertBuilder, closeButtonBuilderMock, textButtonBuilderMock, viewButtonBuilderMock);
}

@SuppressWarnings("unchecked")
public static <T extends Hitogo> T getMock(Hitogo hitogo, DialogAlertBuilder dialogAlertBuilder, PopupAlertBuilder popupAlertBuilder,
SnackbarAlertBuilder snackbarAlertBuilder, ToastAlertBuilder toastAlertBuilder,
ViewAlertBuilder viewAlertBuilder, ViewButtonBuilder closeButtonBuilderMock,
TextButtonBuilder textButtonBuilderMock, ViewButtonBuilder viewButtonBuilderMock) {

when(hitogo.asDialogAlert()).thenReturn(dialogAlertBuilder);
when(hitogo.asDialogAlert(any(Class.class), any(Class.class))).thenReturn(dialogAlertBuilder);
Expand Down Expand Up @@ -69,6 +85,6 @@ public static Hitogo getMock(DialogAlertBuilder dialogAlertBuilder, PopupAlertBu
when(hitogo.asViewButton(any(Class.class), any(Class.class))).thenReturn(viewButtonBuilderMock);
when(hitogo.asViewButton(any(Class.class))).thenReturn(viewButtonBuilderMock);

return hitogo;
return (T) hitogo;
}
}
23 changes: 23 additions & 0 deletions testing/src/main/java/org/hitogo/core/HitogoServiceMock.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,12 @@ public static <T extends HitogoService> T getMock(HitogoService hitogoService) {
return (T) hitogoService;
}

public static <T extends HitogoService> T getMock(HitogoService hitogoService, Hitogo hitogo) {
when(hitogoService.create())
.thenReturn(HitogoMock.getMock(hitogo));
return (T) hitogoService;
}

public static <T extends HitogoService> T getMock(HitogoService hitogoService,
DialogAlertBuilder dialogAlertBuilder,
PopupAlertBuilder popupAlertBuilder,
Expand All @@ -34,4 +40,21 @@ public static <T extends HitogoService> T getMock(HitogoService hitogoService,
closeButtonBuilderMock, textButtonBuilderMock, viewButtonBuilderMock));
return (T) hitogoService;
}

public static <T extends HitogoService> T getMock(HitogoService hitogoService,
Hitogo hitogo,
DialogAlertBuilder dialogAlertBuilder,
PopupAlertBuilder popupAlertBuilder,
SnackbarAlertBuilder snackbarAlertBuilder,
ToastAlertBuilder toastAlertBuilder,
ViewAlertBuilder viewAlertBuilder,
ViewButtonBuilder closeButtonBuilderMock,
TextButtonBuilder textButtonBuilderMock,
ViewButtonBuilder viewButtonBuilderMock) {
when(hitogoService.create())
.thenReturn(HitogoMock.getMock(hitogo, dialogAlertBuilder, popupAlertBuilder,
snackbarAlertBuilder, toastAlertBuilder, viewAlertBuilder,
closeButtonBuilderMock, textButtonBuilderMock, viewButtonBuilderMock));
return (T) hitogoService;
}
}

0 comments on commit 4850662

Please sign in to comment.