private void checkPair(String dateStr) { int id = dict.getIdFromValue(dateStr); String dateStrBack = dict.getValueFromId(id); assertEquals(dateStr, dateStrBack); }
@Test public void testNull() { int nullId = dict.getIdFromValue(null); assertNull(dict.getValueFromId(nullId)); }
@Test public void testIllegalArgument() { try { dict.getIdFromValue("abcd"); fail("IllegalArgumentException expected"); } catch (IllegalArgumentException e) { // good } try { dict.getValueFromId(-2); fail("IllegalArgumentException expected"); } catch (IllegalArgumentException e) { // good } }
@Test public void testMinMaxId() { assertEquals(0, dict.getIdFromValue("0000-01-01")); assertEquals(DateDimEnc.ID_9999_12_31, dict.getIdFromValue("9999-12-31")); try { dict.getValueFromId(-2); // -1 is id for NULL fail("IllegalArgumentException expected"); } catch (IllegalArgumentException e) { // good } try { dict.getValueFromId(DateDimEnc.ID_9999_12_31 + 1); fail("IllegalArgumentException expected"); } catch (IllegalArgumentException e) { // good } try { dict.getIdFromValue("10000-1-1"); fail("IllegalArgumentException expected"); } catch (IllegalArgumentException e) { // good } }
@Override final protected int getValueBytesFromIdImpl(int id, byte[] returnValue, int offset) { String date = getValueFromId(id); byte bytes[]; try { bytes = date.getBytes("ISO-8859-1"); } catch (UnsupportedEncodingException e) { throw new RuntimeException(e); // never happen } System.arraycopy(bytes, 0, returnValue, offset, bytes.length); return bytes.length; }
private void checkPair(String dateStr) { int id = dict.getIdFromValue(dateStr); String dateStrBack = dict.getValueFromId(id); assertEquals(dateStr, dateStrBack); } }
@Test public void testIllegalArgument() { try { dict.getIdFromValue("abcd"); fail("IllegalArgumentException expected"); } catch (IllegalArgumentException e) { // good } try { dict.getValueFromId(-2); fail("IllegalArgumentException expected"); } catch (IllegalArgumentException e) { // good } }
@Test public void testMinMaxId() { assertEquals(0, dict.getIdFromValue("0000-01-01")); assertEquals(DateStrDictionary.ID_9999_12_31, dict.getIdFromValue("9999-12-31")); try { dict.getValueFromId(-2); // -1 is id for NULL fail("IllegalArgumentException expected"); } catch (IllegalArgumentException e) { // good } try { dict.getValueFromId(DateStrDictionary.ID_9999_12_31 + 1); fail("IllegalArgumentException expected"); } catch (IllegalArgumentException e) { // good } try { dict.getIdFromValue("10000-1-1"); fail("IllegalArgumentException expected"); } catch (IllegalArgumentException e) { // good } }
@Test public void testNull() { int nullId = dict.getIdFromValue(null); assertNull(dict.getValueFromId(nullId)); int nullId2 = dict.getIdFromValueBytes(null, 0, 0); assertEquals(dict.getValueBytesFromId(nullId2, null, 0), -1); assertEquals(nullId, nullId2); }
@Override final protected int getValueBytesFromIdImpl(int id, byte[] returnValue, int offset) { String date = getValueFromId(id); byte bytes[]; try { bytes = date.getBytes("ISO-8859-1"); } catch (UnsupportedEncodingException e) { throw new RuntimeException(e); // never happen } System.arraycopy(bytes, 0, returnValue, offset, bytes.length); return bytes.length; }