Skip to content

Instantly share code, notes, and snippets.

@ecgreb
Created February 3, 2017 15:37
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ecgreb/671efdcec7a5b5f337960c8c66819521 to your computer and use it in GitHub Desktop.
Save ecgreb/671efdcec7a5b5f337960c8c66819521 to your computer and use it in GitHub Desktop.
public class ResourceManagerTest {
private TestResources resources = new TestResources();
private ResourceManager resourceManager = new ResourceManager(resources);
@Test public void shouldNotBeNull() throws Exception {
assertThat(resourceManager).isNotNull();
}
@Test public void getTitle_true_shouldReturnSuccessTitle() throws Exception {
assertThat(resourceManager.getTitle(true)).isEqualTo("Success");
}
@Test public void getTitle_false_shouldReturnErrorTitle() throws Exception {
assertThat(resourceManager.getTitle(false)).isEqualTo("Error");
}
@Test public void getDescription_true_shouldReturnSuccessDescription() throws Exception {
assertThat(resourceManager.getDescription(true)).isEqualTo("Congrats you did it!");
}
@Test public void getDescription_false_shouldReturnErrorDescription() throws Exception {
assertThat(resourceManager.getDescription(false)).isEqualTo("Uh oh something went wrong");
}
private class TestResources extends Resources {
public TestResources() {
super(null, null, null);
}
@NonNull @Override public String getString(int id) throws NotFoundException {
switch (id) {
case R.string.success_title:
return "Success";
case R.string.error_title:
return "Error";
case R.string.success_description:
return "Congrats you did it!";
case R.string.error_description:
return "Uh oh something went wrong";
}
throw new NotFoundException();
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment