Debian Codegraph @

tests/com/bulenkov/iconloader/IconLoaderTestCase.java

raw symbols SCIP
1 /*
2 * Copyright 2000-2014 JetBrains s.r.o.
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
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 * @author Konstantin Bulenkov
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 //noinspection unchecked
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 }