1   /**
2    * This program is free software: you can redistribute it and/or modify
3    * it under the terms of the GNU General Public License as published by
4    * the Free Software Foundation, version 3.
5    *
6    * This program is distributed in the hope that it will be useful,
7    * but WITHOUT ANY WARRANTY; without even the implied warranty of
8    * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
9    * GNU General Public License for more details.
10   *
11   * You should have received a copy of the GNU General Public License
12   * along with this program. If not, see <http://www.gnu.org/licenses/>.
13   */
14  
15  package net.curre.prefcount.service;
16  
17  import java.util.logging.Logger;
18  
19  import net.curre.prefcount.gui.theme.skin.DefaultSkin;
20  import net.curre.prefcount.gui.theme.skin.PrefSkin;
21  import net.curre.prefcount.test.BaseTestCase;
22  
23  /**
24   * This is a junit test for testing LAF service.
25   * <p/>
26   * Created date: Jul 25, 2007
27   *
28   * @author Yevgeny Nyden
29   */
30  public class LafThemeServiceTest extends BaseTestCase {
31  
32    /** Private class logger. */
33    private static Logger log = Logger.getLogger(LafThemeServiceTest.class.toString());
34  
35    /**
36     * Test main settings service functionality.
37     *
38     * @throws Exception on error.
39     */
40    public void testAll() throws Exception {
41  
42      log.info("Running testAll()...");
43  
44      PrefSkin[] skins = LafThemeService.AVAILABLE_SKINS;
45      assertNotNull("PrefSkin array is null", skins);
46      assertTrue("PrefSkin array is empty", skins.length > 0);
47      for (PrefSkin skin : skins) {
48        assertNotNull("PrefSkin is null", skin);
49        assertNotNull("PrefSkin boardBackgroundPaint is null", skin.getBoardBackgroundPaint());
50        assertNotNull("PrefSkin boardLineColor is null", skin.getBoardLineColor());
51        assertNotNull("PrefSkin boardLineStroke is null", skin.getBoardLineStroke());
52        assertNotNull("PrefSkin mainBackgroundColor is null", skin.getMainBackgroundColor());
53        assertNotNull("PrefSkin nameResourceKey is null", skin.getNameResourceKey());
54        assertNotNull("PrefSkin playerNameColor is null", skin.getPlayerNameColor());
55        assertNotNull("PrefSkin playerNameFont is null", skin.getPlayerNameFont());
56        assertNotNull("PrefSkin playerNameStroke is null", skin.getPlayerNameStroke());
57        assertNotNull("PrefSkin playerTotalsColor is null", skin.getPlayerTotalsColor());
58        assertNotNull("PrefSkin playerTotalsFont is null", skin.getPlayerTotalsFont());
59        assertNotNull("PrefSkin playerTotalsStroke is null", skin.getPlayerTotalsStroke());
60        if (skin instanceof DefaultSkin) {
61          assertNull("DefaultSkin should have substanceSkinClassName set to null.", skin.getSubstanceSkinClassName());
62        } else {
63          assertNotNull("PrefSkin substanceSkinClassName is null", skin.getSubstanceSkinClassName());
64        }
65      }
66  
67      LafThemeService service = LafThemeService.getInstance();
68      assertNotNull("LafThemeService is null", service);
69      PrefSkin prefSkin = service.getCurrentSkin();
70      assertNotNull("Current skin is null", prefSkin);
71      assertTrue("Default current skin must be DefaultSkin", prefSkin instanceof DefaultSkin);
72  
73      // checking finding skin method
74      PrefSkin skin = service.findSkinById(skins[0].getNameResourceKey());
75      assertNotNull("Unable to find skin by ID \"" + skins[0].getNameResourceKey() + "\"", skin);
76      assertEquals("Wrong skin found", skins[0].getNameResourceKey(), skin.getNameResourceKey());
77      try {
78        service.findSkinById("noSuchSkinId");
79        fail("Expected ServiceException for ID \"noSuchSkinId\" parameter.");
80      } catch (ServiceException e) {
81        // expected
82      }
83    }
84  
85  }