Skip to content

Commit

Permalink
Merge pull request #120 from SecUSo/add-workflows
Browse files Browse the repository at this point in the history
Add workflows and fix lint errors
  • Loading branch information
udenr authored Dec 9, 2024
2 parents 5b6f0b2 + 684d6ef commit 6387001
Show file tree
Hide file tree
Showing 30 changed files with 1,679 additions and 1,431 deletions.
3 changes: 2 additions & 1 deletion .github/workflows/changelog.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ name: Changelog Generation

on:
release:
types: [published, released]
types: [published]
workflow_dispatch:

jobs:
Expand All @@ -16,6 +16,7 @@ jobs:
- uses: rhysd/changelog-from-release/action@v3
with:
file: CHANGELOG.md
pull_request: true
github_token: ${{ secrets.GITHUB_TOKEN }}
commit_summary_template: 'update changelog for %s changes'
args: -l 2
Expand Down
67 changes: 67 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
name: Continuous Integration
on: [push, pull_request]

jobs:
test:
runs-on: ubuntu-20.04
steps:
- name: Checkout
uses: actions/checkout@v3
with:
submodules: "recursive"

- name: Set up JDK environment
uses: actions/setup-java@v3
with:
distribution: "zulu"
java-version: 17

- name: Make gradlew executable
run: chmod +x ./gradlew

- name: Setup Gradle
uses: gradle/gradle-build-action@v2

- name: Run local unit tests
run: bash ./gradlew test --stacktrace

build:
runs-on: ubuntu-20.04
steps:
- name: Checkout
uses: actions/checkout@v3
with:
submodules: "recursive"

- name: Set up JDK environment
uses: actions/setup-java@v3
with:
distribution: "zulu"
java-version: 17

- name: Make gradlew executable
run: chmod +x ./gradlew

- name: Setup Gradle
uses: gradle/gradle-build-action@v2

- name: Run lint check
run: bash ./gradlew lint

- name: Upload lint result
uses: actions/upload-artifact@v4
with:
name: lint-results-debug
path: app/build/reports/lint-results-debug.html

- name: Build the app
run: bash ./gradlew build --stacktrace

- name: Build debug apk
run: bash ./gradlew assembleDebug

- name: Upload debug apk
uses: actions/upload-artifact@v4
with:
name: debug-apk
path: app/build/outputs/apk/debug/*.apk
13 changes: 10 additions & 3 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -53,6 +55,9 @@ android {
]
}
}
lint {
lintConfig = file("lint.xml")
}
}

android.applicationVariants.all { variant ->
Expand All @@ -76,8 +81,10 @@ dependencies {
// tests
testImplementation 'junit:junit:4.12'
testImplementation 'org.mockito:mockito-core:2.7.6'
androidTestImplementation 'androidx.test.ext:junit:1.1.1'
androidTestImplementation 'androidx.test:rules:1.1.1'
androidTestImplementation 'androidx.test.ext:junit:1.2.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
implementation 'com.squareup.dagger:dagger:1.2.5'
Expand Down
11 changes: 11 additions & 0 deletions app/lint.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<?xml version="1.0" encoding="UTF-8"?>
<lint>
<!-- Disable the NotificationPermission check for glide -->
<issue id="NotificationPermission">
<ignore regexp="com.bumptech.glide.request.target.NotificationTarget" />
</issue>

<!-- Set the severity of missing translations to warning instead of error -->
<issue id="MissingTranslation" severity="warning" />
<issue id="MissingQuantity" severity="warning" />
</lint>
Original file line number Diff line number Diff line change
@@ -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;

/**
Expand All @@ -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() {
}
}
Original file line number Diff line number Diff line change
@@ -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;

/**
* <a href="http://d.android.com/tools/testing/testing_android.html">Testing Fundamentals</a>
*/
public class ApplicationTest extends ApplicationTestCase<Application>
{
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());
}
}
Original file line number Diff line number Diff line change
@@ -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())
}
}
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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;
Expand All @@ -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);
Expand All @@ -67,8 +73,7 @@ protected void setupBeforeEachTest()
}

@Test
public void testSaveProductItem()
{
public void testSaveProductItem() {
ProductItem item = getDefaultItem();

productService.saveOrUpdate(item, listId).toBlocking().single();
Expand All @@ -77,8 +82,7 @@ public void testSaveProductItem()
}

@Test
public void testGetById()
{
public void testGetById() {
ProductItem item = getDefaultItem();
productService.saveOrUpdate(item, listId).toBlocking().single();

Expand All @@ -87,8 +91,7 @@ public void testGetById()
}

@Test
public void testDeleteById()
{
public void testDeleteById() {
ProductItem item = getDefaultItem();
productService.saveOrUpdate(item, listId).toBlocking().single();

Expand All @@ -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();
Expand All @@ -121,8 +123,7 @@ public void testDeleteSelected()
}

@Test
public void testGetAllProducts()
{
public void testGetAllProducts() {
ProductItem item1 = getDefaultItem();
productService.saveOrUpdate(item1, listId).toBlocking().single();

Expand All @@ -140,8 +141,7 @@ public void testGetAllProducts()
}

@Test
public void testMoveSelectedToEnd()
{
public void testMoveSelectedToEnd() {
ProductItem item1 = getDefaultItem();
item1.setChecked(true);
ProductItem item2 = getDefaultItem();
Expand All @@ -154,8 +154,7 @@ public void testMoveSelectedToEnd()
}

@Test
public void testDeleteProductsWhenListIsDeleted()
{
public void testDeleteProductsWhenListIsDeleted() {
ProductItem item1 = getDefaultItem();
item1.setId(null);
item1.setId(null);
Expand All @@ -177,8 +176,7 @@ public void testDeleteProductsWhenListIsDeleted()
}


private ProductItem getDefaultItem()
{
private ProductItem getDefaultItem() {
String expectedProductId = "1";
String expectedQuantity = "5";
String expectedNotes = "Some Notes";
Expand Down
Loading

0 comments on commit 6387001

Please sign in to comment.