Example #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());
 }
Example #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());
 }
Example #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);
 }
Example #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);
 }
Example #6
0
 @Test
 public void nullContent() {
   assertEquals(QualityValue.DEFAULT, QualityValue.valueOf(null));
 }
Example #7
0
 @Test(expected = BadRequestException.class)
 public void wrongContent() {
   QualityValue.valueOf("0,2F");
 }
Example #8
0
 @Test(expected = BadRequestException.class)
 public void tooShort() {
   QualityValue.valueOf("");
 }
Example #9
0
 @Test(expected = BadRequestException.class)
 public void tooLong() {
   QualityValue.valueOf("0.1234");
 }
Example #10
0
 @Test(expected = BadRequestException.class)
 public void tooSmall() {
   QualityValue.valueOf("-0.001");
 }
Example #11
0
 @Test(expected = BadRequestException.class)
 public void tooLarge() {
   QualityValue.valueOf("1.001");
 }
Example #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")));
 }