diff --git a/app/build.gradle b/app/build.gradle index d78e4767..dae964b6 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -6,11 +6,13 @@ android { defaultConfig { applicationId "privacyfriendlyshoppinglist.secuso.org.privacyfriendlyshoppinglist" - minSdkVersion 17 + minSdkVersion 19 targetSdkVersion 33 versionCode 8 versionName "1.1" multiDexEnabled true + + testInstrumentationRunner 'androidx.test.runner.AndroidJUnitRunner' } buildTypes { @@ -77,7 +79,8 @@ dependencies { testImplementation 'junit:junit:4.12' testImplementation 'org.mockito:mockito-core:2.7.6' androidTestImplementation 'androidx.test.ext:junit:1.2.1' - androidTestImplementation 'androidx.test:rules:1.5.1' + androidTestImplementation 'androidx.test:rules:1.6.1' + androidTestImplementation 'androidx.test:core:1.6.1' androidTestImplementation 'com.android.support.test.espresso:espresso-contrib:3.0.2' testImplementation 'pl.pragmatists:JUnitParams:0.3.6' // dependency injection diff --git a/app/src/androidTest/java/privacyfriendlyshoppinglist/secuso/org/privacyfriendlyshoppinglist/AbstractDatabaseTest.java b/app/src/androidTest/java/privacyfriendlyshoppinglist/secuso/org/privacyfriendlyshoppinglist/AbstractDatabaseTest.java index b0b2e6e4..468e912c 100644 --- a/app/src/androidTest/java/privacyfriendlyshoppinglist/secuso/org/privacyfriendlyshoppinglist/AbstractDatabaseTest.java +++ b/app/src/androidTest/java/privacyfriendlyshoppinglist/secuso/org/privacyfriendlyshoppinglist/AbstractDatabaseTest.java @@ -1,8 +1,12 @@ package privacyfriendlyshoppinglist.secuso.org.privacyfriendlyshoppinglist; -import android.support.test.runner.AndroidJUnit4; -import android.test.AndroidTestCase; +import androidx.test.ext.junit.runners.AndroidJUnit4; +import androidx.test.platform.app.InstrumentationRegistry; + +import org.junit.After; +import org.junit.Before; import org.junit.runner.RunWith; + import privacyfriendlyshoppinglist.secuso.org.privacyfriendlyshoppinglist.framework.persistence.DB; /** @@ -11,24 +15,22 @@ * Created: 31.05.16 creation date */ @RunWith(AndroidJUnit4.class) -abstract public class AbstractDatabaseTest extends AndroidTestCase -{ +abstract public class AbstractDatabaseTest { - protected void setUp() throws Exception - { - super.setUp(); + @Before + public void setUp() throws Exception { // delete database before each test - getContext().deleteDatabase(DB.TEST.getDbName()); + InstrumentationRegistry.getInstrumentation().getContext().deleteDatabase(DB.TEST.getDbName()); setupBeforeEachTest(); } - protected void tearDown() throws Exception - { - super.tearDown(); + @After + public void tearDown() throws Exception { cleanAfterEachTest(); } abstract protected void setupBeforeEachTest(); - protected void cleanAfterEachTest(){} + protected void cleanAfterEachTest() { + } } diff --git a/app/src/androidTest/java/privacyfriendlyshoppinglist/secuso/org/privacyfriendlyshoppinglist/ApplicationTest.java b/app/src/androidTest/java/privacyfriendlyshoppinglist/secuso/org/privacyfriendlyshoppinglist/ApplicationTest.java index 1422994b..032a31f8 100644 --- a/app/src/androidTest/java/privacyfriendlyshoppinglist/secuso/org/privacyfriendlyshoppinglist/ApplicationTest.java +++ b/app/src/androidTest/java/privacyfriendlyshoppinglist/secuso/org/privacyfriendlyshoppinglist/ApplicationTest.java @@ -1,15 +1,26 @@ package privacyfriendlyshoppinglist.secuso.org.privacyfriendlyshoppinglist; -import android.app.Application; -import android.test.ApplicationTestCase; +import static org.junit.Assert.assertEquals; + +import androidx.test.core.app.ApplicationProvider; +import androidx.test.ext.junit.runners.AndroidJUnit4; +import androidx.test.platform.app.InstrumentationRegistry; + +import org.junit.Test; +import org.junit.runner.RunWith; /** * Testing Fundamentals */ -public class ApplicationTest extends ApplicationTestCase -{ - public ApplicationTest() - { - super(Application.class); +@RunWith(AndroidJUnit4.class) +public class ApplicationTest { + @Test + public void useApplicationContext() { + assertEquals("privacyfriendlyshoppinglist.secuso.org.privacyfriendlyshoppinglist", ApplicationProvider.getApplicationContext().getPackageName()); + } + + @Test + public void useContext() { + assertEquals("privacyfriendlyshoppinglist.secuso.org.privacyfriendlyshoppinglist.test", InstrumentationRegistry.getInstrumentation().getContext().getPackageName()); } } \ No newline at end of file diff --git a/app/src/androidTest/java/privacyfriendlyshoppinglist/secuso/org/privacyfriendlyshoppinglist/MainActivityBasicTest.kt b/app/src/androidTest/java/privacyfriendlyshoppinglist/secuso/org/privacyfriendlyshoppinglist/MainActivityBasicTest.kt new file mode 100644 index 00000000..30f9685e --- /dev/null +++ b/app/src/androidTest/java/privacyfriendlyshoppinglist/secuso/org/privacyfriendlyshoppinglist/MainActivityBasicTest.kt @@ -0,0 +1,26 @@ +package privacyfriendlyshoppinglist.secuso.org.privacyfriendlyshoppinglist + +import androidx.test.espresso.Espresso.onView +import androidx.test.espresso.action.ViewActions.click +import androidx.test.espresso.matcher.ViewMatchers.withContentDescription +import androidx.test.ext.junit.rules.ActivityScenarioRule +import androidx.test.ext.junit.runners.AndroidJUnit4 +import org.junit.Rule +import org.junit.Test +import org.junit.runner.RunWith +import privacyfriendlyshoppinglist.secuso.org.privacyfriendlyshoppinglist.ui.main.MainActivity + +@RunWith(AndroidJUnit4::class) +class MainActivityBasicTest { + @get: Rule + var mActivityRule = ActivityScenarioRule(MainActivity::class.java) + + @Test + fun launchActivity() { + } + + @Test + fun openDrawer() { + onView(withContentDescription(R.string.navigation_drawer_open)).perform(click()) + } +} \ No newline at end of file diff --git a/app/src/androidTest/java/privacyfriendlyshoppinglist/secuso/org/privacyfriendlyshoppinglist/logic/product/business/ProductServiceTest.java b/app/src/androidTest/java/privacyfriendlyshoppinglist/secuso/org/privacyfriendlyshoppinglist/logic/product/business/ProductServiceTest.java index 9658d29f..9d748a59 100644 --- a/app/src/androidTest/java/privacyfriendlyshoppinglist/secuso/org/privacyfriendlyshoppinglist/logic/product/business/ProductServiceTest.java +++ b/app/src/androidTest/java/privacyfriendlyshoppinglist/secuso/org/privacyfriendlyshoppinglist/logic/product/business/ProductServiceTest.java @@ -1,8 +1,19 @@ package privacyfriendlyshoppinglist.secuso.org.privacyfriendlyshoppinglist.logic.product.business; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertNull; + import android.content.res.Resources; + +import androidx.test.platform.app.InstrumentationRegistry; + import org.joda.time.DateTime; import org.junit.Test; + +import java.util.Arrays; +import java.util.List; + import privacyfriendlyshoppinglist.secuso.org.privacyfriendlyshoppinglist.AbstractDatabaseTest; import privacyfriendlyshoppinglist.secuso.org.privacyfriendlyshoppinglist.R; import privacyfriendlyshoppinglist.secuso.org.privacyfriendlyshoppinglist.framework.context.AbstractInstanceFactory; @@ -13,16 +24,12 @@ import privacyfriendlyshoppinglist.secuso.org.privacyfriendlyshoppinglist.logic.shoppingList.business.ShoppingListService; import privacyfriendlyshoppinglist.secuso.org.privacyfriendlyshoppinglist.logic.shoppingList.business.domain.ListItem; -import java.util.Arrays; -import java.util.List; - /** * Description: * Author: Grebiel Jose Ifill Brito * Created: 17.07.16 creation date */ -public class ProductServiceTest extends AbstractDatabaseTest -{ +public class ProductServiceTest extends AbstractDatabaseTest { private ProductService productService; private ShoppingListService shoppingListService; @@ -33,14 +40,13 @@ public class ProductServiceTest extends AbstractDatabaseTest private String language; @Override - protected void setupBeforeEachTest() - { - AbstractInstanceFactory instanceFactory = new InstanceFactoryForTests(getContext()); + protected void setupBeforeEachTest() { + AbstractInstanceFactory instanceFactory = new InstanceFactoryForTests(InstrumentationRegistry.getInstrumentation().getContext()); productService = (ProductService) instanceFactory.createInstance(ProductService.class); shoppingListService = (ShoppingListService) instanceFactory.createInstance(ShoppingListService.class); productItemDao = (ProductItemDao) instanceFactory.createInstance(ProductItemDao.class); - Resources resources = getContext().getResources(); + Resources resources = InstrumentationRegistry.getInstrumentation().getContext().getResources(); shortDatePattern = resources.getString(R.string.date_short_pattern); timePattern = resources.getString(R.string.time_pattern); language = resources.getString(R.string.language); @@ -67,8 +73,7 @@ protected void setupBeforeEachTest() } @Test - public void testSaveProductItem() - { + public void testSaveProductItem() { ProductItem item = getDefaultItem(); productService.saveOrUpdate(item, listId).toBlocking().single(); @@ -77,8 +82,7 @@ public void testSaveProductItem() } @Test - public void testGetById() - { + public void testGetById() { ProductItem item = getDefaultItem(); productService.saveOrUpdate(item, listId).toBlocking().single(); @@ -87,8 +91,7 @@ public void testGetById() } @Test - public void testDeleteById() - { + public void testDeleteById() { ProductItem item = getDefaultItem(); productService.saveOrUpdate(item, listId).toBlocking().single(); @@ -99,8 +102,7 @@ public void testDeleteById() } @Test - public void testDeleteSelected() - { + public void testDeleteSelected() { ProductItem item1 = getDefaultItem(); item1.setSelectedForDeletion(false); productService.saveOrUpdate(item1, listId).toBlocking().single(); @@ -121,8 +123,7 @@ public void testDeleteSelected() } @Test - public void testGetAllProducts() - { + public void testGetAllProducts() { ProductItem item1 = getDefaultItem(); productService.saveOrUpdate(item1, listId).toBlocking().single(); @@ -140,8 +141,7 @@ public void testGetAllProducts() } @Test - public void testMoveSelectedToEnd() - { + public void testMoveSelectedToEnd() { ProductItem item1 = getDefaultItem(); item1.setChecked(true); ProductItem item2 = getDefaultItem(); @@ -154,8 +154,7 @@ public void testMoveSelectedToEnd() } @Test - public void testDeleteProductsWhenListIsDeleted() - { + public void testDeleteProductsWhenListIsDeleted() { ProductItem item1 = getDefaultItem(); item1.setId(null); item1.setId(null); @@ -177,8 +176,7 @@ public void testDeleteProductsWhenListIsDeleted() } - private ProductItem getDefaultItem() - { + private ProductItem getDefaultItem() { String expectedProductId = "1"; String expectedQuantity = "5"; String expectedNotes = "Some Notes"; diff --git a/app/src/androidTest/java/privacyfriendlyshoppinglist/secuso/org/privacyfriendlyshoppinglist/logic/product/business/impl/converter/ProductConverterServiceTest.java b/app/src/androidTest/java/privacyfriendlyshoppinglist/secuso/org/privacyfriendlyshoppinglist/logic/product/business/impl/converter/ProductConverterServiceTest.java index 513e0d8b..bd7f33bb 100644 --- a/app/src/androidTest/java/privacyfriendlyshoppinglist/secuso/org/privacyfriendlyshoppinglist/logic/product/business/impl/converter/ProductConverterServiceTest.java +++ b/app/src/androidTest/java/privacyfriendlyshoppinglist/secuso/org/privacyfriendlyshoppinglist/logic/product/business/impl/converter/ProductConverterServiceTest.java @@ -1,6 +1,12 @@ package privacyfriendlyshoppinglist.secuso.org.privacyfriendlyshoppinglist.logic.product.business.impl.converter; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; + +import androidx.test.platform.app.InstrumentationRegistry; + import org.junit.Test; + import privacyfriendlyshoppinglist.secuso.org.privacyfriendlyshoppinglist.AbstractDatabaseTest; import privacyfriendlyshoppinglist.secuso.org.privacyfriendlyshoppinglist.framework.context.AbstractInstanceFactory; import privacyfriendlyshoppinglist.secuso.org.privacyfriendlyshoppinglist.framework.context.InstanceFactoryForTests; @@ -12,20 +18,17 @@ * Author: Grebiel Jose Ifill Brito * Created: 17.07.16 creation date */ -public class ProductConverterServiceTest extends AbstractDatabaseTest -{ +public class ProductConverterServiceTest extends AbstractDatabaseTest { private ProductConverterService converterService; @Override - protected void setupBeforeEachTest() - { - AbstractInstanceFactory instanceFactory = new InstanceFactoryForTests(getContext()); + protected void setupBeforeEachTest() { + AbstractInstanceFactory instanceFactory = new InstanceFactoryForTests(InstrumentationRegistry.getInstrumentation().getContext()); converterService = (ProductConverterService) instanceFactory.createInstance(ProductConverterService.class); } @Test - public void testConvertItemToEntity() throws Exception - { + public void testConvertItemToEntity() throws Exception { String expectedProductId = "1"; String expectedQuantity = "5"; String expectedNotes = "Some Notes"; @@ -52,8 +55,7 @@ public void testConvertItemToEntity() throws Exception } @Test - public void testConvertEntitiesToItem() throws Exception - { + public void testConvertEntitiesToItem() throws Exception { String expectedProductName = "product"; String expectedCategory = "category"; diff --git a/app/src/androidTest/java/privacyfriendlyshoppinglist/secuso/org/privacyfriendlyshoppinglist/logic/product/persistence/ProductItemDaoTest.java b/app/src/androidTest/java/privacyfriendlyshoppinglist/secuso/org/privacyfriendlyshoppinglist/logic/product/persistence/ProductItemDaoTest.java index a8eb9ea4..68f963f0 100644 --- a/app/src/androidTest/java/privacyfriendlyshoppinglist/secuso/org/privacyfriendlyshoppinglist/logic/product/persistence/ProductItemDaoTest.java +++ b/app/src/androidTest/java/privacyfriendlyshoppinglist/secuso/org/privacyfriendlyshoppinglist/logic/product/persistence/ProductItemDaoTest.java @@ -1,7 +1,14 @@ package privacyfriendlyshoppinglist.secuso.org.privacyfriendlyshoppinglist.logic.product.persistence; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; + +import androidx.test.platform.app.InstrumentationRegistry; + import com.j256.ormlite.dao.ForeignCollection; + import org.junit.Test; + import privacyfriendlyshoppinglist.secuso.org.privacyfriendlyshoppinglist.AbstractDatabaseTest; import privacyfriendlyshoppinglist.secuso.org.privacyfriendlyshoppinglist.framework.context.AbstractInstanceFactory; import privacyfriendlyshoppinglist.secuso.org.privacyfriendlyshoppinglist.framework.context.InstanceFactoryForTests; @@ -14,8 +21,7 @@ * Author: Grebiel Jose Ifill Brito * Created: 11.06.16 creation date */ -public class ProductItemDaoTest extends AbstractDatabaseTest -{ +public class ProductItemDaoTest extends AbstractDatabaseTest { private ShoppingListDao shoppingListDao; private ProductItemDao productItemDao; @@ -23,9 +29,8 @@ public class ProductItemDaoTest extends AbstractDatabaseTest @Override - protected void setupBeforeEachTest() - { - AbstractInstanceFactory instanceFactory = new InstanceFactoryForTests(getContext()); + protected void setupBeforeEachTest() { + AbstractInstanceFactory instanceFactory = new InstanceFactoryForTests(InstrumentationRegistry.getInstrumentation().getContext()); shoppingListDao = (ShoppingListDao) instanceFactory.createInstance(ShoppingListDao.class); productItemDao = (ProductItemDao) instanceFactory.createInstance(ProductItemDao.class); @@ -37,8 +42,7 @@ protected void setupBeforeEachTest() } @Test - public void testSave() - { + public void testSave() { ProductItemEntity entity = new ProductItemEntity(); entity.setShoppingList(shoppingList); @@ -53,8 +57,7 @@ public void testSave() } @Test(expected = Exception.class) - public void testSaveWithoutProductTemplate() - { + public void testSaveWithoutProductTemplate() { ProductItemEntity entity = new ProductItemEntity(); entity.setShoppingList(shoppingList); @@ -62,8 +65,7 @@ public void testSaveWithoutProductTemplate() } @Test(expected = Exception.class) - public void testSaveWithoutShoppingList() - { + public void testSaveWithoutShoppingList() { ProductItemEntity entity = new ProductItemEntity(); productItemDao.save(entity); } diff --git a/app/src/androidTest/java/privacyfriendlyshoppinglist/secuso/org/privacyfriendlyshoppinglist/logic/shoppingList/business/ShoppingListServiceTest.java b/app/src/androidTest/java/privacyfriendlyshoppinglist/secuso/org/privacyfriendlyshoppinglist/logic/shoppingList/business/ShoppingListServiceTest.java index 65f9b793..bd557e6c 100644 --- a/app/src/androidTest/java/privacyfriendlyshoppinglist/secuso/org/privacyfriendlyshoppinglist/logic/shoppingList/business/ShoppingListServiceTest.java +++ b/app/src/androidTest/java/privacyfriendlyshoppinglist/secuso/org/privacyfriendlyshoppinglist/logic/shoppingList/business/ShoppingListServiceTest.java @@ -1,5 +1,10 @@ package privacyfriendlyshoppinglist.secuso.org.privacyfriendlyshoppinglist.logic.shoppingList.business; +import static androidx.test.InstrumentationRegistry.getContext; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; + import android.content.res.Resources; import org.joda.time.DateTime; import org.junit.Test; diff --git a/app/src/androidTest/java/privacyfriendlyshoppinglist/secuso/org/privacyfriendlyshoppinglist/logic/shoppingList/persistence/ShoppingListDaoTest.java b/app/src/androidTest/java/privacyfriendlyshoppinglist/secuso/org/privacyfriendlyshoppinglist/logic/shoppingList/persistence/ShoppingListDaoTest.java index 71fdb227..354c1025 100644 --- a/app/src/androidTest/java/privacyfriendlyshoppinglist/secuso/org/privacyfriendlyshoppinglist/logic/shoppingList/persistence/ShoppingListDaoTest.java +++ b/app/src/androidTest/java/privacyfriendlyshoppinglist/secuso/org/privacyfriendlyshoppinglist/logic/shoppingList/persistence/ShoppingListDaoTest.java @@ -1,34 +1,37 @@ package privacyfriendlyshoppinglist.secuso.org.privacyfriendlyshoppinglist.logic.shoppingList.persistence; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; + +import androidx.test.platform.app.InstrumentationRegistry; + import org.joda.time.DateTime; import org.junit.Test; + +import java.util.Date; +import java.util.List; + import privacyfriendlyshoppinglist.secuso.org.privacyfriendlyshoppinglist.AbstractDatabaseTest; import privacyfriendlyshoppinglist.secuso.org.privacyfriendlyshoppinglist.framework.context.AbstractInstanceFactory; import privacyfriendlyshoppinglist.secuso.org.privacyfriendlyshoppinglist.framework.context.InstanceFactoryForTests; import privacyfriendlyshoppinglist.secuso.org.privacyfriendlyshoppinglist.logic.shoppingList.persistence.entity.ShoppingListEntity; -import java.util.Date; -import java.util.List; - /** * Description: * Author: Grebiel Jose Ifill Brito * Created: 10.06.16 creation date */ -public class ShoppingListDaoTest extends AbstractDatabaseTest -{ +public class ShoppingListDaoTest extends AbstractDatabaseTest { private ShoppingListDao shoppingListDao; @Override - protected void setupBeforeEachTest() - { - AbstractInstanceFactory instanceFactory = new InstanceFactoryForTests(getContext()); + protected void setupBeforeEachTest() { + AbstractInstanceFactory instanceFactory = new InstanceFactoryForTests(InstrumentationRegistry.getInstrumentation().getContext()); shoppingListDao = (ShoppingListDao) instanceFactory.createInstance(ShoppingListDao.class); } @Test - public void testSave() - { + public void testSave() { ShoppingListEntity entity = new ShoppingListEntity(); entity.setListName("name"); entity.setPriority("HIGH"); @@ -41,8 +44,7 @@ public void testSave() } @Test - public void testGetById() - { + public void testGetById() { String expectedName = "name"; String expectedPriority = "HIGH"; String expectedNotes = "notes"; @@ -67,8 +69,7 @@ public void testGetById() } @Test - public void testGetAllEntities() - { + public void testGetAllEntities() { ShoppingListEntity entity1 = new ShoppingListEntity(); ShoppingListEntity entity2 = new ShoppingListEntity(); entity1.setListName("entity1"); @@ -83,8 +84,7 @@ public void testGetAllEntities() } @Test - public void testDeleteById() - { + public void testDeleteById() { ShoppingListEntity entity1 = new ShoppingListEntity(); ShoppingListEntity entity2 = new ShoppingListEntity(); entity1.setListName("entity1"); diff --git a/app/src/androidTest/java/privacyfriendlyshoppinglist/secuso/org/privacyfriendlyshoppinglist/logic/statistics/persistence/StatisticsDaoTest.java b/app/src/androidTest/java/privacyfriendlyshoppinglist/secuso/org/privacyfriendlyshoppinglist/logic/statistics/persistence/StatisticsDaoTest.java index defc897a..60d0dbdf 100644 --- a/app/src/androidTest/java/privacyfriendlyshoppinglist/secuso/org/privacyfriendlyshoppinglist/logic/statistics/persistence/StatisticsDaoTest.java +++ b/app/src/androidTest/java/privacyfriendlyshoppinglist/secuso/org/privacyfriendlyshoppinglist/logic/statistics/persistence/StatisticsDaoTest.java @@ -1,5 +1,10 @@ package privacyfriendlyshoppinglist.secuso.org.privacyfriendlyshoppinglist.logic.statistics.persistence; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; + +import androidx.test.platform.app.InstrumentationRegistry; + import org.joda.time.DateTime; import org.junit.Test; import privacyfriendlyshoppinglist.secuso.org.privacyfriendlyshoppinglist.AbstractDatabaseTest; @@ -22,7 +27,7 @@ public class StatisticsDaoTest extends AbstractDatabaseTest @Override protected void setupBeforeEachTest() { - AbstractInstanceFactory instanceFactory = new InstanceFactoryForTests(getContext()); + AbstractInstanceFactory instanceFactory = new InstanceFactoryForTests(InstrumentationRegistry.getInstrumentation().getContext()); statisticsDao = (StatisticsDao) instanceFactory.createInstance(StatisticsDao.class); } diff --git a/build.gradle b/build.gradle index 46b473a2..a13bea72 100644 --- a/build.gradle +++ b/build.gradle @@ -2,7 +2,6 @@ buildscript { repositories { - jcenter() mavenCentral() google() } @@ -20,7 +19,6 @@ buildscript { allprojects { repositories { - jcenter() mavenCentral() google() maven { url "https://jitpack.io" }