Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Instrumented test improvement #27

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,11 @@ public void testDefaultChocobar() {
assertEquals("Snackbar duration did not match the expected.", Snackbar.LENGTH_SHORT, chocoBar.getDuration());

assertTrue(chocolateLayout.getBackground() instanceof GradientDrawable);

// and that it can be shown
chocoBar.show();
assertTrue(chocoBar.isShown());
thenWait(1000);
}

/**
Expand Down Expand Up @@ -76,6 +81,11 @@ public void testGreenChocobar() {
assertEquals("Expected background color for snackbar layout to be #388E3C.",
Color.parseColor("#388E3C"),
((ColorDrawable) chocolateLayout.getBackground()).getColor());

// and that it can be shown
chocoBar.show();
assertTrue(chocoBar.isShown());
thenWait(1000);
}

/**
Expand Down Expand Up @@ -106,6 +116,11 @@ public void testRedChocobar() {
assertEquals("Expected background color for snackbar layout to be #D50000.",
Color.parseColor("#D50000"),
((ColorDrawable) chocolateLayout.getBackground()).getColor());

// and that it can be shown
chocoBar.show();
assertTrue(chocoBar.isShown());
thenWait(1000);
}

/**
Expand Down Expand Up @@ -136,6 +151,11 @@ public void testCyanChocobar() {
assertEquals("Expected background color for snackbar layout to be #e0ffff.",
Color.parseColor("#e0ffff"),
((ColorDrawable) chocolateLayout.getBackground()).getColor());

// and that it can be shown
chocoBar.show();
assertTrue(chocoBar.isShown());
thenWait(1000);
}

/**
Expand Down Expand Up @@ -166,6 +186,11 @@ public void testOrangeChocobar() {
assertEquals("Expected background color for snackbar layout to be #ffa500.",
Color.parseColor("#ffa500"),
((ColorDrawable) chocolateLayout.getBackground()).getColor());

// and that it can be shown
chocoBar.show();
assertTrue(chocoBar.isShown());
thenWait(1000);
}

/**
Expand Down Expand Up @@ -196,6 +221,11 @@ public void testGoodChocobar() {
assertEquals("Expected background color for snackbar layout to be #C5BEBE.",
Color.parseColor("#C5BEBE"),
((ColorDrawable) chocolateLayout.getBackground()).getColor());

// and that it can be shown
chocoBar.show();
assertTrue(chocoBar.isShown());
thenWait(1000);
}

/**
Expand Down Expand Up @@ -226,6 +256,11 @@ public void testBadChocobar() {
assertEquals("Expected background color for snackbar layout to be #C5BEBE.",
Color.parseColor("#C5BEBE"),
((ColorDrawable) chocolateLayout.getBackground()).getColor());

// and that it can be shown
chocoBar.show();
assertTrue(chocoBar.isShown());
thenWait(1000);
}

/**
Expand Down Expand Up @@ -256,6 +291,11 @@ public void testBlackChocobar() {
assertEquals("Expected background color for snackbar layout to be #000000.",
Color.parseColor("#000000"),
((ColorDrawable) chocolateLayout.getBackground()).getColor());

// and that it can be shown
chocoBar.show();
assertTrue(chocoBar.isShown());
thenWait(1000);
}

/**
Expand Down Expand Up @@ -286,6 +326,11 @@ public void testLoveChocobar() {
assertEquals("Expected background color for snackbar layout to be #E8290B.",
Color.parseColor("#E8290B"),
((ColorDrawable) chocolateLayout.getBackground()).getColor());

// and that it can be shown
chocoBar.show();
assertTrue(chocoBar.isShown());
thenWait(1000);
}

/**
Expand Down Expand Up @@ -316,5 +361,53 @@ public void testNotificationOnChocobar() {
assertEquals("Expected background color for snackbar layout to be #000000.",
Color.parseColor("#000000"),
((ColorDrawable) chocolateLayout.getBackground()).getColor());

// and that it can be shown
chocoBar.show();
assertTrue(chocoBar.isShown());
thenWait(1000);
}

/**
* Verifies the blocked Chocobar type.
*/
@Test
public void testBlockedChocobar() {
// Given chocobar builder
ChocoBar.Builder chocoBarBuilder = ChocoBar.builder()
.setView(activityTestRule.getActivity().getCurrentFocus());

// When building a blocked Snackbar
Snackbar chocoBar = chocoBarBuilder.blocked();

// Then it matches the expected configuration
Snackbar.SnackbarLayout chocolateLayout = (Snackbar.SnackbarLayout) chocoBar.getView();

TextView snackbarText = (TextView) chocolateLayout.findViewById(R.id.snackbar_text);
assertEquals(
"Snackbar text did not match the expected.",
"BLOCKED",
snackbarText.getText());

assertEquals("Snackbar duration did not match the expected.",
Snackbar.LENGTH_SHORT,
chocoBar.getDuration());

assertEquals("Expected background color for snackbar layout to be #E8290B.",
Color.parseColor("#E8290B"),
((ColorDrawable) chocolateLayout.getBackground()).getColor());

// and that it can be shown
chocoBar.show();
assertTrue(chocoBar.isShown());
thenWait(1000);
}

private void thenWait(long milliseconds) {
try {
Thread.sleep(milliseconds);
} catch (InterruptedException e) {
e.printStackTrace();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,17 @@
*/
@RunWith(AndroidJUnit4.class)
public class ExampleInstrumentedTest {
/**
* Verifies that the package name of the app context returns the expected value.
*/
@Test
public void useAppContext() {
// Context of the app under test.
// Given Context of the app under test.
Context appContext = InstrumentationRegistry.getTargetContext();

// When getting the package name

// Then it matches the expected value
assertEquals("com.pd.snickers", appContext.getPackageName());
}
}