File tree 2 files changed +13
-3
lines changed
java/io/material/catalog/feature
test/javatests/io/material/catalog/feature
2 files changed +13
-3
lines changed Original file line number Diff line number Diff line change 28
28
import android .text .format .Formatter ;
29
29
import android .util .AttributeSet ;
30
30
import android .util .TypedValue ;
31
+ import androidx .annotation .NonNull ;
31
32
import com .google .common .collect .EvictingQueue ;
32
33
import java .util .Queue ;
33
34
@@ -129,7 +130,16 @@ protected void onAttachedToWindow() {
129
130
paint .setColor (colorPrimary );
130
131
}
131
132
132
- public void refreshMemStats (Runtime runtime ) {
133
+ /** A wrapper around {@link Runtime} to allow mocking by tests. */
134
+ interface RuntimeWrapper {
135
+ long maxMemory ();
136
+
137
+ long totalMemory ();
138
+
139
+ long freeMemory ();
140
+ }
141
+
142
+ public void refreshMemStats (@ NonNull RuntimeWrapper runtime ) {
133
143
maxMemoryInBytes = runtime .maxMemory ();
134
144
long availableMemInBytes = maxMemoryInBytes - (runtime .totalMemory () - runtime .freeMemory ());
135
145
long usedMemInBytes = maxMemoryInBytes - availableMemInBytes ;
Original file line number Diff line number Diff line change @@ -45,7 +45,7 @@ public class MemoryViewTest {
45
45
46
46
private static final int BYTES_IN_MB = 1024 * 1024 ;
47
47
private MemoryView memoryView ;
48
- private Runtime runtime ;
48
+ private MemoryView . RuntimeWrapper runtime ;
49
49
50
50
@ Before
51
51
public void createAndMeasureMemoryView () {
@@ -60,7 +60,7 @@ public void createAndMeasureMemoryView() {
60
60
61
61
@ Before
62
62
public void setUpRuntime () {
63
- runtime = mock (Runtime .class );
63
+ runtime = mock (MemoryView . RuntimeWrapper .class );
64
64
when (runtime .maxMemory ()).thenReturn (100L * BYTES_IN_MB );
65
65
when (runtime .totalMemory ()).thenReturn (100L * BYTES_IN_MB );
66
66
when (runtime .freeMemory ()).thenReturn (75L * BYTES_IN_MB );
You can’t perform that action at this time.
0 commit comments