示例#1
0
 @Test
 public void fractions() {
   assertEquals(1, QualityValue.valueOf("0.001").intValue());
   assertEquals(12, QualityValue.valueOf("0.012").intValue());
   assertEquals(123, QualityValue.valueOf("0.123").intValue());
   assertEquals(120, QualityValue.valueOf("0.12").intValue());
   assertEquals(100, QualityValue.valueOf("0.1").intValue());
 }
示例#2
0
 @Test
 public void one() {
   assertEquals(1000, QualityValue.valueOf("1").intValue());
   assertEquals(1000, QualityValue.valueOf("1.").intValue());
   assertEquals(1000, QualityValue.valueOf("1.0").intValue());
   assertEquals(1000, QualityValue.valueOf("1.00").intValue());
   assertEquals(1000, QualityValue.valueOf("1.000").intValue());
 }
示例#3
0
 @Test
 public void zero() {
   assertEquals(0, QualityValue.valueOf("0").intValue());
   assertEquals(0, QualityValue.valueOf("0.").intValue());
   assertEquals(0, QualityValue.valueOf("0.0").intValue());
   assertEquals(0, QualityValue.valueOf("0.00").intValue());
   assertEquals(0, QualityValue.valueOf("0.000").intValue());
 }
 @Test
 public void simple() {
   String header = "da, en-gb;q=0.8, en;q=0.7";
   Locale[] locales = {new Locale("da"), Locale.UK, Locale.ENGLISH};
   QualityValue[] fields = {
     QualityValue.DEFAULT, QualityValue.valueOf("0.8"), QualityValue.valueOf("0.7"),
   };
   assertList(header, locales, fields);
 }
示例#5
0
 @Test
 public void numbers() {
   QualityValue x = QualityValue.valueOf("0.08");
   assertEquals(80, x.intValue());
   assertEquals(80L, x.longValue());
   assertEquals(0.08f, x.floatValue(), 0.00001f);
   assertEquals(0.08d, x.doubleValue(), 0.00001d);
 }
示例#6
0
 @Test
 public void nullContent() {
   assertEquals(QualityValue.DEFAULT, QualityValue.valueOf(null));
 }
示例#7
0
 @Test(expected = BadRequestException.class)
 public void wrongContent() {
   QualityValue.valueOf("0,2F");
 }
示例#8
0
 @Test(expected = BadRequestException.class)
 public void tooShort() {
   QualityValue.valueOf("");
 }
示例#9
0
 @Test(expected = BadRequestException.class)
 public void tooLong() {
   QualityValue.valueOf("0.1234");
 }
示例#10
0
 @Test(expected = BadRequestException.class)
 public void tooSmall() {
   QualityValue.valueOf("-0.001");
 }
示例#11
0
 @Test(expected = BadRequestException.class)
 public void tooLarge() {
   QualityValue.valueOf("1.001");
 }
示例#12
0
 @Test
 public void equivalent() {
   assertTrue(QualityValue.valueOf("0.1").equals(QualityValue.valueOf("0.10")));
   assertFalse(QualityValue.valueOf("1.").equals(QualityValue.valueOf("0.999")));
 }