Skip to content

Commit

Permalink
Merge branch 'master' of https://github.com/dedis/popstellar into wor…
Browse files Browse the repository at this point in the history
…k-simone-feature-path-constants
  • Loading branch information
simone-kalbermatter committed Oct 29, 2023
2 parents 3a40d10 + f64f11a commit d062927
Show file tree
Hide file tree
Showing 7 changed files with 177 additions and 38 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -311,9 +311,9 @@ jobs:
- name: Lint with ruff
run: |
# stop the build if there are Python syntax errors or undefined names
ruff --format=github --select=E9,F63,F7,F82 --target-version=py39 .
ruff --output-format=github --select=E9,F63,F7,F82 --target-version=py39 .
# default set of ruff rules with GitHub Annotations
ruff --format=github --target-version=py39 .
ruff --output-format=github --target-version=py39 .
- name: Run tests
run: |
Expand Down
17 changes: 17 additions & 0 deletions .github/workflows/stats.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
name: Pull Request Stats

on:
pull_request:
types: [opened]

jobs:
stats:
runs-on: ubuntu-latest
steps:
- name: Run pull request stats
uses: flowwer-dev/pull-request-stats@master
with:
period: 30
charts: true
disableLinks: false
sortBy: 'REVIEWS'
Original file line number Diff line number Diff line change
Expand Up @@ -5,28 +5,36 @@
import androidx.test.core.app.ApplicationProvider;
import androidx.test.ext.junit.runners.AndroidJUnit4;

import com.github.dedis.popstellar.di.AppDatabaseModuleHelper;
import com.github.dedis.popstellar.model.objects.*;
import com.github.dedis.popstellar.model.objects.digitalcash.*;
import com.github.dedis.popstellar.model.objects.security.*;
import com.github.dedis.popstellar.repository.database.AppDatabase;
import com.github.dedis.popstellar.repository.database.digitalcash.HashDao;
import com.github.dedis.popstellar.repository.database.digitalcash.TransactionDao;
import com.github.dedis.popstellar.testutils.Base64DataUtils;
import com.github.dedis.popstellar.utility.error.keys.NoRollCallException;

import org.junit.*;
import org.junit.runner.RunWith;
import org.mockito.Mock;
import org.mockito.junit.MockitoJUnit;
import org.mockito.junit.MockitoRule;

import java.security.GeneralSecurityException;
import java.util.*;
import java.util.stream.Collectors;

import io.reactivex.Completable;
import io.reactivex.Single;
import io.reactivex.observers.TestObserver;

import static com.github.dedis.popstellar.testutils.Base64DataUtils.generatePublicKey;
import static com.github.dedis.popstellar.testutils.ObservableUtils.assertCurrentValueIs;
import static java.util.Collections.emptyList;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertThrows;
import static org.mockito.ArgumentMatchers.*;
import static org.mockito.Mockito.when;

