// Path: app/src/main/java/org/secuso/privacyfriendlyweather/database/data/City.java
// @Entity(tableName = "CITIES", indices = {@Index(value = {"city_name", "cities_id"})})
// public class City {
// 
//     private static final String UNKNOWN_POSTAL_CODE_VALUE = "-";
// 
//     @PrimaryKey @ColumnInfo(name = "cities_id") private int cityId;
//     @ColumnInfo(name = "city_name") @NonNull private String cityName = "";
//     @ColumnInfo(name = "country_code") @NonNull private String countryCode = "";
//     @ColumnInfo(name = "longitude") private float longitude;
//     @ColumnInfo(name = "latitude") private float latitude;
// 
//     public City() { }
// 
//     @Ignore public City(int cityId, @NonNull String cityName, @NonNull String countryCode, float lon, float lat) {
//         this.cityId = cityId;
//         this.cityName = cityName;
//         this.countryCode = countryCode;
//         this.longitude = lon;
//         this.latitude = lat;
//     }
// 
//     public int getCityId() {
//         return cityId;
//     }
// 
//     public void setCityId(int cityId) {
//         this.cityId = cityId;
//     }
// 
//     public @NonNull String getCityName() {
//         return cityName;
//     }
// 
//     public void setCityName(@NonNull String cityName) {
//         this.cityName = cityName;
//     }
// 
//     public @NonNull String getCountryCode() {
//         return countryCode;
//     }
// 
//     public void setCountryCode(@NonNull String countryCode) {
//         this.countryCode = countryCode;
//     }
// 
//     @Override
//     public @NonNull String toString() {
//         return String.format(Locale.ENGLISH, "%s, %s (%f - %f)", cityName, countryCode, longitude, latitude);
//     }
// 
//     public void setLatitude(float latitude) {
//         this.latitude = latitude;
//     }
// 
//     public float getLatitude() {
//         return latitude;
//     }
// 
//     public float getLongitude() {
//         return longitude;
//     }
// 
//     public void setLongitude(float lon) {
//         this.longitude = lon;
//     }
// }
// 
// Path: app/src/main/java/org/secuso/privacyfriendlyweather/database/AppDatabase.java
// public static final String DB_NAME = "PF_WEATHER_DB.db";


