Unit test for TupleDesc.nameToId()
()
| 87 | * Unit test for TupleDesc.nameToId() |
| 88 | */ |
| 89 | @Test public void nameToId() { |
| 90 | int[] lengths = new int[] { 1, 2, 1000 }; |
| 91 | String prefix = "test"; |
| 92 | |
| 93 | for (int len: lengths) { |
| 94 | // Make sure you retrieve well-named fields |
| 95 | TupleDesc td = Utility.getTupleDesc(len, prefix); |
| 96 | for (int i = 0; i < len; ++i) { |
| 97 | assertEquals(i, td.fieldNameToIndex(prefix + i)); |
| 98 | } |
| 99 | |
| 100 | // Make sure you throw exception for non-existent fields |
| 101 | try { |
| 102 | td.fieldNameToIndex("foo"); |
| 103 | Assert.fail("foo is not a valid field name"); |
| 104 | } catch (NoSuchElementException e) { |
| 105 | // expected to get here |
| 106 | } |
| 107 | |
| 108 | // Make sure you throw exception for null searches |
| 109 | try { |
| 110 | td.fieldNameToIndex(null); |
| 111 | Assert.fail("null is not a valid field name"); |
| 112 | } catch (NoSuchElementException e) { |
| 113 | // expected to get here |
| 114 | } |
| 115 | |
| 116 | // Make sure you throw exception when all field names are null |
| 117 | td = Utility.getTupleDesc(len); |
| 118 | try { |
| 119 | td.fieldNameToIndex(prefix); |
| 120 | Assert.fail("no fields are named, so you can't find it"); |
| 121 | } catch (NoSuchElementException e) { |
| 122 | // expected to get here |
| 123 | } |
| 124 | } |
| 125 | } |
| 126 | |
| 127 | /** |
| 128 | * Unit test for TupleDesc.getSize() |
nothing calls this directly
no test coverage detected