diff --git a/.idea/modules.xml b/.idea/modules.xml
index cc6a6c5..60baeb7 100644
--- a/.idea/modules.xml
+++ b/.idea/modules.xml
@@ -2,8 +2,8 @@
-
+
diff --git a/app/app.iml b/app/app.iml
index 048a830..46a2cb3 100644
--- a/app/app.iml
+++ b/app/app.iml
@@ -1,5 +1,5 @@
-
+
diff --git a/app/src/androidTest/java/org/hackafe/sunshine/data/TestDatabase.java b/app/src/androidTest/java/org/hackafe/sunshine/data/TestDatabase.java
index 979e4c5..0131d90 100644
--- a/app/src/androidTest/java/org/hackafe/sunshine/data/TestDatabase.java
+++ b/app/src/androidTest/java/org/hackafe/sunshine/data/TestDatabase.java
@@ -27,6 +27,10 @@ protected void setUp() throws Exception {
db = helper.getReadableDatabase();
}
+
+
+
+
public void _testDatabaseCanOpenWritableWhileOpenReadable() throws Exception {
new Thread(new Runnable() {
@@ -54,7 +58,7 @@ public void run() {
// TODO check that database can be opened for writing while there is open for reading and vice verse
}
- public void testHelperIsNotNull() throws Exception {
+ public void _testHelperIsNotNull() throws Exception {
assertNotNull(helper);
}
@@ -64,7 +68,7 @@ public void testDatabaseExists() throws Exception {
assertEquals(WeatherDbHelper.DATABASE_VERSION, db.getVersion());
}
- public void testSqlErrorProducesException() throws Exception {
+ public void _testSqlErrorProducesException() throws Exception {
try {
Cursor c = db.rawQuery("hackafe is the best", null);
fail("sql garbage does't produce exception!");
@@ -73,7 +77,7 @@ public void testSqlErrorProducesException() throws Exception {
}
}
- public void testTablesExists() throws Exception {
+ public void _testTablesExists() throws Exception {
Cursor c = db.rawQuery("select name from sqlite_master where type = 'table' ", null);
boolean found = false;
@@ -87,7 +91,7 @@ public void testTablesExists() throws Exception {
assertTrue("table forecast was not found!", found);
}
- public void testForecastHasAllColumn() throws Exception {
+ public void _testForecastHasAllColumn() throws Exception {
HashSet expectedColumn = new HashSet<>();
expectedColumn.add(WeatherContract.ForecastTable._ID);
expectedColumn.add(WeatherContract.ForecastTable.COLUMN_DATE);
@@ -105,7 +109,7 @@ public void testForecastHasAllColumn() throws Exception {
assertEquals(0, expectedColumn.size());
}
- public void testSaveNewForecast() throws Exception {
+ public void _testSaveNewForecast() throws Exception {
long timestamp = new Date().getTime();
String forecastStr = "sunny all day long with chance for pizza";
Forecast forecast = new Forecast(timestamp,
@@ -139,8 +143,63 @@ public void testSaveNewForecast() throws Exception {
assertEquals(timestamp, cursor.getLong(WeatherContract.ForecastTable.INDEX_DATE));
}
+
// TODO validate only one record per day (try to insert 2 for a single day)
+ public void testSqlInsertTwoRecordsForOneDay() throws Exception {
+ System.out.println("testSqlInsertTwoRecordsForOneDay");
+ long timestamp = new Date().getTime();
+ String forecastStr = "two records for one day test";
+ Forecast forecast = new Forecast(timestamp,
+ forecastStr);
+ //Insert First Record
+ System.out.println("Insert First Record");
+ helper.saveNewForecast(forecast);
+
+ //Insert Second Record
+ System.out.println("Insert Second Record");
+ helper.saveNewForecast(forecast);
+
+ Cursor cursor = db.query(
+ // table name
+ WeatherContract.ForecastTable.TABLE_NAME,
+ // select field
+ WeatherContract.ForecastTable.PROJECTION,
+ // where clause
+ WeatherContract.ForecastTable.COLUMN_DATE+" = ?",
+ // where argument
+ new String[]{Long.toString(timestamp)},
+ // group by
+ null,
+ // having
+ null,
+ // order by
+ null
+ );
+ System.out.println("Cursor rows: " + cursor.getCount());
+ // check for single record
+ assertEquals(2, cursor.getCount());
+
+
+ }
+
// TODO validate bad data
- // TODO validate we have a unique id for the inserted record
+ public void testTimeDataValid() throws Exception {
+ long timestamp = 0;
+ // timestamp= new Date().getTime();
+ assertNotNull(timestamp);
+ if (timestamp == 0){
+ fail();
+ }
+ }
+ public void testforecastStrValid() throws Exception {
+ String forecastStr = null;
+ // forecastStr = "sunny all day long with chance for pizza";
+
+ assertNotNull(forecastStr);
+
+
+ }
+ // TODO validate we have a unique id for the inserted record
+//???????????
}
diff --git a/app/src/main/java/org/hackafe/sunshine/data/WeatherDbHelper.java b/app/src/main/java/org/hackafe/sunshine/data/WeatherDbHelper.java
index 15d3697..bf056fd 100644
--- a/app/src/main/java/org/hackafe/sunshine/data/WeatherDbHelper.java
+++ b/app/src/main/java/org/hackafe/sunshine/data/WeatherDbHelper.java
@@ -13,7 +13,7 @@
public class WeatherDbHelper extends SQLiteOpenHelper {
private static final String DATABASE_NAME = "weather.db";
- static final int DATABASE_VERSION = 4;
+ static final int DATABASE_VERSION = 8;
public WeatherDbHelper(Context context) {
super(context, DATABASE_NAME, null, DATABASE_VERSION);
@@ -21,16 +21,20 @@ public WeatherDbHelper(Context context) {
@Override
public void onCreate(SQLiteDatabase db) {
- db.execSQL("DROP TABLE IF EXISTS forecast;");
+ System.out.println("onCreate");
+ System.out.println("Drop");
+ db.execSQL("DROP TABLE IF EXISTS forecasts;");
+ System.out.println("Create");
db.execSQL("CREATE TABLE \"forecasts\" (\n" +
"\"_id\" INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL,\n" +
"weather TEXT NOT NULL," +
- "fordate INTEGER NOT NULL" +
- ");\n");
+ "fordate INTEGER NOT NULL, " +
+ " UNIQUE(fordate) ON CONFLICT IGNORE);\n");
}
@Override
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
+ System.out.println("onUpgrade");
onCreate(db);
}
diff --git a/android-fundamentals-course.iml b/hw6-0419.iml
similarity index 100%
rename from android-fundamentals-course.iml
rename to hw6-0419.iml
diff --git a/ulorm0p3.bfd.txt b/ulorm0p3.bfd.txt
new file mode 100644
index 0000000..2b86a3c
--- /dev/null
+++ b/ulorm0p3.bfd.txt
@@ -0,0 +1,17 @@
+
+# Please enter the commit message for your changes. Lines starting
+# with '#' will be ignored, and an empty message aborts the commit.
+# On branch hw6.0419
+# Your branch is up-to-date with 'upstream/lesson6-sqlite'.
+#
+# Changes to be committed:
+# modified: .idea/modules.xml
+# modified: app/app.iml
+# modified: app/src/androidTest/java/org/hackafe/sunshine/data/TestDatabase.java
+# modified: app/src/main/java/org/hackafe/sunshine/data/WeatherDbHelper.java
+# new file: hw6-0419.iml
+#
+# Changes not staged for commit:
+# deleted: android-fundamentals-course.iml
+#
+