Skip to content

Commit 631a16f

Browse files
committed
more tests
1 parent 38293a8 commit 631a16f

File tree

4 files changed

+227
-0
lines changed

4 files changed

+227
-0
lines changed
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
package com.github.tehras.loadingskeleton.helpers;
2+
3+
import org.junit.Test;
4+
import org.junit.runner.RunWith;
5+
import org.robolectric.RobolectricTestRunner;
6+
import org.robolectric.annotation.Config;
7+
8+
import static com.google.common.truth.Truth.assertThat;
9+
10+
11+
@RunWith(RobolectricTestRunner.class)
12+
@Config(manifest = Config.NONE)
13+
public class OptionsTest {
14+
15+
@Test
16+
public void equalsTest() {
17+
Options o1 = new Options(true, true, 10f, 1);
18+
Options o2 = new Options(true, true, 10f, 1);
19+
20+
assertThat(o1).isEqualTo(o2);
21+
}
22+
23+
24+
@Test
25+
public void getterTests() {
26+
Options o1 = new Options(true, true, 10f, 1);
27+
28+
assertThat(o1.getColor()).isEqualTo(1);
29+
assertThat(o1.getGradient()).isTrue();
30+
assertThat(o1.getCornerRadius()).isEqualTo(10f);
31+
assertThat(o1.getShimmer()).isTrue();
32+
}
33+
34+
@Test
35+
public void copyTest() {
36+
Options o1 = new Options(true, true, 10f, 1);
37+
Options o2 = o1.copy(true, true, 10f, 1);
38+
39+
assertThat(o1).isEqualTo(o2);
40+
}
41+
42+
}
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
package com.github.tehras.loadingskeleton.shadows;
2+
3+
4+
import android.graphics.Color;
5+
import android.graphics.drawable.ColorDrawable;
6+
import android.graphics.drawable.Drawable;
7+
8+
import org.apache.tools.ant.types.resources.Resources;
9+
import org.robolectric.annotation.Implementation;
10+
import org.robolectric.annotation.Implements;
11+
12+
@Implements(Resources.class)
13+
public class ShadowResources {
14+
15+
@Deprecated
16+
@Implementation
17+
public Drawable getDrawable(int id) throws android.content.res.Resources.NotFoundException {
18+
return new ColorDrawable();
19+
}
20+
21+
@Deprecated
22+
@Implementation
23+
public int getColor(int id) throws android.content.res.Resources.NotFoundException {
24+
return Color.RED;
25+
}
26+
}
Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
package com.github.tehras.loadingskeleton.utils;
2+
3+
import android.app.Activity;
4+
import android.graphics.Color;
5+
import android.graphics.drawable.GradientDrawable;
6+
import android.view.View;
7+
import android.widget.LinearLayout;
8+
9+
import com.github.tehras.loadingskeleton.BuildConfig;
10+
import com.github.tehras.loadingskeleton.R;
11+
import com.github.tehras.loadingskeleton.helpers.Options;
12+
import com.github.tehras.loadingskeleton.shadows.ShadowResources;
13+
14+
import org.junit.Before;
15+
import org.junit.Test;
16+
import org.junit.runner.RunWith;
17+
import org.robolectric.RobolectricTestRunner;
18+
import org.robolectric.annotation.Config;
19+
20+
import static com.google.common.truth.Truth.assertThat;
21+
import static org.robolectric.Robolectric.setupActivity;
22+
23+
@RunWith(RobolectricTestRunner.class)
24+
@Config(constants = BuildConfig.class, shadows = {ShadowResources.class})
25+
public class ViewHelperKtTest {
26+
27+
28+
private Activity activity;
29+
30+
@Before
31+
public void setUp() {
32+
this.activity = setupActivity(Activity.class);
33+
}
34+
35+
@Test
36+
public void darkerTest() {
37+
int color = Color.RED;
38+
39+
//Just makes sure no crash
40+
ViewHelperKt.darker(color, .5f);
41+
ViewHelperKt.darker(color, 1.5f);
42+
ViewHelperKt.darker(color, 25.5f);
43+
ViewHelperKt.darker(color, -5.5f);
44+
}
45+
46+
@Test
47+
public void gradientTest() {
48+
Options o1 = new Options(true, true, 10f, R.color.loading_skeleton_default_animation_color);
49+
50+
GradientDrawable gd = ViewHelperKt.gradientDrawable(o1, new View(activity));
51+
52+
assertThat(gd.getCornerRadius()).isEqualTo(0f);
53+
assertThat(gd.getGradientType()).isEqualTo(0);
54+
}
55+
56+
@Test
57+
public void assignBackgroundtest() {
58+
Options o1 = new Options(true, true, 10f, R.color.loading_skeleton_default_animation_color);
59+
60+
LinearLayout v = new LinearLayout(activity);
61+
62+
ViewHelperKt.assignBackground(o1, v);
63+
64+
assertThat(v.getBackground()).isInstanceOf(GradientDrawable.class);
65+
assertThat(v.getBackground().getAlpha()).isEqualTo(255);
66+
assertThat(((GradientDrawable) v.getBackground()).getCornerRadius()).isEqualTo(0f);
67+
68+
o1 = new Options(true, false, 10f, R.color.loading_skeleton_default_animation_color);
69+
ViewHelperKt.assignBackground(o1, v);
70+
71+
assertThat(v.getBackground()).isInstanceOf(GradientDrawable.class);
72+
assertThat(v.getBackground().getAlpha()).isEqualTo(127);
73+
assertThat(((GradientDrawable) v.getBackground()).getCornerRadius()).isEqualTo(0f);
74+
75+
}
76+
77+
}
Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
package com.github.tehras.loadingskeleton.view_streamers;
2+
3+
import android.app.Activity;
4+
import android.graphics.Color;
5+
import android.graphics.drawable.Drawable;
6+
import android.graphics.drawable.GradientDrawable;
7+
import android.widget.TextView;
8+
9+
import com.github.tehras.loadingskeleton.BuildConfig;
10+
import com.github.tehras.loadingskeleton.R;
11+
import com.github.tehras.loadingskeleton.helpers.Options;
12+
import com.github.tehras.loadingskeleton.shadows.ShadowResources;
13+
import com.google.common.truth.Truth;
14+
15+
import org.junit.Before;
16+
import org.junit.Test;
17+
import org.junit.runner.RunWith;
18+
import org.robolectric.RobolectricTestRunner;
19+
import org.robolectric.annotation.Config;
20+
21+
import static com.google.common.truth.Truth.assertThat;
22+
import static org.robolectric.Robolectric.setupActivity;
23+
24+
@RunWith(RobolectricTestRunner.class)
25+
@Config(constants = BuildConfig.class, shadows = {ShadowResources.class})
26+
public class DefaultTextViewStreamerTest {
27+
28+
private Activity activity;
29+
30+
@Before
31+
public void setUp() {
32+
this.activity = setupActivity(Activity.class);
33+
}
34+
35+
@Test
36+
public void convertTest() {
37+
DefaultTextViewStreamer defaultTextViewStreamer = new DefaultTextViewStreamer();
38+
39+
Drawable drawable = new GradientDrawable();
40+
drawable.setAlpha(200);
41+
42+
TextView t = new TextView(activity);
43+
t.setBackground(drawable);
44+
Options o = new Options(true, true, 10f, R.color.loading_skeleton_default_animation_color);
45+
46+
defaultTextViewStreamer.convert(activity, t, o);
47+
48+
assertThat(t.getBackground().getAlpha()).isNotEqualTo(200);
49+
50+
t.setText("Test");
51+
52+
defaultTextViewStreamer.convert(activity, t, o);
53+
54+
assertThat(t.getText()).isNotEqualTo("Test");
55+
}
56+
57+
@Test
58+
public void revertTest() {
59+
DefaultTextViewStreamer defaultTextViewStreamer = new DefaultTextViewStreamer();
60+
61+
Drawable drawable = new GradientDrawable();
62+
drawable.setAlpha(200);
63+
64+
TextView t = new TextView(activity);
65+
t.setText("Test");
66+
t.setBackground(drawable);
67+
Options o = new Options(true, true, 10f, R.color.loading_skeleton_default_animation_color);
68+
69+
defaultTextViewStreamer.start();
70+
defaultTextViewStreamer.convert(activity, t, o);
71+
72+
assertThat(t.getText()).isNotEqualTo("Test");
73+
assertThat(t.getBackground().getAlpha()).isNotEqualTo(200);
74+
75+
defaultTextViewStreamer.stop();
76+
defaultTextViewStreamer.revert(activity, t);
77+
78+
assertThat(t.getText()).isEqualTo("Test");
79+
assertThat(t.getBackground().getAlpha()).isEqualTo(200);
80+
}
81+
82+
}

0 commit comments

Comments
 (0)