EnglishReasonPhraseCatalog implements ReasonPhraseCatalog { @Override public String getReason(final int status, final Locale loc) { Args.checkRange(status, 100, 599, "Unknown category for status code"); final int category = status / 100; final int subcode = status - 100*category; String reason = null; if (REASON_PHRASES[category].length > subcode) { reason = REASON_PHRASES[category][subcode]; } return reason; } protected  EnglishReasonPhraseCatalog(); @Override String getReason(final int status, final Locale loc); final static EnglishReasonPhraseCatalog INSTANCE; }
@Test public void testReasonPhrases() throws IllegalAccessException { final Field[] publicFields = HttpStatus.class.getFields(); Assert.assertNotNull( publicFields ); Assert.assertTrue( publicFields.length > 0 ); for (final Field f : publicFields) { final int modifiers = f.getModifiers(); if ( (f.getType() == int.class) && Modifier.isPublic(modifiers) && Modifier.isFinal(modifiers) && Modifier.isStatic(modifiers) ) { final int iValue = f.getInt(null); final String text = EnglishReasonPhraseCatalog. INSTANCE.getReason(iValue, null); Assert.assertNotNull("text is null for HttpStatus."+f.getName(), text); Assert.assertTrue(text.length() > 0); } } }
@Test public void testStatusInvalid() throws Exception { try { EnglishReasonPhraseCatalog.INSTANCE.getReason(-1, null); Assert.fail("IllegalArgumentException must have been thrown (-1)"); } catch (final IllegalArgumentException expected) { } try { EnglishReasonPhraseCatalog.INSTANCE.getReason(99, null); Assert.fail("IllegalArgumentException must have been thrown (99)"); } catch (final IllegalArgumentException expected) { } try { EnglishReasonPhraseCatalog.INSTANCE.getReason(600, null); Assert.fail("IllegalArgumentException must have been thrown (600)"); } catch (final IllegalArgumentException expected) { } }
@Test public void testStatusAll() throws Exception { for (int i = 100; i < 600; i++) { EnglishReasonPhraseCatalog.INSTANCE.getReason(i, null); } }