From d3aeb9b9bf61a7cdb8f727edcb88551f66e0771c Mon Sep 17 00:00:00 2001 From: Niko Strijbol Date: Thu, 30 Nov 2023 19:52:27 +0100 Subject: [PATCH] Remove some tests that don't work --- .../ugent/zeus/hydra/info/InfoItemTest.java | 53 --- .../ugent/zeus/hydra/library/LibraryTest.java | 50 --- .../details/OpeningHoursRequestTest.java | 74 ---- .../library/favourites/FavouriteDaoTest.java | 135 ------- .../library/list/LibraryViewHolderTest.java | 82 ----- .../zeus/hydra/news/NewsArticleTest.java | 44 --- .../ugent/zeus/hydra/resto/RestoMealTest.java | 34 -- .../ugent/zeus/hydra/resto/RestoMenuTest.java | 34 -- .../zeus/hydra/resto/menu/MenuFilterTest.java | 137 -------- .../regular/RegularViewHolderTest.java | 91 ----- .../schamper/SchamperViewHolderTest.java | 67 ---- app/src/test/resources/libraries.sql | 5 - app/src/test/resources/library_hours.json | 332 ------------------ 13 files changed, 1138 deletions(-) delete mode 100644 app/src/test/java/be/ugent/zeus/hydra/info/InfoItemTest.java delete mode 100644 app/src/test/java/be/ugent/zeus/hydra/library/LibraryTest.java delete mode 100644 app/src/test/java/be/ugent/zeus/hydra/library/details/OpeningHoursRequestTest.java delete mode 100644 app/src/test/java/be/ugent/zeus/hydra/library/favourites/FavouriteDaoTest.java delete mode 100644 app/src/test/java/be/ugent/zeus/hydra/library/list/LibraryViewHolderTest.java delete mode 100644 app/src/test/java/be/ugent/zeus/hydra/news/NewsArticleTest.java delete mode 100644 app/src/test/java/be/ugent/zeus/hydra/resto/RestoMealTest.java delete mode 100644 app/src/test/java/be/ugent/zeus/hydra/resto/RestoMenuTest.java delete mode 100644 app/src/test/java/be/ugent/zeus/hydra/resto/menu/MenuFilterTest.java delete mode 100644 app/src/test/java/be/ugent/zeus/hydra/resto/sandwich/regular/RegularViewHolderTest.java delete mode 100644 app/src/test/java/be/ugent/zeus/hydra/schamper/SchamperViewHolderTest.java delete mode 100644 app/src/test/resources/libraries.sql delete mode 100644 app/src/test/resources/library_hours.json diff --git a/app/src/test/java/be/ugent/zeus/hydra/info/InfoItemTest.java b/app/src/test/java/be/ugent/zeus/hydra/info/InfoItemTest.java deleted file mode 100644 index b2d12ff6b..000000000 --- a/app/src/test/java/be/ugent/zeus/hydra/info/InfoItemTest.java +++ /dev/null @@ -1,53 +0,0 @@ -/* - * Copyright (c) 2021 The Hydra authors - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ - -package be.ugent.zeus.hydra.info; - -import be.ugent.zeus.hydra.testing.Utils; -import org.junit.Test; - -import static be.ugent.zeus.hydra.testing.Assert.assertRecordParcelable; -import static be.ugent.zeus.hydra.testing.Utils.generate; -import static org.junit.Assert.assertEquals; - -/** - * @author Niko Strijbol - */ -public class InfoItemTest { - - @Test - public void parcelable() { - assertRecordParcelable(Utils.generate(InfoItem.class)); - } - - @Test - public void getType() { - InfoItem infoItem = generate(InfoItem.class, "urlAndroid", "html", "subContent"); - assertEquals(InfoType.EXTERNAL_LINK, infoItem.getType()); - InfoItem infoItem1 = generate(InfoItem.class, "url", "html", "subContent"); - assertEquals(InfoType.EXTERNAL_APP, infoItem1.getType()); - InfoItem infoItem2 = generate(InfoItem.class, "url", "urlAndroid", "subContent"); - assertEquals(InfoType.INTERNAL, infoItem2.getType()); - InfoItem infoItem3 = generate(InfoItem.class, "url", "urlAndroid", "html"); - assertEquals(InfoType.SUBLIST, infoItem3.getType()); - } -} \ No newline at end of file diff --git a/app/src/test/java/be/ugent/zeus/hydra/library/LibraryTest.java b/app/src/test/java/be/ugent/zeus/hydra/library/LibraryTest.java deleted file mode 100644 index 7e0592bd1..000000000 --- a/app/src/test/java/be/ugent/zeus/hydra/library/LibraryTest.java +++ /dev/null @@ -1,50 +0,0 @@ -/* - * Copyright (c) 2021 The Hydra authors - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ - -package be.ugent.zeus.hydra.library; - -import be.ugent.zeus.hydra.testing.Utils; -import org.junit.Test; - -import static be.ugent.zeus.hydra.testing.Assert.assertRecordParcelable; -import static be.ugent.zeus.hydra.testing.Utils.generate; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertTrue; - -/** - * @author Niko Strijbol - */ -public class LibraryTest { - - @Test - public void parcelable() { - assertRecordParcelable(Utils.generate(Library.class)); - } - - @Test - public void hasTelephone() { - Library full = generate(Library.class); - assertTrue(full.hasTelephone()); - Library empty = full.withTelephone(null); - assertFalse(empty.hasTelephone()); - } -} \ No newline at end of file diff --git a/app/src/test/java/be/ugent/zeus/hydra/library/details/OpeningHoursRequestTest.java b/app/src/test/java/be/ugent/zeus/hydra/library/details/OpeningHoursRequestTest.java deleted file mode 100644 index 08a23b9b4..000000000 --- a/app/src/test/java/be/ugent/zeus/hydra/library/details/OpeningHoursRequestTest.java +++ /dev/null @@ -1,74 +0,0 @@ -/* - * Copyright (c) 2021 The Hydra authors - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ - -package be.ugent.zeus.hydra.library.details; - -import java.io.IOException; -import java.util.List; - -import be.ugent.zeus.hydra.common.network.AbstractJsonRequestTest; -import be.ugent.zeus.hydra.library.Library; -import be.ugent.zeus.hydra.library.list.LibraryList; -import com.squareup.moshi.JsonAdapter; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.robolectric.RobolectricTestRunner; - -import static org.hamcrest.MatcherAssert.assertThat; -import static org.hamcrest.Matchers.endsWith; -import static org.junit.Assert.assertNotNull; - -/** - * @author Niko Strijbol - */ -@RunWith(RobolectricTestRunner.class) -public class OpeningHoursRequestTest extends AbstractJsonRequestTest> { - - @Override - protected String getRelativePath() { - return "library_hours.json"; - } - - @Override - protected OpeningHoursRequest getRequest() { - try { - return new OpeningHoursRequest(context, getRandomConstLibrary()); - } catch (IOException e) { - throw new RuntimeException(e); - } - } - - @Test - public void testLibraryCode() throws IOException { - Library library = getRandomConstLibrary(); - OpeningHoursRequest request = getRequest(); - assertThat(request.apiUrl(), endsWith("libraries/" + library.code() + "/calendar.json")); - } - - private Library getRandomConstLibrary() throws IOException { - JsonAdapter listAdapter = moshi.adapter(LibraryList.class); - LibraryList list = listAdapter.fromJson(readData(getResourceFile("all_libraries.json"))); - assertNotNull(list); - assertNotNull(list.libraries()); - return list.libraries().get(0); - } -} \ No newline at end of file diff --git a/app/src/test/java/be/ugent/zeus/hydra/library/favourites/FavouriteDaoTest.java b/app/src/test/java/be/ugent/zeus/hydra/library/favourites/FavouriteDaoTest.java deleted file mode 100644 index f0b5e2836..000000000 --- a/app/src/test/java/be/ugent/zeus/hydra/library/favourites/FavouriteDaoTest.java +++ /dev/null @@ -1,135 +0,0 @@ -/* - * Copyright (c) 2021 The Hydra authors - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ - -package be.ugent.zeus.hydra.library.favourites; - -import android.content.Context; -import android.util.Pair; -import androidx.annotation.RequiresApi; -import androidx.arch.core.executor.testing.InstantTaskExecutorRule; -import androidx.room.Room; -import androidx.test.core.app.ApplicationProvider; -import androidx.test.ext.junit.runners.AndroidJUnit4; - -import java.io.File; -import java.io.IOException; -import java.nio.file.Files; -import java.util.ArrayList; -import java.util.List; -import java.util.stream.Collectors; - -import be.ugent.zeus.hydra.TestApp; -import be.ugent.zeus.hydra.common.database.Database; -import be.ugent.zeus.hydra.feed.cards.dismissal.DismissalDao; -import be.ugent.zeus.hydra.library.Library; -import be.ugent.zeus.hydra.testing.Utils; -import org.junit.*; -import org.junit.runner.RunWith; -import org.robolectric.annotation.Config; -import org.robolectric.annotation.LooperMode; - -import static be.ugent.zeus.hydra.testing.Utils.generate; -import static be.ugent.zeus.hydra.testing.Utils.getRandom; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertTrue; - -/** - * Tests for the {@link DismissalDao}. - * - * @author Niko Strijbol - */ -// Request an older version of Android, since the SQLite version in Robolectric does not follow Android releases. -@RequiresApi(api = 26) -@RunWith(AndroidJUnit4.class) -@LooperMode(LooperMode.Mode.PAUSED) -@Config(application = TestApp.class) -public class FavouriteDaoTest { - - @Rule - public InstantTaskExecutorRule executorRule = new InstantTaskExecutorRule(); - - private Database database; - private FavouriteRepository favouritesDao; - private List> libraries; - - @Before - public void setUp() throws IOException { - Context context = ApplicationProvider.getApplicationContext(); - database = Room.inMemoryDatabaseBuilder(context, Database.class) - .allowMainThreadQueries() - .build(); - fillData(); - favouritesDao = database.getFavouriteRepository(); - } - - @After - public void tearDown() { - database.clearAllTables(); - database.close(); - } - - private void fillData() throws IOException { - libraries = new ArrayList<>(); - var rawData = generate(Library.class, 5).toList(); - for (int i = 0; i < rawData.size(); i++) { - Library library = rawData.get(i) - .withCode("test" + i) - .withName("Lib" + i); - libraries.add(Pair.create(library, true)); - } - - File sql = Utils.getResourceFile("libraries.sql"); - List inserts = Files.readAllLines(sql.toPath()); - database.runInTransaction(() -> inserts.forEach(s -> database.compileStatement(s).execute())); - - assertEquals("Error during data loading.", libraries.size(), inserts.size()); - } - - @Test - public void shouldDelete_WhenDeleting() { - Library deletable = getRandom(libraries).first; - favouritesDao.delete(deletable); - assertFalse(favouritesDao.getFavouriteIds().contains(deletable.code())); - } - - @Test - public void shouldInsert_WhenInsertingNew() { - Library library = generate(Library.class); - favouritesDao.insert(library); - - assertTrue(favouritesDao.getFavouriteIds().contains(library.code())); - } - - @Test - public void shouldOverwrite_WhenInsertingExisting() { - Library library = getRandom(libraries).first; - String old = library.name(); - var newLib = library.withName("New2"); - favouritesDao.insert(newLib); - - assertFalse(favouritesDao.getAll().stream() - .map(LibraryFavourite::getName).collect(Collectors.toList()).contains(old)); - assertTrue(favouritesDao.getAll().stream() - .map(LibraryFavourite::getName).collect(Collectors.toList()).contains("New2")); - } -} \ No newline at end of file diff --git a/app/src/test/java/be/ugent/zeus/hydra/library/list/LibraryViewHolderTest.java b/app/src/test/java/be/ugent/zeus/hydra/library/list/LibraryViewHolderTest.java deleted file mode 100644 index 701e14336..000000000 --- a/app/src/test/java/be/ugent/zeus/hydra/library/list/LibraryViewHolderTest.java +++ /dev/null @@ -1,82 +0,0 @@ -/* - * Copyright (c) 2021 The Hydra authors - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ - -package be.ugent.zeus.hydra.library.list; - -import android.content.Intent; -import android.util.Pair; -import android.view.View; - -import be.ugent.zeus.hydra.R; -import be.ugent.zeus.hydra.library.Library; -import be.ugent.zeus.hydra.library.details.LibraryDetailActivity; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.robolectric.RobolectricTestRunner; - -import static be.ugent.zeus.hydra.testing.RobolectricUtils.assertTextIs; -import static be.ugent.zeus.hydra.testing.RobolectricUtils.getShadowApplication; -import static be.ugent.zeus.hydra.testing.RobolectricUtils.inflate; -import static be.ugent.zeus.hydra.testing.Utils.generate; -import static org.junit.Assert.assertEquals; -import static org.mockito.Mockito.mock; - -/** - * @author Niko Strijbol - */ -@RunWith(RobolectricTestRunner.class) -public class LibraryViewHolderTest { - - @Test - public void populate() { - View view = inflate(R.layout.item_library); - Library library = generate(Library.class); - LibraryListAdapter adapter = mock(LibraryListAdapter.class); - LibraryViewHolder viewHolder = new LibraryViewHolder(view, adapter); - viewHolder.populate(Pair.create(library, true)); - - assertTextIs(library.name(), view.findViewById(R.id.title)); - assertTextIs(library.campus(), view.findViewById(R.id.subtitle)); - - view.performClick(); - - Intent expected = new Intent(view.getContext(), LibraryDetailActivity.class); - Intent actual = getShadowApplication().getNextStartedActivity(); - - assertEquals(expected.getComponent(), actual.getComponent()); - assertEquals(library, actual.getParcelableExtra(LibraryDetailActivity.ARG_LIBRARY, Library.class)); - } - - @Test - public void populateFavourite() { - View view = inflate(R.layout.item_library); - Library library = generate(Library.class); - LibraryListAdapter adapter = mock(LibraryListAdapter.class); - LibraryViewHolder viewHolder = new LibraryViewHolder(view, adapter); - - viewHolder.populate(Pair.create(library, true)); - assertEquals(view.findViewById(R.id.library_favourite_image).getVisibility(), View.VISIBLE); - - viewHolder.populate(Pair.create(library, false)); - assertEquals(view.findViewById(R.id.library_favourite_image).getVisibility(), View.GONE); - } -} \ No newline at end of file diff --git a/app/src/test/java/be/ugent/zeus/hydra/news/NewsArticleTest.java b/app/src/test/java/be/ugent/zeus/hydra/news/NewsArticleTest.java deleted file mode 100644 index 8e1c35cb3..000000000 --- a/app/src/test/java/be/ugent/zeus/hydra/news/NewsArticleTest.java +++ /dev/null @@ -1,44 +0,0 @@ -/* - * Copyright (c) 2021 The Hydra authors - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ - -package be.ugent.zeus.hydra.news; - -import be.ugent.zeus.hydra.common.ModelTest; -import be.ugent.zeus.hydra.testing.Utils; -import org.junit.Test; - -/** - * @author Niko Strijbol - */ -public class NewsArticleTest extends ModelTest { - public NewsArticleTest() { - super(NewsArticle.class); - } - - @Test - public void equalsAndHash() { - Utils.defaultVerifier(NewsArticle.class) - .withNonnullFields("id") - .withOnlyTheseFields("id") - .verify(); - } -} \ No newline at end of file diff --git a/app/src/test/java/be/ugent/zeus/hydra/resto/RestoMealTest.java b/app/src/test/java/be/ugent/zeus/hydra/resto/RestoMealTest.java deleted file mode 100644 index 83045e441..000000000 --- a/app/src/test/java/be/ugent/zeus/hydra/resto/RestoMealTest.java +++ /dev/null @@ -1,34 +0,0 @@ -/* - * Copyright (c) 2021 The Hydra authors - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ - -package be.ugent.zeus.hydra.resto; - -import be.ugent.zeus.hydra.common.ModelTest; - -/** - * @author Niko Strijbol - */ -public class RestoMealTest extends ModelTest { - public RestoMealTest() { - super(RestoMeal.class); - } -} \ No newline at end of file diff --git a/app/src/test/java/be/ugent/zeus/hydra/resto/RestoMenuTest.java b/app/src/test/java/be/ugent/zeus/hydra/resto/RestoMenuTest.java deleted file mode 100644 index dabb160fe..000000000 --- a/app/src/test/java/be/ugent/zeus/hydra/resto/RestoMenuTest.java +++ /dev/null @@ -1,34 +0,0 @@ -/* - * Copyright (c) 2021 The Hydra authors - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ - -package be.ugent.zeus.hydra.resto; - -import be.ugent.zeus.hydra.common.ModelTest; - -/** - * @author Niko Strijbol - */ -public class RestoMenuTest extends ModelTest { - public RestoMenuTest() { - super(RestoMenu.class); - } -} \ No newline at end of file diff --git a/app/src/test/java/be/ugent/zeus/hydra/resto/menu/MenuFilterTest.java b/app/src/test/java/be/ugent/zeus/hydra/resto/menu/MenuFilterTest.java deleted file mode 100644 index c63669207..000000000 --- a/app/src/test/java/be/ugent/zeus/hydra/resto/menu/MenuFilterTest.java +++ /dev/null @@ -1,137 +0,0 @@ -/* - * Copyright (c) 2021 The Hydra authors - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ - -package be.ugent.zeus.hydra.resto.menu; - -import android.content.Context; -import android.content.SharedPreferences; -import androidx.preference.PreferenceManager; -import androidx.test.core.app.ApplicationProvider; - -import java.io.IOException; -import java.time.*; -import java.util.ArrayList; -import java.util.Collections; -import java.util.List; - -import be.ugent.zeus.hydra.common.network.InstanceProvider; -import be.ugent.zeus.hydra.resto.RestoMenu; -import be.ugent.zeus.hydra.resto.RestoPreferenceFragment; -import be.ugent.zeus.hydra.testing.Utils; -import com.squareup.moshi.Moshi; -import com.squareup.moshi.Types; -import org.junit.Before; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.robolectric.RobolectricTestRunner; - -import static be.ugent.zeus.hydra.testing.Assert.assertThat; -import static be.ugent.zeus.hydra.testing.Utils.generate; -import static org.hamcrest.Matchers.contains; -import static org.hamcrest.Matchers.empty; -import static org.hamcrest.Matchers.hasSize; -import static org.junit.Assert.assertTrue; - -/** - * @author Niko Strijbol - */ -@RunWith(RobolectricTestRunner.class) -public class MenuFilterTest { - - private final Instant cutOff = Instant.parse("2007-12-03T10:15:00.000Z"); - private final Clock clock = Clock.fixed(cutOff, ZoneOffset.UTC); - - private Context context; - - @Before - public void setUp() { - context = ApplicationProvider.getApplicationContext(); - } - - @Test - public void testDefaults() throws IOException { - Moshi moshi = InstanceProvider.moshi(); - List menus = Utils.readJson(moshi, "resto/menu_default.json", Types.newParameterizedType(List.class, RestoMenu.class)); - // Set half of the restos to before, half after. - var newMenus = new ArrayList(); - for (int i = 0; i < menus.size(); i++) { - var oldMenu = menus.get(i); - LocalDate date; - if (i < menus.size() / 2) { - date = LocalDateTime.ofInstant(cutOff, ZoneId.systemDefault()).toLocalDate().minusDays(menus.size() / 2 - i); - } else { - date = LocalDateTime.ofInstant(cutOff, ZoneId.systemDefault()).toLocalDate().plusDays(i - menus.size() / 2); - } - newMenus.add(oldMenu.withDate(date)); - } - - MenuFilter filter = new MenuFilter(context, clock); - List result = filter.apply(newMenus); - assertThat(result, hasSize(newMenus.size() / 2)); - assertTrue(result.stream().noneMatch(restoMenu -> restoMenu.date().isBefore(cutOff.atZone(ZoneId.systemDefault()).toLocalDate()))); - } - - @Test - public void testSameDayBefore() { - - RestoMenu restoMenu = generate(RestoMenu.class).withDate(LocalDateTime.ofInstant(cutOff, ZoneId.systemDefault()).toLocalDate()); - - // If the time in the settings is after the current time, the resto must be allowed to pass. - SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(context); - preferences.edit().putString(RestoPreferenceFragment.PREF_RESTO_CLOSING_HOUR, "11:00").apply(); - - MenuFilter filter = new MenuFilter(context, clock); - List result = filter.apply(Collections.singletonList(restoMenu)); - - assertThat(result, contains(restoMenu)); - } - - @Test - public void testSameDayAfter() { - RestoMenu restoMenu = generate(RestoMenu.class).withDate(LocalDateTime.ofInstant(cutOff, ZoneId.systemDefault()).toLocalDate()); - - // If the time in the settings is after the current time, the resto must be allowed to pass. - SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(context); - preferences.edit().putString(RestoPreferenceFragment.PREF_RESTO_CLOSING_HOUR, "09:00").apply(); - - MenuFilter filter = new MenuFilter(context, clock); - List result = filter.apply(Collections.singletonList(restoMenu)); - - assertThat(result, empty()); - } - - @Test - public void testSameDayOnMoment() { - RestoMenu restoMenu = generate(RestoMenu.class).withDate(LocalDateTime.ofInstant(cutOff, ZoneId.systemDefault()).toLocalDate()); - - // If the time in the settings is after the current time, the resto must be allowed to pass. - SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(context); - preferences.edit().putString(RestoPreferenceFragment.PREF_RESTO_CLOSING_HOUR, "10:15").apply(); - - // TODO: for some weird reason, if we do not pass the same preference, it doesn't work, even if the debugger - // says they are the same instance and all that. Perhaps this is a bug in Robolectric? - MenuFilter filter = new MenuFilter(preferences, clock); - List result = filter.apply(Collections.singletonList(restoMenu)); - - assertThat(result, empty()); - } -} diff --git a/app/src/test/java/be/ugent/zeus/hydra/resto/sandwich/regular/RegularViewHolderTest.java b/app/src/test/java/be/ugent/zeus/hydra/resto/sandwich/regular/RegularViewHolderTest.java deleted file mode 100644 index cf9eb7712..000000000 --- a/app/src/test/java/be/ugent/zeus/hydra/resto/sandwich/regular/RegularViewHolderTest.java +++ /dev/null @@ -1,91 +0,0 @@ -/* - * Copyright (c) 2021 The Hydra authors - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ - -package be.ugent.zeus.hydra.resto.sandwich.regular; - -import android.view.View; -import androidx.recyclerview.widget.RecyclerView; - -import java.util.Arrays; -import java.util.Collection; - -import be.ugent.zeus.hydra.R; -import be.ugent.zeus.hydra.common.ui.recyclerview.adapters.MultiSelectAdapter; -import net.cachapa.expandablelayout.ExpandableLayout; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.mockito.ArgumentCaptor; -import org.robolectric.ParameterizedRobolectricTestRunner; - -import static be.ugent.zeus.hydra.testing.RobolectricUtils.assertNotEmpty; -import static be.ugent.zeus.hydra.testing.RobolectricUtils.assertTextIs; -import static be.ugent.zeus.hydra.testing.RobolectricUtils.inflate; -import static be.ugent.zeus.hydra.testing.Utils.generate; -import static org.junit.Assert.assertEquals; -import static org.mockito.ArgumentMatchers.anyInt; -import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.verify; -import static org.mockito.Mockito.when; - -/** - * @author Niko Strijbol - */ -@RunWith(ParameterizedRobolectricTestRunner.class) -public class RegularViewHolderTest { - - private final boolean expanded; - - public RegularViewHolderTest(boolean expanded) { - this.expanded = expanded; - } - - @ParameterizedRobolectricTestRunner.Parameters - public static Collection data() { - return Arrays.asList(new Object[][]{{true}, {false}}); - } - - @Test - public void populate() { - View view = inflate(R.layout.item_sandwich); - RegularSandwich sandwich = generate(RegularSandwich.class); - @SuppressWarnings("unchecked") - MultiSelectAdapter adapter = mock(MultiSelectAdapter.class); - when(adapter.isChecked(anyInt())).thenReturn(expanded); - RegularHolder viewHolder = new RegularHolder(view, adapter); - viewHolder.populate(sandwich); - - assertTextIs(sandwich.name(), view.findViewById(R.id.sandwich_name)); - assertNotEmpty(view.findViewById(R.id.sandwich_price_medium)); - assertNotEmpty(view.findViewById(R.id.sandwich_ingredients)); - - ExpandableLayout layout = view.findViewById(R.id.expandable_layout); - assertEquals(expanded, layout.isExpanded()); - - ArgumentCaptor positionCaptor = ArgumentCaptor.forClass(Integer.class); - view.performClick(); - verify(adapter).setChecked(positionCaptor.capture()); - assertEquals(RecyclerView.NO_POSITION, (int) positionCaptor.getValue()); - - assertEquals(!expanded, layout.isExpanded()); - } - -} diff --git a/app/src/test/java/be/ugent/zeus/hydra/schamper/SchamperViewHolderTest.java b/app/src/test/java/be/ugent/zeus/hydra/schamper/SchamperViewHolderTest.java deleted file mode 100644 index b45e389e6..000000000 --- a/app/src/test/java/be/ugent/zeus/hydra/schamper/SchamperViewHolderTest.java +++ /dev/null @@ -1,67 +0,0 @@ -/* - * Copyright (c) 2021 The Hydra authors - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ - -package be.ugent.zeus.hydra.schamper; - -import android.view.View; - -import be.ugent.zeus.hydra.R; -import be.ugent.zeus.hydra.common.ui.customtabs.ActivityHelper; -import org.junit.Before; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.robolectric.RobolectricTestRunner; - -import static be.ugent.zeus.hydra.testing.RobolectricUtils.assertNotEmpty; -import static be.ugent.zeus.hydra.testing.RobolectricUtils.assertTextIs; -import static be.ugent.zeus.hydra.testing.RobolectricUtils.inflate; -import static be.ugent.zeus.hydra.testing.Utils.generate; -import static org.junit.Assert.assertTrue; -import static org.mockito.Mockito.mock; - -/** - * @author Niko Strijbol - */ -@RunWith(RobolectricTestRunner.class) -public class SchamperViewHolderTest { - - private ActivityHelper helper; - - @Before - public void setUp() { - helper = mock(ActivityHelper.class); - } - - @Test - public void populate() { - View view = inflate(R.layout.item_schamper); - SchamperViewHolder viewHolder = new SchamperViewHolder(view, helper); - Article article = generate(Article.class, "categoryColour"); - viewHolder.populate(article); - - assertTextIs(article.title(), view.findViewById(R.id.title)); - assertNotEmpty(view.findViewById(R.id.date)); - assertTextIs(article.author(), view.findViewById(R.id.author)); - // Ignore other fields, maybe one day somebody wants to test them. - assertTrue(view.hasOnClickListeners()); - } -} diff --git a/app/src/test/resources/libraries.sql b/app/src/test/resources/libraries.sql deleted file mode 100644 index 489e32050..000000000 --- a/app/src/test/resources/libraries.sql +++ /dev/null @@ -1,5 +0,0 @@ -INSERT INTO `library_favourites` (`id`, `name`) VALUES ('test1', 'Lib1'); -INSERT INTO `library_favourites` (`id`, `name`) VALUES ('test2', 'Lib2'); -INSERT INTO `library_favourites` (`id`, `name`) VALUES ('test3', 'Lib3'); -INSERT INTO `library_favourites` (`id`, `name`) VALUES ('test4', 'Lib4'); -INSERT INTO `library_favourites` (`id`, `name`) VALUES ('test5', 'Lib5'); \ No newline at end of file diff --git a/app/src/test/resources/library_hours.json b/app/src/test/resources/library_hours.json deleted file mode 100644 index e91c6475a..000000000 --- a/app/src/test/resources/library_hours.json +++ /dev/null @@ -1,332 +0,0 @@ -[ - { - "wday": 3, - "hours": "08:00-17:00", - "month": 8, - "date": "2017-08-09", - "wday_formatted": "Wed", - "comments": "", - "date_formatted": "09-Aug-2017", - "mday": "09", - "year": "2017" - }, - { - "wday": 4, - "hours": "08:00-17:00", - "month": 8, - "date": "2017-08-10", - "wday_formatted": "Thu", - "comments": "", - "date_formatted": "10-Aug-2017", - "mday": "10", - "year": "2017" - }, - { - "wday": 5, - "hours": "08:00-17:00", - "month": 8, - "date": "2017-08-11", - "wday_formatted": "Fri", - "comments": "", - "date_formatted": "11-Aug-2017", - "mday": "11", - "year": "2017" - }, - { - "wday": 6, - "hours": "-", - "month": 8, - "date": "2017-08-12", - "wday_formatted": "Sat", - "comments": "", - "date_formatted": "12-Aug-2017", - "mday": "12", - "year": "2017" - }, - { - "wday": 0, - "hours": "-", - "month": 8, - "date": "2017-08-13", - "wday_formatted": "Sun", - "comments": "", - "date_formatted": "13-Aug-2017", - "mday": "13", - "year": "2017" - }, - { - "wday": 1, - "hours": "-", - "month": 8, - "date": "2017-08-14", - "wday_formatted": "Mon", - "comments": "", - "date_formatted": "14-Aug-2017", - "mday": "14", - "year": "2017" - }, - { - "wday": 2, - "hours": "-", - "month": 8, - "date": "2017-08-15", - "wday_formatted": "Tue", - "comments": "", - "date_formatted": "15-Aug-2017", - "mday": "15", - "year": "2017" - }, - { - "wday": 3, - "hours": "08:00-17:00", - "month": 8, - "date": "2017-08-16", - "wday_formatted": "Wed", - "comments": "", - "date_formatted": "16-Aug-2017", - "mday": "16", - "year": "2017" - }, - { - "wday": 4, - "hours": "08:00-17:00", - "month": 8, - "date": "2017-08-17", - "wday_formatted": "Thu", - "comments": "", - "date_formatted": "17-Aug-2017", - "mday": "17", - "year": "2017" - }, - { - "wday": 5, - "hours": "08:00-17:00", - "month": 8, - "date": "2017-08-18", - "wday_formatted": "Fri", - "comments": "", - "date_formatted": "18-Aug-2017", - "mday": "18", - "year": "2017" - }, - { - "wday": 6, - "hours": "-", - "month": 8, - "date": "2017-08-19", - "wday_formatted": "Sat", - "comments": "", - "date_formatted": "19-Aug-2017", - "mday": "19", - "year": "2017" - }, - { - "wday": 0, - "hours": "-", - "month": 8, - "date": "2017-08-20", - "wday_formatted": "Sun", - "comments": "", - "date_formatted": "20-Aug-2017", - "mday": "20", - "year": "2017" - }, - { - "wday": 1, - "hours": "08:00-17:00", - "month": 8, - "date": "2017-08-21", - "wday_formatted": "Mon", - "comments": "", - "date_formatted": "21-Aug-2017", - "mday": "21", - "year": "2017" - }, - { - "wday": 2, - "hours": "08:00-17:00", - "month": 8, - "date": "2017-08-22", - "wday_formatted": "Tue", - "comments": "", - "date_formatted": "22-Aug-2017", - "mday": "22", - "year": "2017" - }, - { - "wday": 3, - "hours": "08:00-17:00", - "month": 8, - "date": "2017-08-23", - "wday_formatted": "Wed", - "comments": "", - "date_formatted": "23-Aug-2017", - "mday": "23", - "year": "2017" - }, - { - "wday": 4, - "hours": "08:00-17:00", - "month": 8, - "date": "2017-08-24", - "wday_formatted": "Thu", - "comments": "", - "date_formatted": "24-Aug-2017", - "mday": "24", - "year": "2017" - }, - { - "wday": 5, - "hours": "08:00-17:00", - "month": 8, - "date": "2017-08-25", - "wday_formatted": "Fri", - "comments": "", - "date_formatted": "25-Aug-2017", - "mday": "25", - "year": "2017" - }, - { - "wday": 6, - "hours": "-", - "month": 8, - "date": "2017-08-26", - "wday_formatted": "Sat", - "comments": "", - "date_formatted": "26-Aug-2017", - "mday": "26", - "year": "2017" - }, - { - "wday": 0, - "hours": "-", - "month": 8, - "date": "2017-08-27", - "wday_formatted": "Sun", - "comments": "", - "date_formatted": "27-Aug-2017", - "mday": "27", - "year": "2017" - }, - { - "wday": 1, - "hours": "08:00-17:00", - "month": 8, - "date": "2017-08-28", - "wday_formatted": "Mon", - "comments": "", - "date_formatted": "28-Aug-2017", - "mday": "28", - "year": "2017" - }, - { - "wday": 2, - "hours": "08:00-17:00", - "month": 8, - "date": "2017-08-29", - "wday_formatted": "Tue", - "comments": "", - "date_formatted": "29-Aug-2017", - "mday": "29", - "year": "2017" - }, - { - "wday": 3, - "hours": "08:00-17:00", - "month": 8, - "date": "2017-08-30", - "wday_formatted": "Wed", - "comments": "", - "date_formatted": "30-Aug-2017", - "mday": "30", - "year": "2017" - }, - { - "wday": 4, - "hours": "08:00-17:00", - "month": 8, - "date": "2017-08-31", - "wday_formatted": "Thu", - "comments": "", - "date_formatted": "31-Aug-2017", - "mday": "31", - "year": "2017" - }, - { - "wday": 5, - "hours": "08:00-17:00", - "month": 9, - "date": "2017-09-01", - "wday_formatted": "Fri", - "comments": "", - "date_formatted": "01-Sep-2017", - "mday": "01", - "year": "2017" - }, - { - "wday": 6, - "hours": "-", - "month": 9, - "date": "2017-09-02", - "wday_formatted": "Sat", - "comments": "", - "date_formatted": "02-Sep-2017", - "mday": "02", - "year": "2017" - }, - { - "wday": 0, - "hours": "-", - "month": 9, - "date": "2017-09-03", - "wday_formatted": "Sun", - "comments": "", - "date_formatted": "03-Sep-2017", - "mday": "03", - "year": "2017" - }, - { - "wday": 1, - "hours": "08:00-17:00", - "month": 9, - "date": "2017-09-04", - "wday_formatted": "Mon", - "comments": "", - "date_formatted": "04-Sep-2017", - "mday": "04", - "year": "2017" - }, - { - "wday": 2, - "hours": "08:00-17:00", - "month": 9, - "date": "2017-09-05", - "wday_formatted": "Tue", - "comments": "", - "date_formatted": "05-Sep-2017", - "mday": "05", - "year": "2017" - }, - { - "wday": 3, - "hours": "08:00-17:00", - "month": 9, - "date": "2017-09-06", - "wday_formatted": "Wed", - "comments": "", - "date_formatted": "06-Sep-2017", - "mday": "06", - "year": "2017" - }, - { - "wday": 4, - "hours": "08:00-17:00", - "month": 9, - "date": "2017-09-07", - "wday_formatted": "Thu", - "comments": "", - "date_formatted": "07-Sep-2017", - "mday": "07", - "year": "2017" - } -]