Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: b5e93aafbcd216e889b8157bfddc0619e0f69138 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
/*******************************************************************************
 * Copyright (c) 2012 Original authors and others.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 * 
 * Contributors:
 *     Original authors and others - initial API and implementation
 ******************************************************************************/
package org.eclipse.nebula.widgets.nattable.persistence;

import static org.junit.Assert.assertEquals;

import java.util.Properties;

import org.eclipse.nebula.widgets.nattable.persistence.ColorPersistor;
import org.eclipse.swt.SWT;
import org.eclipse.swt.graphics.Color;
import org.eclipse.swt.widgets.Display;
import org.junit.Before;
import org.junit.Test;

public class ColorPersistorTest {

	private static final Color TEST_COLOR = Display.getDefault().getSystemColor(SWT.COLOR_RED);;
	Properties properties;

	@Before
	public void setup() {
		properties = new Properties();
	}

	@Test
	public void shouldSaveTheColorAsAString() throws Exception {
		ColorPersistor.saveColor("prefix", properties, TEST_COLOR);
		assertEquals("255,0,0", properties.getProperty("prefix.color"));
	}

	@Test
	public void shouldRecostructColorInstanceFromSavedRGBString() throws Exception {
		properties.setProperty("prefix.color", "255, 0, 0");
		
		Color actual = ColorPersistor.loadColor("prefix", properties);
		
		assertEquals(TEST_COLOR, actual);
	}
}

Back to the top