Skip to content
Open
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
8 changes: 8 additions & 0 deletions .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
package com.example.simpleparadox.listycity;

import static junit.framework.TestCase.assertTrue;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;

import android.app.Activity;
import android.widget.EditText;
import android.widget.ListView;

import androidx.test.ext.junit.runners.AndroidJUnit4;
import androidx.test.platform.app.InstrumentationRegistry;
import androidx.test.rule.ActivityTestRule;

import com.robotium.solo.Solo;

import org.junit.After;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.junit.runner.RunWith;

/**
* Test class for MainActivity. All the UI tests are written here. Robotium test framework is used
*/
@RunWith(AndroidJUnit4.class)
public class ShowActivityTest {

private Solo solo;

@Rule
public ActivityTestRule<ShowActivity> rule =
new ActivityTestRule<>(ShowActivity.class, true, true);
/**
* Runs before all tests and creates solo instance.
* @throws Exception
*/
@Before
public void setUp() throws Exception{

solo = new Solo(InstrumentationRegistry.getInstrumentation(),rule.getActivity());
}
/**
* Gets the Activity
* @throws Exception
*/
@Test
public void start() throws Exception{
Activity activity = rule.getActivity();
}
/**
* Add a city to the listview and check the city name using assertTrue
* Clear all the cities from the listview and check again with assertFalse
*/
@Test
public void checkButton(){
// Asserts that the current activity is the Show Activity. Otherwise, show “Wrong Activity”
solo.assertCurrentActivity("Wrong Activity", ShowActivity.class);

solo.clickOnButton("MAIN"); //Click Button

solo.assertCurrentActivity("Wrong Activity", MainActivity.class);

}


/**
* Close activity after each test
* @throws Exception
*/
@After
public void tearDown() throws Exception{
solo.finishOpenedActivities();
}
}
13 changes: 12 additions & 1 deletion app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
package="com.example.simpleparadox.listycity">

<application
Expand All @@ -9,10 +10,20 @@
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/AppTheme">
<activity android:name=".MainActivity">
<activity android:name=".MainActivity"
android:exported="true">
<intent-filter>
<action android:name="android.intent.action.MAIN" />

<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name=".ShowActivity"
android:exported="true"
tools:ignore="DuplicateActivity">
<intent-filter>
<action android:name="android.intent.action.SHOW" />

<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,16 @@

import androidx.appcompat.app.AppCompatActivity;

import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.util.SparseBooleanArray;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.EditText;
import android.widget.LinearLayout;
import android.widget.ListAdapter;
import android.widget.ListView;

import java.util.ArrayList;
import java.util.Arrays;

public class MainActivity extends AppCompatActivity {

Expand Down Expand Up @@ -71,6 +67,14 @@ public void onClick(View v) {
}
});

final Button gotoShowActivity = findViewById(R.id.button_goto_showActivity);
gotoShowActivity.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
Intent intent2 = new Intent(MainActivity.this, ShowActivity.class);
startActivity(intent2);
}
});

}


Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package com.example.simpleparadox.listycity;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;

import androidx.appcompat.app.AppCompatActivity;


public class ShowActivity extends AppCompatActivity {
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_show);


final Button gotoMainActivity = findViewById(R.id.button_goto_Main);
gotoMainActivity.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
Intent intent = new Intent(ShowActivity.this, MainActivity.class);
startActivity(intent);
}
});

}

}
10 changes: 8 additions & 2 deletions app/src/main/res/layout/activity_main.xml
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,21 @@

<Button
android:id="@+id/button_add"
android:layout_width="180dp"
android:layout_width="100dp"
android:layout_height="wrap_content"
android:text="ADD CITY" />

<Button
android:id="@+id/button_clear"
android:layout_width="180dp"
android:layout_width="100dp"
android:layout_height="wrap_content"
android:text="ClEAR ALL" />

<Button
android:id="@+id/button_goto_showActivity"
android:layout_width="100dp"
android:layout_height="wrap_content"
android:text="NEW ACTIVITY" />
</LinearLayout>

<ListView
Expand Down
23 changes: 23 additions & 0 deletions app/src/main/res/layout/activity_show.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
tools:context=".ShowActivity">

<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">

<Button
android:id="@+id/button_goto_Main"
android:layout_width="100dp"
android:layout_height="wrap_content"
android:text="MAIN" />

</LinearLayout>

</LinearLayout>