2011-09-29 53 views
-1

如果我得到文本的颜色,我得到: java.awt.Color [r = 234,g = 152,b = 28]应该对应橙色 ,但是当我执行断言:这是不工作颜色java类

assertEquals(Color.ORANGE.ToString(),myText.getColor()); 

预期:java.awt.Color中[R = 255,G = 0,b = 0]但:java.awt.Color中[R = 234,G = 152,b = 28]

有什么想法吗?

回答

4

您正在比较String和Color对象。正确断言是

assertEquals(Color.ORANGE, myText.getColor()); 

另外java.awt.Color.orange是new Color(255, 200, 0);

+0

我得到:java.lang.AssertionError:期望值但是: lola

+3

然后要么你的测试是错误的,要么你的代码是错误的。事实上,颜色*在你的眼睛看起来是橙色的并不等于橙色,这种颜色非常精确地定义为r = 255,g = 200,b = 0。 –

0

并且无论如何在Java/AWT/Color.java源ORANGE定义为:

/** 
* The color orange. In the default sRGB space. 
*/ 
public final static Color orange = new Color(255, 200, 0); 

/** 
* The color orange. In the default sRGB space. 
* @since 1.4 
*/ 
public final static Color ORANGE = orange;