+>>>>>>> ui-test
\ No newline at end of file
diff --git a/CityList b/CityList
new file mode 160000
index 00000000..88d855dc
--- /dev/null
+++ b/CityList
@@ -0,0 +1 @@
+Subproject commit 88d855dc67688a00ac925f63f52c9f06524a4802
diff --git a/app/build.gradle b/app/build.gradle
index f6c5007c..8904b57c 100644
--- a/app/build.gradle
+++ b/app/build.gradle
@@ -25,6 +25,7 @@ android {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
+ namespace 'com.example.citylist'
}
dependencies {
@@ -35,4 +36,6 @@ dependencies {
testImplementation 'junit:junit:4.13.2'
androidTestImplementation 'androidx.test.ext:junit:1.1.3'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0'
+ androidTestImplementation 'androidx.test:runner:1.4.0'
+ androidTestImplementation 'androidx.test:rules:1.4.0'
}
\ No newline at end of file
diff --git a/app/src/androidTest/java/com/example/citylist/MainActivityTest.java b/app/src/androidTest/java/com/example/citylist/MainActivityTest.java
new file mode 100644
index 00000000..53876461
--- /dev/null
+++ b/app/src/androidTest/java/com/example/citylist/MainActivityTest.java
@@ -0,0 +1,113 @@
+package com.example.citylist;
+
+import static androidx.test.espresso.Espresso.onData;
+import static androidx.test.espresso.action.ViewActions.click;
+import static androidx.test.espresso.assertion.ViewAssertions.doesNotExist;
+import static androidx.test.espresso.assertion.ViewAssertions.matches;
+import static androidx.test.espresso.matcher.ViewMatchers.isDisplayed;
+import static androidx.test.espresso.matcher.ViewMatchers.withId;
+import static androidx.test.espresso.matcher.ViewMatchers.withText;
+import static androidx.test.espresso.Espresso.onView;
+
+import static org.hamcrest.CoreMatchers.anything;
+
+import androidx.test.espresso.Espresso;
+import androidx.test.espresso.action.ViewActions;
+import androidx.test.ext.junit.rules.ActivityScenarioRule;
+import androidx.test.ext.junit.runners.AndroidJUnit4;
+import androidx.test.filters.LargeTest;
+
+import org.junit.Rule;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+
+@RunWith(AndroidJUnit4.class)
+@LargeTest
+public class MainActivityTest {
+
+ @Rule
+ public ActivityScenarioRule activityRule =
+ new ActivityScenarioRule<>(MainActivity.class);
+
+ @Test
+ public void testAppName() {
+ onView(withText("CityList")).check(matches(isDisplayed())); //Check the name on the screen
+ }
+
+ @Test
+ public void testAddCity(){
+ onView(withId(R.id.button_add)).perform(click()); //Click add button to add a city to the list
+ onView(withId(R.id.editText_name)).perform(ViewActions.typeText("Edmonton")); //Type a city name
+ onView(withId(R.id.button_confirm)).perform(click()); //Confirm the city name and add to the list
+ onView(withText("Edmonton")).check(matches(isDisplayed())); //Check the name on the screen
+ }
+
+ @Test
+ public void testClearCity(){
+ onView(withId(R.id.button_add)).perform(click()); //Click add button to add a city to the list
+ onView(withId(R.id.editText_name)).perform(ViewActions.typeText("Edmonton")); //Type a city name
+ onView(withId(R.id.button_confirm)).perform(click()); //Confirm the city name and add to the list
+ //Add another city to the list
+ onView(withId(R.id.button_add)).perform(click()); //Click add button to add a city to the list
+ onView(withId(R.id.editText_name)).perform(ViewActions.typeText("Toronto")); //Type a city name
+ onView(withId(R.id.button_confirm)).perform(click()); //Confirm the city name and add to the list
+ //Clear the list
+ onView(withId(R.id.button_clear)).perform(click());
+ onView(withText("Edmonton")).check(doesNotExist());
+
+ }
+ @Test
+ public void testListView(){
+ onView(withId(R.id.button_add)).perform(click()); //Click add button to add a city to the list
+ onView(withId(R.id.editText_name)).perform(ViewActions.typeText("Edmonton")); //Type a city name
+ onView(withId(R.id.button_confirm)).perform(click()); //Confirm the city name and add to the list
+
+ onData(anything()).inAdapterView(withId(R.id.city_list)).atPosition(0).
+ check(matches((withText("Edmonton")))); //Check the content on the list - no content in this case
+ }
+
+ @Test
+ public void testListViewClickAndBack(){
+ onView(withId(R.id.button_add)).perform(click()); //Click add button to add a city to the list
+ onView(withId(R.id.editText_name)).perform(ViewActions.typeText("Edmonton")); //Type a city name
+ onView(withId(R.id.button_confirm)).perform(click()); //Confirm the city name and add to the list
+
+ onData(anything()).inAdapterView(withId(R.id.city_list)).atPosition(0).perform(click()); //Check the content on the list - no content in this case
+ Espresso.pressBack(); //Back button
+ }
+
+ @Test
+ public void lab2test()
+ {
+ onView(withId(R.id.button_add)).perform(click()); //Click add button to add a city to the list
+ onView(withId(R.id.editText_name)).perform(ViewActions.typeText("Admonton")); //Type a city name
+ Espresso.pressBack();
+ onView(withId(R.id.button_confirm)).perform(click()); //Confirm the city name and add to the list
+
+ onView(withId(R.id.button_add)).perform(click()); //Click add button to add a city to the list
+ onView(withId(R.id.editText_name)).perform(ViewActions.typeText("Bdmonton")); //Type a city name
+ Espresso.pressBack();
+ onView(withId(R.id.button_confirm)).perform(click()); //Confirm the city name and add to the list
+
+ onView(withId(R.id.button_add)).perform(click()); //Click add button to add a city to the list
+ onView(withId(R.id.editText_name)).perform(ViewActions.typeText("Cdmonton")); //Type a city name
+ Espresso.pressBack();
+ onView(withId(R.id.button_confirm)).perform(click()); //Confirm the city name and add to the list
+
+ onView(withId(R.id.button_add)).perform(click()); //Click add button to add a city to the list
+ onView(withId(R.id.editText_name)).perform(ViewActions.typeText("Ddmonton")); //Type a city name
+ Espresso.pressBack();
+ onView(withId(R.id.button_confirm)).perform(click()); //Confirm the city name and add to the list
+
+ onData(anything()).inAdapterView(withId(R.id.city_list)).atPosition(3).perform(click());
+ //Second activity display hoise kina check koro
+ onView(withId(R.id.second)).check(matches(isDisplayed()));
+ //main activity er click kora city secondactivity er text view te gese kina
+ onView(withText("Ddmonton")).check(matches(isDisplayed()));
+ //back button e click krlam
+ onView(withId(R.id.button)).perform(click());
+ //main activity te fire ashlam kina
+ onView(withId(R.id.main)).check(matches(isDisplayed()));
+ }
+
+}
diff --git a/app/src/androidTest/java/com/example/citylist/ShowActivityTest.java b/app/src/androidTest/java/com/example/citylist/ShowActivityTest.java
new file mode 100644
index 00000000..f3aa57a6
--- /dev/null
+++ b/app/src/androidTest/java/com/example/citylist/ShowActivityTest.java
@@ -0,0 +1,12 @@
+package com.example.citylist;
+
+import static org.junit.Assert.*;
+
+import org.junit.runner.RunWith;
+import org.junit.runners.JUnit4;
+
+@RunWith(JUnit4.class)
+
+public class ShowActivityTest {
+
+}
\ No newline at end of file
diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml
index b15e6b3c..97a0eeca 100644
--- a/app/src/main/AndroidManifest.xml
+++ b/app/src/main/AndroidManifest.xml
@@ -1,6 +1,5 @@
-
+
+ android:theme="@style/Theme.CityList">
+
+ android:exported="true">
diff --git a/app/src/main/java/com/example/citylist/City.java b/app/src/main/java/com/example/citylist/City.java
index 4bec61ac..8615fe3b 100644
--- a/app/src/main/java/com/example/citylist/City.java
+++ b/app/src/main/java/com/example/citylist/City.java
@@ -1,6 +1,6 @@
package com.example.citylist;
-public class City {
+public class City implements Comparable{
private String city;
private String province;
@@ -16,4 +16,9 @@ String getCityName(){
String getProvinceName(){
return this.province;
}
-}
+
+ @Override
+ public int compareTo(City city) {
+ return this.city.compareTo(city.getCityName());
+ }
+}
\ No newline at end of file
diff --git a/app/src/main/java/com/example/citylist/CityList.java b/app/src/main/java/com/example/citylist/CityList.java
new file mode 100644
index 00000000..994e78e3
--- /dev/null
+++ b/app/src/main/java/com/example/citylist/CityList.java
@@ -0,0 +1,63 @@
+package com.example.citylist;
+
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.Comparator;
+import java.util.List;
+
+/**
+ * This is a class that keeps track of a list of city objects
+ */
+public class CityList {
+ private List cities = new ArrayList<>();
+
+ /**
+ * This adds a city to the list if that city does not exist
+ * @param city
+ * This is the city to add
+ */
+ public void add(City city) {
+ if (cities.contains(city)) {
+ throw new IllegalArgumentException();
+ }
+ cities.add(city);
+ }
+
+ /**
+ * This returns a sorted list of cities
+ * @return
+ * Return the sorted list of cities
+ */
+ public List getCities(int parameter) {
+ List cityList = cities;
+ if(parameter == 0)
+ {
+ Collections.sort(cityList);
+ }
+ else
+ {
+ Collections.sort(cityList, new Comparator() {
+ @Override
+ public int compare(City city, City t1) {
+ return city.getProvinceName().compareTo(t1.getProvinceName());
+ }
+ });
+ }
+ return cityList;
+ }
+
+ public void delete(City city)
+ {
+ if(!cities.contains(city))
+ {
+ throw new IllegalArgumentException();
+ }
+ cities.remove(city);
+ }
+ public int count()
+ {
+ return cities.size();
+ }
+}
+
+
diff --git a/app/src/main/java/com/example/citylist/CustomList.java b/app/src/main/java/com/example/citylist/CustomList.java
deleted file mode 100644
index 915c1bf8..00000000
--- a/app/src/main/java/com/example/citylist/CustomList.java
+++ /dev/null
@@ -1,44 +0,0 @@
-package com.example.citylist;
-
-import android.content.Context;
-import android.view.LayoutInflater;
-import android.view.View;
-import android.view.ViewGroup;
-import android.widget.ArrayAdapter;
-import android.widget.TextView;
-
-import androidx.annotation.NonNull;
-import androidx.annotation.Nullable;
-
-import java.util.ArrayList;
-
-public class CustomList extends ArrayAdapter {
-
- private ArrayList cities;
- private Context context;
-
- public CustomList(Context context, ArrayList cities){
- super(context, 0, cities);
- this.cities = cities;
- this.context = context;
- }
- @NonNull
- @Override
- public View getView(int position, @Nullable View convertView, @NonNull ViewGroup parent){
- View view = convertView;
-
- if(view == null){
- view = LayoutInflater.from(context).inflate(R.layout.content, parent, false);
- }
-
- City city = cities.get(position);
-
- TextView cityName = view.findViewById(R.id.city_text);
- TextView provinceName = view.findViewById(R.id.province_text);
-
- cityName.setText(city.getCityName());
- provinceName.setText(city.getProvinceName());
-
- return view;
- }
-}
diff --git a/app/src/main/java/com/example/citylist/MainActivity.java b/app/src/main/java/com/example/citylist/MainActivity.java
index 898aa6ec..1d4f3ac5 100644
--- a/app/src/main/java/com/example/citylist/MainActivity.java
+++ b/app/src/main/java/com/example/citylist/MainActivity.java
@@ -1,37 +1,75 @@
package com.example.citylist;
import androidx.appcompat.app.AppCompatActivity;
+
+import android.content.Intent;
import android.os.Bundle;
+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.ListView;
-
import java.util.ArrayList;
-import java.util.Arrays;
public class MainActivity extends AppCompatActivity {
// Declare the variables so that you will be able to reference it later.
ListView cityList;
- ArrayAdapter cityAdapter;
- ArrayList cityDataList;
+ EditText newName;
+ LinearLayout nameField;
+ ArrayAdapter cityAdapter;
+ ArrayList dataList;
+
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
+ nameField = findViewById(R.id.field_nameEntry);
+ newName = findViewById(R.id.editText_name);
+
cityList = findViewById(R.id.city_list);
+ dataList = new ArrayList<>();
+ cityAdapter = new ArrayAdapter<>(this, R.layout.content, dataList);
+ cityList.setAdapter(cityAdapter);
- String cities[] = {"Edmonton", "Vancouver", "Toronto", "Calgary", "Hamilton", "Waterloo" };
- String provinces[] = {"AB", "BC", "ON", "AB", "ON", "ON"};
+ final Button addButton = findViewById(R.id.button_add);
+ addButton.setOnClickListener(new View.OnClickListener() {
+ public void onClick(View v) {
+ nameField.setVisibility(View.VISIBLE);
+ }
+ });
- cityDataList = new ArrayList<>();
+ final Button confirmButton = findViewById(R.id.button_confirm);
+ confirmButton.setOnClickListener(new View.OnClickListener() {
+ public void onClick(View v) {
+ String cityName = newName.getText().toString();
+ cityAdapter.add(cityName);
+ newName.getText().clear();
+ nameField.setVisibility(View.INVISIBLE);
+ }
+ });
- for(int i=0; i adapterView, View view, int i, long l) {
+ Intent intent = new Intent(MainActivity.this, ShowActivity.class);
+ intent.putExtra("cityname", dataList.get(i));
+ startActivity(intent);
+ }
+ });
- cityList.setAdapter(cityAdapter);
}
+
+
}
\ No newline at end of file
diff --git a/app/src/main/java/com/example/citylist/ShowActivity.java b/app/src/main/java/com/example/citylist/ShowActivity.java
new file mode 100644
index 00000000..d236cb15
--- /dev/null
+++ b/app/src/main/java/com/example/citylist/ShowActivity.java
@@ -0,0 +1,33 @@
+package com.example.citylist;
+
+import androidx.appcompat.app.AppCompatActivity;
+
+import android.content.Intent;
+import android.os.Bundle;
+import android.view.View;
+import android.widget.Button;
+import android.widget.TextView;
+
+public class ShowActivity extends AppCompatActivity {
+
+ @Override
+ protected void onCreate(Bundle savedInstanceState) {
+ super.onCreate(savedInstanceState);
+ setContentView(R.layout.activity_show);
+ Intent intent= getIntent();
+ String s = intent.getStringExtra("cityname");
+ TextView textView = findViewById(R.id.textView);
+ textView.setText(s);
+
+ Button button=findViewById(R.id.button);
+
+ button.setOnClickListener(new View.OnClickListener() {
+ @Override
+ public void onClick(View view) {
+ Intent intent1 = new Intent(ShowActivity.this, MainActivity.class);
+ startActivity(intent1);
+ finish();
+ }
+ });
+ }
+}
\ No newline at end of file
diff --git a/app/src/main/res/layout/activity_main.xml b/app/src/main/res/layout/activity_main.xml
index 2af50fa9..0be43b84 100644
--- a/app/src/main/res/layout/activity_main.xml
+++ b/app/src/main/res/layout/activity_main.xml
@@ -2,16 +2,65 @@
+ android:orientation="vertical"
+ tools:context=".MainActivity"
+ android:id="@+id/main">
+
+
+
+
+
+
+
+ android:layout_height="wrap_content"
+ android:choiceMode="singleChoice"
+ android:listSelector="#999999">
-
\ No newline at end of file
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/app/src/main/res/layout/activity_show.xml b/app/src/main/res/layout/activity_show.xml
new file mode 100644
index 00000000..797e8fd8
--- /dev/null
+++ b/app/src/main/res/layout/activity_show.xml
@@ -0,0 +1,32 @@
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/app/src/main/res/layout/content.xml b/app/src/main/res/layout/content.xml
index 9ac3bbdd..aa747ed0 100644
--- a/app/src/main/res/layout/content.xml
+++ b/app/src/main/res/layout/content.xml
@@ -1,27 +1,10 @@
-
-
-
-
-
-
-
-
+ android:padding="20dp"
+ android:text="test"
+ android:textSize="40sp">
-
\ No newline at end of file
+
\ No newline at end of file
diff --git a/app/src/test/java/com/example/citylist/CityListTest.java b/app/src/test/java/com/example/citylist/CityListTest.java
new file mode 100644
index 00000000..41bb33c5
--- /dev/null
+++ b/app/src/test/java/com/example/citylist/CityListTest.java
@@ -0,0 +1,114 @@
+package com.example.citylist;
+
+import org.junit.Test;
+
+import static org.junit.Assert.*;
+
+public class CityListTest {
+ private CityList mockCityList() {
+ CityList cityList = new CityList();
+ cityList.add(mockCity());
+ return cityList;
+ }
+
+ private City mockCity() {
+ return new City("Edmonton", "AB");
+ }
+
+ @Test
+ public void testAdd() {
+ CityList cityList = mockCityList();
+ assertEquals(1, cityList.getCities(0).size());
+
+ City city = new City("Regina", "SK");
+ cityList.add(city);
+
+ assertEquals(2, cityList.getCities(0).size());
+ assertTrue(cityList.getCities(0).contains(city));
+ }
+
+ @Test
+ public void testDelete() {
+ CityList cityList = new CityList();
+ City city = new City("Jessore", "Khulna");
+ City city1 = new City("Chandpur", "Noakhali");
+
+ cityList.add(city);
+ cityList.add(city1);
+
+ cityList.delete(city);
+
+ assertTrue(!cityList.getCities(0).contains(city));
+ }
+ @Test
+ public void testAddException() {
+ CityList cityList = new CityList();
+ City city = mockCity();
+ cityList.add(city);
+
+ assertThrows(IllegalArgumentException.class, () -> {
+ cityList.add(city);
+ });
+ }
+
+
+
+ @Test
+ public void testDeleteException() {
+ CityList cityList = new CityList();
+ City city = new City("Jessore", "Khulna");
+ City city1 = new City("Chandpur", "Noakhali");
+
+ cityList.add(city);
+ cityList.add(city1);
+
+ cityList.delete(city);
+ assertThrows(IllegalArgumentException.class, () -> {
+ cityList.delete(city);
+ });
+ }
+
+ @Test
+ public void testCount(){
+ CityList cityList = new CityList();
+ City city = new City("Jessore", "Khulna");
+ City city1 = new City("Chandpur", "Noakhali");
+
+ cityList.add(city);
+ cityList.add(city1);
+ assertEquals(2, cityList.count());
+
+ cityList.delete(city);
+ assertEquals(1, cityList.count());
+
+ }
+
+ @Test
+ public void testGetCities() {
+ CityList cityList = mockCityList();
+ assertEquals(0, mockCity().compareTo(cityList.getCities(0).get(0)));
+
+ City city = new City("Charlottetown", "Prince Edward Island");
+ cityList.add(city);
+
+ assertEquals(0, city.compareTo(cityList.getCities(0).get(0)));
+ assertEquals(0, mockCity().compareTo(cityList.getCities(0).get(1)));
+ }
+
+ @Test
+ public void testSort() {
+ CityList cityList = new CityList();
+ City city = new City("Dhaka", "Bangshal");
+ cityList.add(city);
+ City city1 = new City("Kumilla", "Adabor");
+ cityList.add(city1);
+
+ assertEquals(0, city1.compareTo(cityList.getCities(1).get(0)));
+
+ assertEquals(0, city.compareTo(cityList.getCities(0).get(0)));
+
+
+ }
+
+
+}
diff --git a/build.gradle b/build.gradle
index 905d3bd2..4a0042b4 100644
--- a/build.gradle
+++ b/build.gradle
@@ -1,7 +1,7 @@
// Top-level build file where you can add configuration options common to all sub-projects/modules.
plugins {
- id 'com.android.application' version '7.1.3' apply false
- id 'com.android.library' version '7.1.3' apply false
+ id 'com.android.application' version '7.4.2' apply false
+ id 'com.android.library' version '7.4.2' apply false
}
task clean(type: Delete) {
diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties
index bc091ede..da4fbed4 100644
--- a/gradle/wrapper/gradle-wrapper.properties
+++ b/gradle/wrapper/gradle-wrapper.properties
@@ -1,6 +1,6 @@
#Mon May 02 15:40:26 BDT 2022
distributionBase=GRADLE_USER_HOME
-distributionUrl=https\://services.gradle.org/distributions/gradle-7.2-bin.zip
+distributionUrl=https\://services.gradle.org/distributions/gradle-7.5-bin.zip
distributionPath=wrapper/dists
zipStorePath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME