Skip to content

Commit

Permalink
Fixing and refactoring Tests
Browse files Browse the repository at this point in the history
  • Loading branch information
ThorstenBandel committed Mar 4, 2022
1 parent 6606246 commit 9e5074d
Show file tree
Hide file tree
Showing 19 changed files with 170 additions and 174 deletions.
2 changes: 2 additions & 0 deletions Paintroid/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,8 @@ dependencies {
androidTestImplementation 'androidx.test.espresso:espresso-contrib:3.1.0'
androidTestImplementation 'androidx.test.espresso:espresso-intents:3.1.0'
androidTestImplementation "androidx.test.uiautomator:uiautomator:2.2.0"
testImplementation "androidx.test:core-ktx:1.4.0"
implementation 'com.android.support.test.espresso:espresso-idling-resource:3.1.0'
}

tasks.withType(Javadoc).all {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ public class FileFromOtherSourceIntegrationTest {
public ScreenshotOnFailRule screenshotOnFailRule = new ScreenshotOnFailRule();

@ClassRule
public static GrantPermissionRule grantPermissionRule = EspressoUtils.grantPermissionRulesVersionCheck();
public static GrantPermissionRule grantPermissionRule = EspressoUtils.INSTANCE.grantPermissionRulesVersionCheck();

private ContentResolver resolver;
private MainActivity activity;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import android.graphics.Canvas
import android.graphics.Color
import android.net.Uri
import androidx.test.espresso.Espresso.onView
import androidx.test.espresso.IdlingRegistry
import androidx.test.espresso.action.ViewActions.click
import androidx.test.espresso.assertion.ViewAssertions
import androidx.test.espresso.intent.Intents
Expand All @@ -36,6 +37,7 @@ import androidx.test.espresso.matcher.ViewMatchers.withText
import androidx.test.ext.junit.runners.AndroidJUnit4
import androidx.test.rule.ActivityTestRule
import androidx.test.rule.GrantPermissionRule
import java.io.File
import org.catrobat.paintroid.MainActivity
import org.catrobat.paintroid.R
import org.catrobat.paintroid.common.MAX_LAYERS
Expand All @@ -59,7 +61,6 @@ import org.junit.Before
import org.junit.Rule
import org.junit.Test
import org.junit.runner.RunWith
import java.io.File

@RunWith(AndroidJUnit4::class)
class LayerIntegrationTest {
Expand Down Expand Up @@ -595,6 +596,8 @@ class LayerIntegrationTest {

@Test
fun testHideThenUnhideLayer() {
val idlingResource = launchActivityRule.activity.idlingResource
IdlingRegistry.getInstance().register(idlingResource)
LayerMenuViewInteraction.onLayerMenuView()
.performOpen()
.performAddLayer()
Expand All @@ -614,6 +617,7 @@ class LayerIntegrationTest {
.performToggleLayerVisibility(0)
.performClose()
DrawingSurfaceInteraction.onDrawingSurfaceView().checkPixelColor(Color.BLACK, 1f, 1f)
IdlingRegistry.getInstance().unregister(idlingResource)
}

@Test
Expand Down Expand Up @@ -642,11 +646,13 @@ class LayerIntegrationTest {

@Test
fun testLoadLargeBitmapAndAddMaxLayerMenu() {
val idlingResource = launchActivityRule.activity.idlingResource
val intent = Intent().apply {
data = createTestImageFile()
}
Intents.init()
val intentResult = ActivityResult(Activity.RESULT_OK, intent)
IdlingRegistry.getInstance().register(idlingResource)

Intents.intending(IntentMatchers.anyIntent()).respondWith(intentResult)
TopBarViewInteraction.onTopBarView()
Expand All @@ -664,6 +670,7 @@ class LayerIntegrationTest {
.performAddLayer()
.performAddLayer()
.checkLayerCount(MAX_LAYERS)
IdlingRegistry.getInstance().unregister(idlingResource)
}

private fun createTestImageFile(): Uri {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ public class MoreOptionsIntegrationTest {
public ScreenshotOnFailRule screenshotOnFailRule = new ScreenshotOnFailRule();

@ClassRule
public static GrantPermissionRule grantPermissionRule = EspressoUtils.grantPermissionRulesVersionCheck();
public static GrantPermissionRule grantPermissionRule = EspressoUtils.INSTANCE.grantPermissionRulesVersionCheck();

@Before
public void setUp() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ public class ToolOnBackPressedIntegrationTest {
public ScreenshotOnFailRule screenshotOnFailRule = new ScreenshotOnFailRule();

@ClassRule
public static GrantPermissionRule grantPermissionRule = EspressoUtils.grantPermissionRulesVersionCheck();
public static GrantPermissionRule grantPermissionRule = EspressoUtils.INSTANCE.grantPermissionRulesVersionCheck();

private File saveFile = null;
private ToolReference toolReference;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
package org.catrobat.paintroid.test.espresso;

import org.catrobat.paintroid.MainActivity;
import org.catrobat.paintroid.test.espresso.util.EspressoUtils;
import org.catrobat.paintroid.test.utils.ScreenshotOnFailRule;
import org.catrobat.paintroid.tools.ToolType;
import org.junit.Before;
Expand All @@ -30,7 +31,6 @@
import androidx.test.ext.junit.runners.AndroidJUnit4;
import androidx.test.rule.ActivityTestRule;

import static org.catrobat.paintroid.test.espresso.util.EspressoUtils.waitForToast;
import static org.catrobat.paintroid.test.espresso.util.wrappers.BottomNavigationViewInteraction.onBottomNavigationView;
import static org.catrobat.paintroid.test.espresso.util.wrappers.ToolBarViewInteraction.onToolBarView;

Expand All @@ -56,7 +56,7 @@ public void testToolSelectionToast() {
onToolBarView()
.performSelectTool(toolType);

waitForToast(withText(toolType.getNameResource()), 1000);
EspressoUtils.INSTANCE.waitForToast(withText(toolType.getNameResource()), 1000);
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ public class MoreOptionsIntegrationTest {
public ScreenshotOnFailRule screenshotOnFailRule = new ScreenshotOnFailRule();

@ClassRule
public static GrantPermissionRule grantPermissionRule = EspressoUtils.grantPermissionRulesVersionCheck();
public static GrantPermissionRule grantPermissionRule = EspressoUtils.INSTANCE.grantPermissionRulesVersionCheck();

@Before
public void setUp() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ public class OpenedFromPocketCodeNewImageTest {
public ScreenshotOnFailRule screenshotOnFailRule = new ScreenshotOnFailRule();

@ClassRule
public static GrantPermissionRule grantPermissionRule = EspressoUtils.grantPermissionRulesVersionCheck();
public static GrantPermissionRule grantPermissionRule = EspressoUtils.INSTANCE.grantPermissionRulesVersionCheck();

private File imageFile = null;
private MainActivity activity;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -679,11 +679,9 @@ public void alphaValueIsSetInSliderWhenChangedInSeekBar() {
.performOpenColorPicker();
onView(allOf(withId(R.id.color_picker_tab_icon), withBackground(R.drawable.ic_color_picker_tab_rgba))).perform(click());

// set color to value #7F000000, alpha seekbar 49%
onView(withId(R.id.color_picker_color_rgb_seekbar_alpha)).perform(touchCenterMiddle());
onView(allOf(withId(R.id.color_picker_tab_icon), withBackground(R.drawable.ic_color_picker_tab_preset))).perform(scrollTo(), click());
onToolProperties()
.checkMatchesColor(Color.parseColor("#7F000000"));
onColorPickerView().checkNewColorViewColor(Color.parseColor("#80000000"));
}

@Test
Expand All @@ -692,7 +690,6 @@ public void alphaValueIsSetInSeekBarWhenChangedInSlider() {
.performOpenColorPicker();
onView(allOf(withId(R.id.color_picker_tab_icon), withBackground(R.drawable.ic_color_picker_tab_preset))).perform(click());

// set color to value #80000000, alpha seekbar 50%
onView(withId(R.id.color_alpha_slider)).perform(scrollTo(), touchCenterMiddle());

onView(allOf(withId(R.id.color_picker_tab_icon), withBackground(R.drawable.ic_color_picker_tab_rgba))).perform(click());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@
import org.junit.Test;
import org.junit.runner.RunWith;

import androidx.test.espresso.IdlingRegistry;
import androidx.test.espresso.idling.CountingIdlingResource;
import androidx.test.ext.junit.runners.AndroidJUnit4;
import androidx.test.rule.ActivityTestRule;

Expand Down Expand Up @@ -221,6 +223,8 @@ public void testCheckmarkLineFeatureChangeShape() {

@Test
public void testCheckmarkLineFeatureChangeStrokeWidth() {
CountingIdlingResource idlingResource = launchActivityRule.getActivity().getIdlingResource();
IdlingRegistry.getInstance().register(idlingResource);
onToolProperties().setColor(Color.BLACK);

onDrawingSurfaceView()
Expand Down Expand Up @@ -252,6 +256,7 @@ public void testCheckmarkLineFeatureChangeStrokeWidth() {

onDrawingSurfaceView()
.checkPixelColor(Color.BLACK, BitmapLocationProvider.MIDDLE);
IdlingRegistry.getInstance().unregister(idlingResource);
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
import org.catrobat.paintroid.MainActivity;
import org.catrobat.paintroid.R;
import org.catrobat.paintroid.test.espresso.rtl.util.RtlActivityTestRule;
import org.catrobat.paintroid.test.espresso.util.EspressoUtils;
import org.catrobat.paintroid.test.utils.ScreenshotOnFailRule;
import org.catrobat.paintroid.tools.ToolType;
import org.junit.Rule;
Expand All @@ -41,7 +42,6 @@
import androidx.test.rule.ActivityTestRule;

import static org.catrobat.paintroid.test.espresso.rtl.util.RtlUiTestUtils.checkTextDirection;
import static org.catrobat.paintroid.test.espresso.util.EspressoUtils.getConfiguration;
import static org.catrobat.paintroid.test.espresso.util.UiMatcher.atPosition;
import static org.catrobat.paintroid.test.espresso.util.UiMatcher.hasTypeFace;
import static org.catrobat.paintroid.test.espresso.util.wrappers.ToolBarViewInteraction.onToolBarView;
Expand Down Expand Up @@ -71,7 +71,7 @@ public class TextToolFontListTestArabic {

@Test
public void testTextFontFaceOfFontSpinnerArabic() {
assertEquals(View.LAYOUT_DIRECTION_RTL, getConfiguration().getLayoutDirection());
assertEquals(View.LAYOUT_DIRECTION_RTL, EspressoUtils.INSTANCE.getConfiguration().getLayoutDirection());
assertTrue(checkTextDirection(Locale.getDefault().getDisplayName()));

onToolBarView()
Expand Down

This file was deleted.

Loading

0 comments on commit 9e5074d

Please sign in to comment.