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

Master #23

Open
wants to merge 13 commits into
base: main
Choose a base branch
from
65 changes: 65 additions & 0 deletions .idea/androidTestResultsUserPreferences.xml

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

2 changes: 1 addition & 1 deletion .idea/compiler.xml

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

8 changes: 1 addition & 7 deletions .idea/gradle.xml

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

9 changes: 8 additions & 1 deletion .idea/misc.xml

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

1 change: 1 addition & 0 deletions CityList
Submodule CityList added at 88d855
3 changes: 3 additions & 0 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ android {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
namespace 'com.example.citylist'
}

dependencies {
Expand All @@ -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'
}
113 changes: 113 additions & 0 deletions app/src/androidTest/java/com/example/citylist/MainActivityTest.java
Original file line number Diff line number Diff line change
@@ -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<MainActivity> 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()));
}

}
Original file line number Diff line number Diff line change
@@ -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 {

}
10 changes: 6 additions & 4 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -1,17 +1,19 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.citylist" >
<manifest xmlns:android="http://schemas.android.com/apk/res/android">

<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/Theme.CityList" >
android:theme="@style/Theme.CityList">
<activity
android:name=".ShowActivity"
android:exported="false" />
<activity
android:name=".MainActivity"
android:exported="true" >
android:exported="true">
<intent-filter>
<action android:name="android.intent.action.MAIN" />

Expand Down
9 changes: 7 additions & 2 deletions app/src/main/java/com/example/citylist/City.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package com.example.citylist;

public class City {
public class City implements Comparable<City>{
private String city;
private String province;

Expand All @@ -16,4 +16,9 @@ String getCityName(){
String getProvinceName(){
return this.province;
}
}

@Override
public int compareTo(City city) {
return this.city.compareTo(city.getCityName());
}
}
63 changes: 63 additions & 0 deletions app/src/main/java/com/example/citylist/CityList.java
Original file line number Diff line number Diff line change
@@ -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<City> 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<City> getCities(int parameter) {
List<City> cityList = cities;
if(parameter == 0)
{
Collections.sort(cityList);
}
else
{
Collections.sort(cityList, new Comparator<City>() {
@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();
}
}


Loading