diff options
author | Raluca Sauciuc <ralucas@google.com> | 2021-07-09 12:37:37 -0700 |
---|---|---|
committer | Raluca Sauciuc <ralucas@google.com> | 2021-07-12 17:53:25 +0000 |
commit | c3ceb9d30ba33dc2b955d9f731171355147cd7ba (patch) | |
tree | 5f5a0efdee3658d250afc1d28582b23968dc2e20 /shared | |
parent | c5357fc7115d064e8559252c54e80ff72812997f (diff) | |
download | analytics-library-c3ceb9d30ba33dc2b955d9f731171355147cd7ba.tar.gz |
Update the stubbed GraphicsDevice to not assume headless mode
AndroidStudioUsageTrackerTest.testGetMachineDetails fails when running
from the IDE on Windows:
java.lang.AssertionError
at org.junit.Assert.fail(Assert.java:86)
at org.junit.Assert.fail(Assert.java:95)
at com.android.tools.analytics.stubs.StubGraphicsConfiguration.getDevice(StubGraphicsConfiguration.kt:34)
at com.intellij.ui.scale.JBUIScale.sysScale(JBUIScale.java:278)
at com.android.tools.idea.stats.AndroidStudioUsageTracker.getDisplayDetails(AndroidStudioUsageTracker.kt:152)
at com.android.tools.idea.stats.AndroidStudioUsageTracker.getMachineDetails(AndroidStudioUsageTracker.kt:172)
at com.android.tools.idea.stats.AndroidStudioUsageTrackerTest.testGetMachineDetails(AndroidStudioUsageTrackerTest.kt:104)
This is because JBUIScale.sysScale determines HiDPI status based on
the running JRE and the java.awt.headless property. The headless
property was only set during IdeaTestSuiteBase initialization, as
part of the early TestApplication setup, which explains why the test
passes CI and only fails when running by itself.
We're trying to clean up the early TestApplication initialization,
which means StubGraphicsDevice has to work no matter what the headless
status is.
Bug: 193111860
Test: AndroidStudioUsageTrackerTest
Change-Id: Idaea660929579810ca88552d736956ea3261597c
Diffstat (limited to 'shared')
-rw-r--r-- | shared/src/test/java/com/android/tools/analytics/stubs/StubGraphicsDevice.kt | 22 |
1 files changed, 14 insertions, 8 deletions
diff --git a/shared/src/test/java/com/android/tools/analytics/stubs/StubGraphicsDevice.kt b/shared/src/test/java/com/android/tools/analytics/stubs/StubGraphicsDevice.kt index 7bfb862..59b5ae6 100644 --- a/shared/src/test/java/com/android/tools/analytics/stubs/StubGraphicsDevice.kt +++ b/shared/src/test/java/com/android/tools/analytics/stubs/StubGraphicsDevice.kt @@ -21,6 +21,7 @@ import org.junit.Assert.fail import java.awt.GraphicsConfiguration import java.awt.GraphicsDevice import java.awt.Rectangle +import java.awt.geom.AffineTransform /** * A Stub implementation of [GraphicsDevice] for use in tests. By default fails on any call. @@ -51,16 +52,21 @@ open class StubGraphicsDevice : GraphicsDevice() { @JvmStatic /** Creates a GraphicsDevice with specified width & height. */ - fun withBounds(width: Int, height: Int): GraphicsDevice { - return object : StubGraphicsDevice() { - override fun getDefaultConfiguration(): GraphicsConfiguration? { - return object : StubGraphicsConfiguration() { - override fun getBounds(): Rectangle? { - return Rectangle(width, height) - } - } + fun withBounds(width: Int, height: Int): GraphicsDevice = + StubGraphicsDeviceWithBounds(width, height) + + private class StubGraphicsDeviceWithBounds constructor( + val width: Int, + val height: Int + ) : StubGraphicsDevice() { + override fun getDefaultConfiguration(): GraphicsConfiguration { + return object : StubGraphicsConfiguration() { + override fun getBounds() = Rectangle(width, height) + override fun getDevice() = this@StubGraphicsDeviceWithBounds + override fun getDefaultTransform() = AffineTransform() } } + override fun getType(): Int = TYPE_RASTER_SCREEN } } } |