StandardWidgetToolkitProvider extends Provider { static File getSwtRuntimeJar(final File defaultRuntimeJar) { File swtRuntime = null; final String overrideSwtJarPath = System.getProperty(SWT_RUNTIME_JAR_OVERRIDE); if (!StringHelper.isNullOrWhiteSpace(overrideSwtJarPath)) { final File overrideSwtJar = new File(overrideSwtJarPath); if (overrideSwtJar.isFile()) { swtRuntime = overrideSwtJar; } } if (swtRuntime == null) { final PackageLocator locator = PACKAGE_LOCATOR_OVERRIDE == null ? packageLocator : PACKAGE_LOCATOR_OVERRIDE; try { final File swtClasspathJar = locator.locatePackage(SWT.class); swtRuntime = swtClasspathJar; } catch (NoClassDefFoundError e){ } } if (swtRuntime == null && defaultRuntimeJar.isFile()) { swtRuntime = defaultRuntimeJar; } return swtRuntime; } protected  StandardWidgetToolkitProvider(); static String getDefaultSwtJarPath(); @Override List<String> checkRequirements(); @Override void augmentProcessParameters(final List<String> command, final List<String> classPath); static final String SWT_RUNTIME_JAR_OVERRIDE; }
@Test public void swtRuntimeRequirementMet_checkPropertyFirst() throws IOException { final File swtFromProperty = File.createTempFile("propertyPointedSwtJar", "unitTest"); final File swtFromClasspath = packageLocator.locatePackage(SWT.class); final File swtDefaultJar = File.createTempFile("defaultFakeSwtJar", "unitTest"); System.setProperty(StandardWidgetToolkitProvider.SWT_RUNTIME_JAR_OVERRIDE, swtFromProperty.getAbsolutePath()); final File swtRuntime = StandardWidgetToolkitProvider.getSwtRuntimeJar(swtDefaultJar); assertNotNull(swtRuntime); assertEquals(swtFromProperty.getAbsolutePath(), swtRuntime.getAbsolutePath()); }
@Test public void swtRuntimeRequirementMet_loadFromClasspathBeforeGetDefault() throws IOException { final File swtFromClasspath = packageLocator.locatePackage(SWT.class); final File swtDefaultJar = File.createTempFile("defaultFakeSwtJar", "unitTest"); final File swtRuntime = StandardWidgetToolkitProvider.getSwtRuntimeJar(swtDefaultJar); assertNotNull(swtRuntime); assertEquals(swtFromClasspath.getAbsolutePath(), swtRuntime.getAbsolutePath()); }
@Test public void swtRuntimeRequirementMet_loadDefaultSwtJarIfExists() throws IOException { final PackageLocator locatorMock = mock(PackageLocator.class); when(locatorMock.locatePackage(SWT.class)).thenThrow(new NoClassDefFoundError()); StandardWidgetToolkitProvider.PACKAGE_LOCATOR_OVERRIDE = locatorMock; final File swtJar = File.createTempFile("eclipseSwtProviderExists", "unitTest"); File actualJarFile = StandardWidgetToolkitProvider.getSwtRuntimeJar(swtJar); assertNotNull(actualJarFile); assertEquals(swtJar.getAbsolutePath(), actualJarFile.getAbsolutePath()); swtJar.delete(); actualJarFile = StandardWidgetToolkitProvider.getSwtRuntimeJar(swtJar); assertNull(actualJarFile); }