Created
February 5, 2020 15:59
-
-
Save seadowg/a9dd682666b2ec7b8f9d242f6553e9ea to your computer and use it in GitHub Desktop.
Default answer in ImageWidget test
This file contains hidden or 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
public final class Helpers { | |
private Helpers() { | |
} | |
public static String createMockReference(ReferenceManager referenceManager, String referenceURI) throws InvalidReferenceException { | |
String localURI = UUID.randomUUID().toString(); | |
return createMockReference(referenceManager, referenceURI, localURI); | |
} | |
public static String createMockReference(ReferenceManager referenceManager, String referenceURI, String localURI) throws InvalidReferenceException { | |
Reference reference = mock(Reference.class); | |
when(reference.getLocalURI()).thenReturn(localURI); | |
when(referenceManager.deriveReference(referenceURI)).thenReturn(reference); | |
return localURI; | |
} | |
} |
This file contains hidden or 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
@Test | |
public void whenPromptHasDefaultAnswer_showsInImageView() throws Exception { | |
ReferenceManager referenceManager = mock(ReferenceManager.class); | |
RobolectricHelpers.overrideAppDependencyModule(new AppDependencyModule() { | |
@Override | |
public ReferenceManager providesReferenceManager() { | |
return referenceManager; | |
} | |
}); | |
String referenceURI = "jr://images/referenceURI"; | |
String imagePath = createMockReference( | |
referenceManager, | |
referenceURI, | |
File.createTempFile("blah", ".bmp").getAbsolutePath() | |
); | |
FormEntryPrompt prompt = new MockFormEntryPromptBuilder() | |
.withAnswerDisplayText(referenceURI) | |
.build(); | |
SignatureWidget widget = new SignatureWidget(RobolectricHelpers.createThemedActivity(TestScreenContextActivity.class), new QuestionDetails(prompt, "")); | |
String loadedImagePath = shadowOf(((BitmapDrawable) widget.getImageView().getDrawable()).getBitmap()).getCreatedFromPath(); | |
assertThat(loadedImagePath, equalTo(imagePath)); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment