diff --git a/persistence-modules/java-mongodb-3/src/main/java/com/baeldung/mongo/find/FindWithObjectId.java b/persistence-modules/java-mongodb-3/src/main/java/com/baeldung/mongo/find/FindWithObjectId.java index b82dcb6c5b..4e7dce2d72 100644 --- a/persistence-modules/java-mongodb-3/src/main/java/com/baeldung/mongo/find/FindWithObjectId.java +++ b/persistence-modules/java-mongodb-3/src/main/java/com/baeldung/mongo/find/FindWithObjectId.java @@ -25,7 +25,7 @@ public class FindWithObjectId { mongoClient = new MongoClient("localhost", 27017); databaseName = "baeldung"; - collectionName = "employee"; + collectionName = "vehicle"; database = mongoClient.getDatabase(databaseName); collection = database.getCollection(collectionName); diff --git a/persistence-modules/java-mongodb-3/src/test/java/com/baeldung/mongo/find/FindWithObjectIdLiveTest.java b/persistence-modules/java-mongodb-3/src/test/java/com/baeldung/mongo/find/FindWithObjectIdLiveTest.java index 590758855c..b8a34c809b 100644 --- a/persistence-modules/java-mongodb-3/src/test/java/com/baeldung/mongo/find/FindWithObjectIdLiveTest.java +++ b/persistence-modules/java-mongodb-3/src/test/java/com/baeldung/mongo/find/FindWithObjectIdLiveTest.java @@ -26,7 +26,7 @@ public class FindWithObjectIdLiveTest { private static MongoClient mongoClient; private static MongoDatabase database; private static MongoCollection collection; - private static final String DATASET_JSON = "/employee.json"; + private static final String DATASET_JSON = "/vehicle.json"; @BeforeClass public static void setUp() throws IOException { @@ -34,7 +34,7 @@ public class FindWithObjectIdLiveTest { mongoClient = new MongoClient("localhost", 27017); database = mongoClient.getDatabase("baeldung"); - collection = database.getCollection("employee"); + collection = database.getCollection("vehicle"); collection.drop(); @@ -47,10 +47,10 @@ public class FindWithObjectIdLiveTest { } @Test - public void givenEmployeeCollection_whenFetchingDocumentsUsingObjectId_thenCheckingForDocuments() { - Document employee = collection.find() + public void givenVehicleCollection_whenFetchingDocumentsUsingObjectId_thenCheckingForDocuments() { + Document vehicle = collection.find() .first(); - ObjectId objectId = (ObjectId) employee.get(OBJECT_ID_FIELD); + ObjectId objectId = (ObjectId) vehicle.get(OBJECT_ID_FIELD); FindIterable documents = collection.find(eq(OBJECT_ID_FIELD, objectId)); MongoCursor cursor = documents.iterator(); @@ -60,24 +60,24 @@ public class FindWithObjectIdLiveTest { } @Test - public void givenEmployeeCollection_whenFetchingFirstDocumentUsingObjectId_thenCheckingForDocument() { - Document employee = collection.find() + public void givenVehicleCollection_whenFetchingFirstDocumentUsingObjectId_thenCheckingForDocument() { + Document vehicle = collection.find() .first(); - ObjectId objectId = (ObjectId) employee.get(OBJECT_ID_FIELD); + ObjectId objectId = (ObjectId) vehicle.get(OBJECT_ID_FIELD); - Document queriedEmployee = collection.find(eq(OBJECT_ID_FIELD, objectId)) + Document queriedVehicle = collection.find(eq(OBJECT_ID_FIELD, objectId)) .first(); - assertNotNull(queriedEmployee); - assertEquals(employee.get(OBJECT_ID_FIELD), queriedEmployee.get(OBJECT_ID_FIELD)); + assertNotNull(queriedVehicle); + assertEquals(vehicle.get(OBJECT_ID_FIELD), queriedVehicle.get(OBJECT_ID_FIELD)); } @Test - public void givenEmployeeCollection_whenFetchingUsingRandomObjectId_thenCheckingForDocument() { - Document employee = collection.find(eq(OBJECT_ID_FIELD, new ObjectId())) + public void givenVehicleCollection_whenFetchingUsingRandomObjectId_thenCheckingForDocument() { + Document vehicle = collection.find(eq(OBJECT_ID_FIELD, new ObjectId())) .first(); - assertNull(employee); + assertNull(vehicle); } @AfterClass diff --git a/persistence-modules/java-mongodb-3/src/test/resources/vehicle.json b/persistence-modules/java-mongodb-3/src/test/resources/vehicle.json new file mode 100644 index 0000000000..567aba647f --- /dev/null +++ b/persistence-modules/java-mongodb-3/src/test/resources/vehicle.json @@ -0,0 +1,3 @@ +{"companyName":"Skoda","modelName":"Octavia","launchYear":2016,"type":"Sports","registeredNo":"SKO 1134"} +{"companyName":"BMW","modelName":"X5","launchYear":2020,"type":"SUV","registeredNo":"BMW 3325"} +{"companyName":"Mercedes","modelName":"Maybach","launchYear":2021,"type":"Luxury","registeredNo":"MER 9754"} \ No newline at end of file