import android.content.Context;
import androidx.room.Room;
import androidx.room.testing.MigrationTestHelper;
import androidx.sqlite.db.framework.FrameworkSQLiteOpenHelperFactory;
import androidx.test.ext.junit.runners.AndroidJUnit4;
import androidx.test.platform.app.InstrumentationRegistry;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.secuso.privacyfriendlyweather.BuildConfig;
import org.secuso.privacyfriendlyweather.database.data.City;
import java.io.IOException;
import java.util.Arrays;
import java.util.List;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
import static org.secuso.privacyfriendlyweather.database.AppDatabase.DB_NAME;
        // migration
        testHelper.runMigrationsAndValidate("PF_WEATHER_DB_4.db", AppDatabase.VERSION, true, AppDatabase.getMigrations(appContext));

        AppDatabase appDatabase = Room.databaseBuilder(appContext, AppDatabase.class, "PF_WEATHER_DB_4.db").build();
        // close the database and release any stream resources when the test finishes
        testHelper.closeWhenFinished(appDatabase);

        assertNotNull(appDatabase.cityToWatchDao().getAll());
        assertNotNull(appDatabase.forecastDao().getAll());
        assertNotNull(appDatabase.currentWeatherDao().getAll());
        assertEquals(209579, appDatabase.cityDao().count()); // make sure all the cities are written correctly

    }




    @Test
    public void testRecommendationsTest() {
        AppDatabase appDatabase = getMigratedRoomDatabase();

        // are all the cities in the database?
        assertEquals(209579, appDatabase.cityDao().count());

        // get recommendations
        List<City> possibleCities = appDatabase.cityDao().getCitiesWhereNameLike("Frankfurt", 10);
        assertEquals(5, possibleCities.size());

        List<String> possibleCityNames = Arrays.asList("Frankfurt am Main", "Frankfurt (Oder)", "Frankfurt Main Flughafen", "Frankfurter Vorstadt");

// Path: app/src/main/java/org/secuso/privacyfriendlyweather/database/data/City.java
// @Entity(tableName = "CITIES", indices = {@Index(value = {"city_name", "cities_id"})})
// public class City {
// 
//     private static final String UNKNOWN_POSTAL_CODE_VALUE = "-";
// 
//     @PrimaryKey @ColumnInfo(name = "cities_id") private int cityId;
//     @ColumnInfo(name = "city_name") @NonNull private String cityName = "";
//     @ColumnInfo(name = "country_code") @NonNull private String countryCode = "";
//     @ColumnInfo(name = "longitude") private float longitude;
//     @ColumnInfo(name = "latitude") private float latitude;
// 
//     public City() { }
// 
//     @Ignore public City(int cityId, @NonNull String cityName, @NonNull String countryCode, float lon, float lat) {
//         this.cityId = cityId;
//         this.cityName = cityName;
//         this.countryCode = countryCode;
//         this.longitude = lon;
//         this.latitude = lat;
//     }
// 
//     public int getCityId() {
//         return cityId;
//     }
// 
//     public void setCityId(int cityId) {
//         this.cityId = cityId;
//     }
// 
//     public @NonNull String getCityName() {
//         return cityName;
//     }
// 
//     public void setCityName(@NonNull String cityName) {
//         this.cityName = cityName;
//     }
// 
//     public @NonNull String getCountryCode() {
//         return countryCode;
//     }
// 
//     public void setCountryCode(@NonNull String countryCode) {
//         this.countryCode = countryCode;
//     }
// 
//     @Override
//     public @NonNull String toString() {
//         return String.format(Locale.ENGLISH, "%s, %s (%f - %f)", cityName, countryCode, longitude, latitude);
//     }
// 
//     public void setLatitude(float latitude) {
//         this.latitude = latitude;
//     }
// 
//     public float getLatitude() {
//         return latitude;
//     }
// 
//     public float getLongitude() {
//         return longitude;
//     }
// 
//     public void setLongitude(float lon) {
//         this.longitude = lon;
//     }
// }
// 
// Path: app/src/main/java/org/secuso/privacyfriendlyweather/database/AppDatabase.java
// public static final String DB_NAME = "PF_WEATHER_DB.db";


// Path: app/src/androidTest/java/org/secuso/privacyfriendlyweather/database/DatabaseTest.java
import android.content.Context;
import androidx.room.Room;
import androidx.room.testing.MigrationTestHelper;
import androidx.sqlite.db.framework.FrameworkSQLiteOpenHelperFactory;
import androidx.test.ext.junit.runners.AndroidJUnit4;
import androidx.test.platform.app.InstrumentationRegistry;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.secuso.privacyfriendlyweather.BuildConfig;
import org.secuso.privacyfriendlyweather.database.data.City;
import java.io.IOException;
import java.util.Arrays;
import java.util.List;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
import static org.secuso.privacyfriendlyweather.database.AppDatabase.DB_NAME;

        // migration
        testHelper.runMigrationsAndValidate("PF_WEATHER_DB_4.db", AppDatabase.VERSION, true, AppDatabase.getMigrations(appContext));

        AppDatabase appDatabase = Room.databaseBuilder(appContext, AppDatabase.class, "PF_WEATHER_DB_4.db").build();
        // close the database and release any stream resources when the test finishes
        testHelper.closeWhenFinished(appDatabase);

        assertNotNull(appDatabase.cityToWatchDao().getAll());
        assertNotNull(appDatabase.forecastDao().getAll());
        assertNotNull(appDatabase.currentWeatherDao().getAll());
        assertEquals(209579, appDatabase.cityDao().count()); // make sure all the cities are written correctly

    }




    @Test
    public void testRecommendationsTest() {
        AppDatabase appDatabase = getMigratedRoomDatabase();

        // are all the cities in the database?
        assertEquals(209579, appDatabase.cityDao().count());

        // get recommendations
        List<City> possibleCities = appDatabase.cityDao().getCitiesWhereNameLike("Frankfurt", 10);
        assertEquals(5, possibleCities.size());

        List<String> possibleCityNames = Arrays.asList("Frankfurt am Main", "Frankfurt (Oder)", "Frankfurt Main Flughafen", "Frankfurter Vorstadt");

        for (City c : possibleCities) {