| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
package com.bulenkov.iconloader; |
| 18 |
|
| 19 |
import com.bulenkov.iconloader.util.Ref; |
| 20 |
import com.bulenkov.iconloader.util.UIUtil; |
| 21 |
import junit.framework.TestCase; |
| 22 |
|
| 23 |
import javax.swing.*; |
| 24 |
import java.lang.reflect.Field; |
| 25 |
|
| 26 |
|
| 27 |
|
| 28 |
|
| 29 |
public abstract class IconLoaderTestCase extends TestCase { |
| 30 |
static { |
| 31 |
IconLoader.enableSaveRealIconPath(); |
| 32 |
} |
| 33 |
|
| 34 |
public static void setRetina(boolean isRetina) throws Exception { |
| 35 |
if (isRetina == UIUtil.isRetina()) { |
| 36 |
return; |
| 37 |
} |
| 38 |
|
| 39 |
final Field ourRetina = UIUtil.class.getDeclaredField("ourRetina"); |
| 40 |
ourRetina.setAccessible(true); |
| 41 |
|
| 42 |
final Ref<Boolean> ref = (Ref<Boolean>)ourRetina.get(null); |
| 43 |
ref.set(isRetina); |
| 44 |
} |
| 45 |
|
| 46 |
public static void setDarkIcons(boolean dark) throws Exception { |
| 47 |
IconLoader.setUseDarkIcons(dark); |
| 48 |
} |
| 49 |
|
| 50 |
public void checkIcon(String path, boolean isRetina, boolean isDark, String expectedName) throws Exception { |
| 51 |
setRetina(isRetina); |
| 52 |
setDarkIcons(isDark); |
| 53 |
final Icon icon = IconLoader.getIcon(path); |
| 54 |
assert icon != null : "Can't find icon '" + path + "'"; |
| 55 |
icon.getIconHeight(); |
| 56 |
|
| 57 |
final String realPath = ((IconLoader.CachedImageIcon) icon).myOriginalPath; |
| 58 |
assert realPath != null && realPath.endsWith(expectedName) : |
| 59 |
"Icon should be loaded from '" + expectedName + "' but it was loaded from '" + realPath + "'"; |
| 60 |
} |
| 61 |
} |