This file contains 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
<?xml version="1.0" encoding="utf-8"?> | |
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" | |
android:layout_width="match_parent" | |
android:layout_height="match_parent"> | |
<TextView android:id="@+id/login_result" | |
android:layout_width="wrap_content" | |
android:layout_height="wrap_content" | |
android:layout_alignParentTop="true" | |
android:layout_centerInParent="true" |
This file contains 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 class LoginActivityTest { | |
@Rule | |
public ActivityTestRule mActivityRule = new ActivityTestRule(LoginActivity.class); | |
private Resources resources; | |
@Before | |
public void init() { | |
resources = mActivityRule.getActivity().getResources(); | |
} |
This file contains 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
<?xml version="1.0" encoding="utf-8"?> | |
<LinearLayout android:id="@+id/parent_container" | |
xmlns:android="http://schemas.android.com/apk/res/android" | |
android:layout_width="match_parent" | |
android:layout_height="match_parent" | |
android:orientation="vertical"> | |
<LinearLayout | |
android:layout_width="match_parent" | |
android:layout_height="match_parent" | |
android:orientation="vertical"> |
This file contains 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 class NestedLayoutActivityTest { | |
@Rule | |
public ActivityTestRule mActivityRule = new ActivityTestRule(NestedLayoutActivity.class); | |
@Test | |
public void performClickOnTextView() { | |
onView(withId(R.id.parent_container)).perform(new ViewAction() { | |
@Override |
This file contains 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
@Rule | |
public ActivityTestRule mActivityRule = new ActivityTestRule(LoginActivity.class, false, false); | |
@Before | |
public void init() { | |
Intent intent = new Intent(); | |
intent.putExtra("key", "value"); | |
mActivityRule.launchActivity(intent); | |
} |
This file contains 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 turnOffWifi() throws UiObjectNotFoundException { | |
String wiFi = "Wi‑Fi"; | |
//Get an instance of device and press home button | |
UiDevice device = UiDevice.getInstance(InstrumentationRegistry.getInstrumentation()); | |
device.pressHome(); | |
//To get the list of all apps, find an object which has description "Apps" and click it | |
UiObject2 allApps = device.findObject(By.desc("Apps")); |
This file contains 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
/** | |
* Method to check whether to check Google Play Services is up to date. | |
* | |
* @return | |
*/ | |
private boolean checkPlayServices() { | |
GoogleApiAvailability googleAPI = GoogleApiAvailability.getInstance(); | |
int result = googleAPI.isGooglePlayServicesAvailable(this); | |
if (result != ConnectionResult.SUCCESS) { | |
//Google Play Services app is not available or version is not up to date. Error the |
This file contains 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
if (result != ConnectionResult.SUCCESS) { | |
//Any random request code | |
int PLAY_SERVICES_RESOLUTION_REQUEST = 1000; | |
//Google Play Services app is not available or version is not up to date. Error the | |
// error condition here | |
if (googleAPI.isUserResolvableError(result)) { | |
googleAPI.getErrorDialog(this, result, | |
PLAY_SERVICES_RESOLUTION_REQUEST).show(); | |
} | |
return false; |
This file contains 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 class RandomClass{ | |
private static final String characters = "abcdefghijklmnopqrstuvwxyz0123456789"; | |
public static String getRandomString(int length) { | |
if (length < 0 || length > 10) { | |
return "Random"; | |
} | |
StringBuilder stringBuilder = new StringBuilder(); | |
Random random = new Random(); |
This file contains 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 class StringPrinter { | |
private final ThreadPoolExecutor threadPoolExecutor = new ThreadPoolExecutor(2, 2, 0, | |
TimeUnit.MILLISECONDS, new LinkedBlockingQueue<Runnable>()); | |
public static void main(String[] args) { | |
new StringPrinter().printString(); | |
} | |
public void printString() { |
OlderNewer