sysmodelmgr/com.symbian.smt.gui.unittest/src/com/symbian/smt/gui/smtwidgets/FilterWidgetTest.java
changeset 0 522a326673b6
equal deleted inserted replaced
-1:000000000000 0:522a326673b6
       
     1 // Copyright (c) 2008-2009 Nokia Corporation and/or its subsidiary(-ies).
       
     2 // All rights reserved.
       
     3 // This component and the accompanying materials are made available
       
     4 // under the terms of "Eclipse Public License v1.0"
       
     5 // which accompanies this distribution, and is available
       
     6 // at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     7 //
       
     8 // Initial Contributors:
       
     9 // Nokia Corporation - initial contribution.
       
    10 //
       
    11 // Contributors:
       
    12 //
       
    13 // Description:
       
    14 //
       
    15 
       
    16 package com.symbian.smt.gui.smtwidgets;
       
    17 
       
    18 import static org.junit.Assert.*;
       
    19 import junit.framework.Assert;
       
    20 import org.eclipse.swt.widgets.Display;
       
    21 import org.eclipse.swt.widgets.Shell;
       
    22 import com.symbian.smt.gui.smtwidgets.FilterWidget;
       
    23 import org.junit.After;
       
    24 import org.junit.Before;
       
    25 import org.junit.Test;
       
    26 import org.eclipse.swt.SWT;
       
    27 
       
    28 public class FilterWidgetTest {
       
    29 	Display display;
       
    30 	Shell shell;
       
    31 	FilterWidget filterWidget;
       
    32 	
       
    33 	@Before
       
    34 	public final void setUp() {
       
    35 		display = new Display();
       
    36 		shell = new Shell(display);
       
    37 		
       
    38 		filterWidget = new FilterWidget(shell, SWT.NONE);
       
    39 	}
       
    40 
       
    41 	@After
       
    42 	public void tearDown() throws Exception {
       
    43 		display.dispose();
       
    44 	}
       
    45 	
       
    46 	/**
       
    47 	 * Test method for {@link com.symbian.smt.gui.smtwidgets.FilterWidget#FilterWidget(org.eclipse.swt.widgets.Composite, int)}.
       
    48 	 */
       
    49 	@Test
       
    50 	public final void testFilterWidget() {
       
    51 		Assert.assertNotNull(filterWidget);
       
    52 	}
       
    53 
       
    54 
       
    55 	/**
       
    56 	 * Test method for {@link com.symbian.smt.gui.smtwidgets.FilterWidget#setFilterItems(java.lang.String[])}.
       
    57 	 */
       
    58 	@Test
       
    59 	public final void testSetEmpty() {
       
    60 		String[] list = new String[0];
       
    61 
       
    62 		filterWidget.setFilterItems(list);
       
    63 		
       
    64 		String[] results = filterWidget.getFilterItems();
       
    65 		
       
    66 		assertNotNull(results);
       
    67 		
       
    68 		if (results.length > 0) {
       
    69 			fail("Should return an empty list");
       
    70 		}
       
    71 	}
       
    72 	
       
    73 	@Test
       
    74 	public final void testFilterItems() {
       
    75 		String[] list = new String[] {"1", "2"};
       
    76 
       
    77 		filterWidget.setFilterItems(list);
       
    78 		
       
    79 		String[] results = filterWidget.getFilterItems();
       
    80 
       
    81 		if (results.length != 2) {
       
    82 			fail("The list returned should contain 2 elements");
       
    83 		}
       
    84 	}
       
    85 	
       
    86 	@Test
       
    87 	public final void testSetTwice() {
       
    88 		
       
    89 		String[] list = new String[] {"1", "2"};
       
    90 		
       
    91 		String[] list2 = new String[] {"1", "2", "3", "4"};
       
    92 		
       
    93 		filterWidget.setFilterItems(list);
       
    94 		
       
    95 		filterWidget.setFilterItems(list2);
       
    96 		
       
    97 		String[] results = filterWidget.getFilterItems();
       
    98 		
       
    99 		Assert.assertEquals("Expected size: " + list2.length + ", got " + results.length, list2.length, results.length);
       
   100 	}
       
   101 	
       
   102 /*	@Test
       
   103 	public final void testSetString() {
       
   104 		
       
   105 		String filter = "java,gt,";
       
   106 		
       
   107 		filterWidget.setFilterItems(filter);
       
   108 		
       
   109 		String[] results = filterWidget.getFilterItems();
       
   110 		
       
   111 		Assert.assertEquals("Expected size: 2, got " + results.length, 2, results.length);
       
   112 		Assert.assertEquals("Expected java as first item", "java", results[0]);
       
   113 		Assert.assertEquals("Expected gt as first item", "gt", results[1]);
       
   114 	
       
   115 	}
       
   116 	
       
   117 	@Test
       
   118 	public final void testSetString2() {
       
   119 		
       
   120 		String filter = "java,gt";
       
   121 		
       
   122 		filterWidget.setFilterItems(filter);
       
   123 		
       
   124 		String[] results = filterWidget.getFilterItems();
       
   125 		
       
   126 		Assert.assertEquals("Expected size: 2, got " + results.length, 2, results.length);
       
   127 		Assert.assertEquals("Expected java as first item", "java", results[0]);
       
   128 		Assert.assertEquals("Expected gt as first item", "gt", results[1]);
       
   129 	
       
   130 	}
       
   131 	
       
   132 	@Test
       
   133 	public final void testGetString() {
       
   134 		
       
   135 		String[] list = new String[] {"1", "2"};
       
   136 		
       
   137 		filterWidget.setFilterItems(list);
       
   138 		
       
   139 	    String result = filterWidget.getFilterItemsString();
       
   140 		
       
   141 		Assert.assertEquals("1,2,", result);
       
   142 	
       
   143 	}
       
   144 	*/
       
   145 }
       
   146 
       
   147 
       
   148