Skip to content

Commit a2f48ff

Browse files
author
mekjaer
committed
enabled test for table.lookup. Throws more specific exceptions. Non-breaking as they are subclasses of RuntimeException
1 parent 80ba759 commit a2f48ff

4 files changed

Lines changed: 23 additions & 16 deletions

File tree

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,3 +104,5 @@ tightdb_jni/src/java/lib/l*
104104
java/share/java/*.jar
105105

106106

107+
# when building lib on mac
108+
tightdb_jni/src/*.dylib

pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
<groupId>com.tightdb</groupId>
77
<artifactId>tightdb-parent</artifactId>
8-
<version>0.1.2</version>
8+
<version>0.1.3</version>
99
<packaging>pom</packaging>
1010

1111
<properties>

tightdb-java-core/src/main/java/com/tightdb/Table.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1146,9 +1146,9 @@ public TableView findAllString(long columnIndex, String value) {
11461146
@Override
11471147
public long lookup(String value) {
11481148
if (value == null)
1149-
throw new RuntimeException("String must not be null");
1149+
throw new NullPointerException("String must not be null");
11501150
if (this.getColumnType(0) != ColumnType.STRING)
1151-
throw new RuntimeException("lookup() requires a String column.");
1151+
throw new UnsupportedOperationException("lookup() requires a String column.");
11521152
return nativeLookup(nativePtr, value);
11531153
}
11541154

tightdb-java-test/src/test/java/com/tightdb/JNITableTest.java

Lines changed: 18 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -121,41 +121,46 @@ public void tableBinaryTest() {
121121
try { t.setBinaryByteArray(0, 2, nullByte); fail("Inserting null array"); } catch(NullPointerException e) { }
122122
}
123123

124-
/*
124+
125125
@Test
126126
public void lookupTableTest() {
127127
Table t = new Table();
128128

129-
t.addColumn(ColumnType.STRING, "col0");
130-
t.addColumn(ColumnType.INTEGER, "col1");
129+
long STRING_COL_INDEX = t.addColumn(ColumnType.STRING, "col0");
130+
long INT_COL_INDEX = t.addColumn(ColumnType.INTEGER, "col1");
131131

132132
t.add("s", 1);
133133
t.add("s", 2);
134134
t.add("ss",1);
135135
t.add("ss", 2);
136+
t.add("", 2);
136137

137-
// Currently lookup works, even if no index has been set on first string column. Shouldn't there be an index? TODO
138-
// try { t.lookup("ss"); fail("Index not set"); } catch (RuntimeException r) { };
139-
138+
assertEquals(0, t.lookup("s"));
140139
assertEquals(2, t.lookup("ss"));
140+
assertEquals(4, t.lookup(""));
141+
142+
assertEquals(false, t.hasIndex(STRING_COL_INDEX));
141143

144+
//try setting an index
142145
t.setIndex(0);
143-
long rowIndex = t.lookup("ss");
144-
assertEquals(1, t.getLong(1, rowIndex));
146+
assertEquals(0, t.lookup("s"));
147+
assertEquals(2, t.lookup("ss"));
148+
assertEquals(4, t.lookup(""));
145149

146-
Table t2 = new Table();
150+
// null lookup value
151+
try { t.lookup(null); fail("lookup value is null"); } catch (NullPointerException r) { };
152+
147153

154+
// Try with non string column
155+
Table t2 = new Table();
148156
t2.addColumn(ColumnType.INTEGER, "col0");
149157
t2.addColumn(ColumnType.INTEGER, "col1");
150-
151158
t2.add(1, 2);
152159
t2.add(3, 4);
153160

154-
try { t2.lookup("ss"); fail("Column not String"); } catch (RuntimeException r) { };
161+
try { t2.lookup("ss"); fail("Column not String"); } catch (UnsupportedOperationException r) { };
155162
}
156163

157-
*/
158-
159164

160165
@Test
161166
public void getValuesFromNonExistingColumn() {

0 commit comments

Comments
 (0)