File tree Expand file tree Collapse file tree 2 files changed +13
-3
lines changed
java/io/material/catalog/feature
test/javatests/io/material/catalog/feature Expand file tree Collapse file tree 2 files changed +13
-3
lines changed Original file line number Diff line number Diff line change 2828import android .text .format .Formatter ;
2929import android .util .AttributeSet ;
3030import android .util .TypedValue ;
31+ import androidx .annotation .NonNull ;
3132import com .google .common .collect .EvictingQueue ;
3233import java .util .Queue ;
3334
@@ -129,7 +130,16 @@ protected void onAttachedToWindow() {
129130 paint .setColor (colorPrimary );
130131 }
131132
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 ) {
133143 maxMemoryInBytes = runtime .maxMemory ();
134144 long availableMemInBytes = maxMemoryInBytes - (runtime .totalMemory () - runtime .freeMemory ());
135145 long usedMemInBytes = maxMemoryInBytes - availableMemInBytes ;
Original file line number Diff line number Diff line change @@ -45,7 +45,7 @@ public class MemoryViewTest {
4545
4646 private static final int BYTES_IN_MB = 1024 * 1024 ;
4747 private MemoryView memoryView ;
48- private Runtime runtime ;
48+ private MemoryView . RuntimeWrapper runtime ;
4949
5050 @ Before
5151 public void createAndMeasureMemoryView () {
@@ -60,7 +60,7 @@ public void createAndMeasureMemoryView() {
6060
6161 @ Before
6262 public void setUpRuntime () {
63- runtime = mock (Runtime .class );
63+ runtime = mock (MemoryView . RuntimeWrapper .class );
6464 when (runtime .maxMemory ()).thenReturn (100L * BYTES_IN_MB );
6565 when (runtime .totalMemory ()).thenReturn (100L * BYTES_IN_MB );
6666 when (runtime .freeMemory ()).thenReturn (75L * BYTES_IN_MB );
You can’t perform that action at this time.
0 commit comments