@RunWith(AndroidJUnit4.class)
public class DigitalCashRepositoryTest {
Expand All @@ -40,17 +48,28 @@ public class DigitalCashRepositoryTest {
private static DigitalCashRepository repo;

private static final Application APPLICATION = ApplicationProvider.getApplicationContext();
private static AppDatabase appDatabase;
@Mock private static AppDatabase appDatabase;
@Mock private static TransactionDao transactionDao;
@Mock private static HashDao hashDao;

@Rule(order = 0)
public final MockitoRule mockitoRule = MockitoJUnit.rule();

@Before
public void initializeRepo() {
appDatabase = AppDatabaseModuleHelper.getAppDatabase(APPLICATION);
when(appDatabase.transactionDao()).thenReturn(transactionDao);
when(appDatabase.hashDao()).thenReturn(hashDao);
repo = new DigitalCashRepository(appDatabase, APPLICATION);
}

@After
public void tearDown() {
appDatabase.close();
// Mock the DAOs
when(hashDao.getDictionaryByLaoId(anyString()))
.thenReturn(Single.just(Collections.emptyList()));
when(hashDao.deleteByLaoId(anyString())).thenReturn(Completable.complete());
when(hashDao.insertAll(anyList())).thenReturn(Completable.complete());
when(transactionDao.getTransactionsByLaoId(anyString()))
.thenReturn(Single.just(Collections.emptyList()));
when(transactionDao.deleteByLaoId(anyString())).thenReturn(Completable.complete());
when(transactionDao.insert(any())).thenReturn(Completable.complete());
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,25 @@
import androidx.test.core.app.ApplicationProvider;
import androidx.test.ext.junit.runners.AndroidJUnit4;

import com.github.dedis.popstellar.di.AppDatabaseModuleHelper;
import com.github.dedis.popstellar.model.network.method.message.data.election.ElectionVersion;
import com.github.dedis.popstellar.model.objects.Election;
import com.github.dedis.popstellar.model.objects.Lao;
import com.github.dedis.popstellar.model.objects.event.EventState;
import com.github.dedis.popstellar.repository.database.AppDatabase;
import com.github.dedis.popstellar.repository.database.event.election.ElectionDao;
import com.github.dedis.popstellar.utility.error.UnknownElectionException;

import org.junit.*;
import org.junit.runner.RunWith;
import org.mockito.Mock;
import org.mockito.junit.MockitoJUnit;
import org.mockito.junit.MockitoRule;

import java.util.Collections;
import java.util.Set;

import io.reactivex.Completable;
import io.reactivex.Single;
import io.reactivex.observers.TestObserver;

import static com.github.dedis.popstellar.testutils.Base64DataUtils.generatePublicKey;
Expand All @@ -27,6 +33,9 @@
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.is;
import static org.junit.Assert.assertThrows;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.anyString;
import static org.mockito.Mockito.when;

@RunWith(AndroidJUnit4.class)
public class ElectionRepositoryTest {
Expand All @@ -37,18 +46,21 @@ public class ElectionRepositoryTest {
.setElectionVersion(ElectionVersion.OPEN_BALLOT)
.build();
private static final Application APPLICATION = ApplicationProvider.getApplicationContext();
private static AppDatabase appDatabase;
@Mock private static AppDatabase appDatabase;
@Mock private static ElectionDao electionDao;
private static ElectionRepository repo;

@Rule(order = 0)
public final MockitoRule mockitoRule = MockitoJUnit.rule();

@Before
public void setup() {
appDatabase = AppDatabaseModuleHelper.getAppDatabase(APPLICATION);
when(appDatabase.electionDao()).thenReturn(electionDao);
repo = new ElectionRepository(appDatabase, APPLICATION);
}

@After
public void tearDown() {
appDatabase.close();
when(electionDao.getElectionsByLaoId(anyString()))
.thenReturn(Single.just(Collections.emptyList()));
when(electionDao.insert(any())).thenReturn(Completable.complete());
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,25 +5,34 @@
import androidx.test.core.app.ApplicationProvider;
import androidx.test.ext.junit.runners.AndroidJUnit4;

import com.github.dedis.popstellar.di.AppDatabaseModuleHelper;
import com.github.dedis.popstellar.model.objects.Meeting;
import com.github.dedis.popstellar.repository.database.AppDatabase;
import com.github.dedis.popstellar.repository.database.event.meeting.MeetingDao;
import com.github.dedis.popstellar.utility.error.UnknownMeetingException;

import org.junit.*;
import org.junit.runner.RunWith;
import org.mockito.Mock;
import org.mockito.junit.MockitoJUnit;
import org.mockito.junit.MockitoRule;

import java.util.*;

import io.reactivex.Completable;
import io.reactivex.Single;
import io.reactivex.observers.TestObserver;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.anyString;
import static org.mockito.Mockito.when;

@RunWith(AndroidJUnit4.class)
public class MeetingRepositoryTest {
private static final Application APPLICATION = ApplicationProvider.getApplicationContext();
private static AppDatabase appDatabase;
@Mock private static AppDatabase appDatabase;
@Mock private static MeetingDao meetingDao;
private static MeetingRepository meetingRepository;
private static final String LAO_ID = "LAO_ID";
private static final String ID = "ID";
Expand All @@ -47,16 +56,18 @@ public class MeetingRepositoryTest {
MODIFICATION_ID,
MODIFICATION_SIGNATURES);

@Rule(order = 0)
public final MockitoRule mockitoRule = MockitoJUnit.rule();

@Before
public void setUp() {
appDatabase = AppDatabaseModuleHelper.getAppDatabase(APPLICATION);
when(appDatabase.meetingDao()).thenReturn(meetingDao);
meetingRepository = new MeetingRepository(appDatabase, APPLICATION);
meetingRepository.updateMeeting(LAO_ID, meeting);
}

@After
public void tearDown() {
appDatabase.close();
when(meetingDao.insert(any())).thenReturn(Completable.complete());
when(meetingDao.getMeetingsByLaoId(anyString()))
.thenReturn(Single.just(Collections.emptyList()));
meetingRepository.updateMeeting(LAO_ID, meeting);
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,33 +5,43 @@
import androidx.test.core.app.ApplicationProvider;
import androidx.test.ext.junit.runners.AndroidJUnit4;

import com.github.dedis.popstellar.di.AppDatabaseModuleHelper;
import com.github.dedis.popstellar.model.objects.*;
import com.github.dedis.popstellar.model.objects.security.MessageID;
import com.github.dedis.popstellar.model.objects.security.PublicKey;
import com.github.dedis.popstellar.repository.database.AppDatabase;
import com.github.dedis.popstellar.repository.database.socialmedia.ChirpDao;
import com.github.dedis.popstellar.repository.database.socialmedia.ReactionDao;
import com.github.dedis.popstellar.utility.error.UnknownChirpException;

import org.junit.*;
import org.junit.runner.RunWith;
import org.mockito.Mock;
import org.mockito.junit.MockitoJUnit;
import org.mockito.junit.MockitoRule;

import java.time.Instant;
import java.util.HashSet;
import java.util.Set;
import java.util.*;

import io.reactivex.Completable;
import io.reactivex.Single;
import io.reactivex.observers.TestObserver;

import static com.github.dedis.popstellar.testutils.Base64DataUtils.*;
import static com.github.dedis.popstellar.testutils.ObservableUtils.assertCurrentValueIs;
import static java.util.Collections.addAll;
import static java.util.Collections.emptySet;
import static org.junit.Assert.*;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.anyString;
import static org.mockito.Mockito.when;

@RunWith(AndroidJUnit4.class)
public class SocialMediaRepositoryTest {

private static final Application APPLICATION = ApplicationProvider.getApplicationContext();
private static AppDatabase appDatabase;
@Mock private static AppDatabase appDatabase;
@Mock private static ReactionDao reactionDao;
@Mock private static ChirpDao chirpDao;
private static final String LAO_ID = Lao.generateLaoId(generatePublicKey(), 1000, "LAO");

private static final PublicKey SENDER = generatePublicKey();
Expand All @@ -56,15 +66,19 @@ public class SocialMediaRepositoryTest {

private static SocialMediaRepository repo;

@Rule(order = 0)
public final MockitoRule mockitoRule = MockitoJUnit.rule();

@Before
public void setup() {
appDatabase = AppDatabaseModuleHelper.getAppDatabase(APPLICATION);
when(appDatabase.chirpDao()).thenReturn(chirpDao);
when(appDatabase.reactionDao()).thenReturn(reactionDao);
repo = new SocialMediaRepository(appDatabase, APPLICATION);
}

@After
public void tearDown() {
appDatabase.close();
when(chirpDao.insert(any())).thenReturn(Completable.complete());
when(reactionDao.insert(any())).thenReturn(Completable.complete());
when(chirpDao.getChirpsByLaoId(anyString())).thenReturn(Single.just(Collections.emptyList()));
when(reactionDao.getReactionsByChirpId(any())).thenReturn(Single.just(Collections.emptyList()));
}

@Test
Expand Down
Loading

0 comments on commit d062927

Please sign in to comment.