Skip to content
26 changes: 26 additions & 0 deletions .github/workflows/android.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
name: Android CI

on:
push:
branches: [ master ]
pull_request:
branches: [ master ]

jobs:
build:

runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v2
- name: set up JDK 11
uses: actions/setup-java@v2
with:
java-version: '11'
distribution: 'temurin'
cache: gradle

- name: Grant execute permission for gradlew
run: chmod +x gradlew
- name: Build with Gradle
run: ./gradlew build
2 changes: 1 addition & 1 deletion app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,4 @@ dependencies {
testImplementation 'junit:junit:4.12'
androidTestImplementation 'androidx.test:runner:1.1.1'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.1.1'
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ public class City {
private String city;
private String province;

City(String city, String province){
public City(String city, String province){
this.city = city;
this.province = province;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@


package com.example.simpleparadox.listycity;

import android.content.Context;
Expand All @@ -10,8 +12,6 @@
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;

import org.w3c.dom.Text;

import java.util.ArrayList;

public class CustomList extends ArrayAdapter<City> {
Expand Down Expand Up @@ -47,4 +47,45 @@ public View getView(int position, @Nullable View convertView, @NonNull ViewGroup
return view;

}

/**
* this function gets the size of the list
* @return
*/

public int getCount() {
return cities.size();
}

/**
* this function would add a city object to the list.
*/

public void addCity(City city) {

cities.add(city);
return;

}

public boolean hasCity(City city) {

if (cities.contains(city)) {

return true;
}
return false;
}

public boolean deleteCity(City city) {

cities.remove(city);

return !hasCity(city);
}

public int countCities() {

return cities.size();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
package com.example.simpleparadox.tests;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;

import com.example.simpleparadox.listycity.City;
import com.example.simpleparadox.listycity.CustomList;

import org.junit.Before;
import org.junit.Test;

import java.util.ArrayList;

public class customListTest {

private CustomList customList;

@Before
public void createList() {
customList= new CustomList(null, new ArrayList<City>());
}

@Test
public void addCityTest() {
int listSize = customList.getCount();
customList.addCity(new City("Halifax" , "NS"));

assertEquals(customList.getCount(), listSize + 1);
}


@Test
public void hasCityTest() {

City city = new City("Edmonton", "AB");

customList.addCity(city);

assertTrue(customList.hasCity(city));
}

@Test
public void deleteCityTest() {

City city = new City("Edmonton", "AB");

customList.addCity(city);

assertTrue(customList.deleteCity(city));
}

@Test
public void countCities() {

customList.addCity(new City("Edmonton", "AB"));

assertEquals(customList.countCities(), 1);
}

}