Skip to content

Commit 1ac438c

Browse files
committed
Test new default methods
This isn't the greatest test, but I think the proper test would be to explicitly list the non-default methods and then use reflection and error if any new methods are added and don't have a default implementation.
1 parent a36a55e commit 1ac438c

File tree

2 files changed

+24
-2
lines changed
  • fdb-record-layer-core/src

2 files changed

+24
-2
lines changed

fdb-record-layer-core/src/main/java/com/apple/foundationdb/record/provider/foundationdb/keyspace/KeySpacePath.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -592,8 +592,8 @@ default List<ResolvedKeySpacePath> listSubdirectory(@Nonnull FDBRecordContext co
592592
@API(API.Status.EXPERIMENTAL)
593593
@Nonnull
594594
default RecordCursor<DataInKeySpacePath> exportAllData(@Nonnull FDBRecordContext context,
595-
@Nullable byte[] continuation,
596-
@Nonnull ScanProperties scanProperties) {
595+
@Nullable byte[] continuation,
596+
@Nonnull ScanProperties scanProperties) {
597597
throw new UnsupportedOperationException("exportAllData is not supported");
598598
}
599599
}

fdb-record-layer-core/src/test/java/com/apple/foundationdb/record/provider/foundationdb/keyspace/KeySpacePathTest.java

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
package com.apple.foundationdb.record.provider.foundationdb.keyspace;
2222

2323
import com.apple.foundationdb.record.RecordCoreArgumentException;
24+
import com.apple.foundationdb.record.ScanProperties;
2425
import com.apple.foundationdb.record.provider.foundationdb.FDBDatabase;
2526
import com.apple.foundationdb.record.provider.foundationdb.FDBRecordContext;
2627
import com.apple.foundationdb.record.test.FDBDatabaseExtension;
@@ -29,6 +30,7 @@
2930
import org.junit.jupiter.api.Test;
3031
import org.junit.jupiter.api.extension.RegisterExtension;
3132
import org.junit.jupiter.params.ParameterizedTest;
33+
import org.mockito.Mockito;
3234

3335
import java.util.UUID;
3436
import java.util.concurrent.ExecutionException;
@@ -191,4 +193,24 @@ void testToResolvedPathAsyncWithInvalidTuple() {
191193
});
192194
}
193195
}
196+
197+
/**
198+
* Test of methods with default implementations to ensure backwards compatibility,
199+
* in case someone is implementing {@link KeySpacePath}.
200+
**/
201+
@Test
202+
void testDefaultMethods() {
203+
final KeySpacePath mock = Mockito.mock(KeySpacePath.class);
204+
final FDBDatabase database = dbExtension.getDatabase();
205+
206+
try (FDBRecordContext context = database.openContext()) {
207+
// thenCallReadMethod throws an error if there is not a default implementation
208+
Mockito.when(mock.toResolvedPathAsync(Mockito.any(), Mockito.any())).thenCallRealMethod();
209+
assertThrows(UnsupportedOperationException.class,
210+
() -> mock.toResolvedPathAsync(context, Tuple.from("foo").pack()));
211+
Mockito.when(mock.exportAllData(Mockito.any(), Mockito.any(), Mockito.any())).thenCallRealMethod();
212+
assertThrows(UnsupportedOperationException.class,
213+
() -> mock.exportAllData(context, null, ScanProperties.FORWARD_SCAN));
214+
}
215+
}
194216
}

0 commit comments

Comments
 (0)