Skip to content

Commit 3680b37

Browse files
committed
chore: refactoring mongodb template
Signed-off-by: Otavio Santana <[email protected]>
1 parent 460cdc0 commit 3680b37

File tree

3 files changed

+26
-26
lines changed

3 files changed

+26
-26
lines changed
Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
import java.util.Objects;
2323

2424
@Entity
25-
public class MongoDBPerson {
25+
public class BirthdayPerson {
2626

2727
@Id
2828
private String name;
@@ -39,21 +39,21 @@ public Integer getAge() {
3939
return age;
4040
}
4141

42-
public MongoDBPerson(String name, Integer age) {
42+
public BirthdayPerson(String name, Integer age) {
4343
this.name = name;
4444
this.age = age;
4545
}
4646

47-
public MongoDBPerson() {
47+
public BirthdayPerson() {
4848
}
4949

5050
@Override
5151
public boolean equals(Object o) {
5252
if (this == o) return true;
5353
if (o == null || getClass() != o.getClass()) return false;
54-
MongoDBPerson mongoDBPerson = (MongoDBPerson) o;
55-
return Objects.equals(name, mongoDBPerson.name) &&
56-
Objects.equals(age, mongoDBPerson.age);
54+
BirthdayPerson birthdayPerson = (BirthdayPerson) o;
55+
return Objects.equals(name, birthdayPerson.name) &&
56+
Objects.equals(age, birthdayPerson.age);
5757
}
5858

5959
@Override

jnosql-mongodb/src/test/java/org/eclipse/jnosql/databases/mongodb/mapping/DefaultMongoDBTemplateTest.java

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ void shouldReturnErrorOnDeleteMethod() {
9191
assertThrows(NullPointerException.class,() -> template.delete("Collection", null));
9292
assertThrows(NullPointerException.class,() -> template.delete((String) null, filter));
9393

94-
assertThrows(NullPointerException.class,() -> template.delete(MongoDBPerson.class, null));
94+
assertThrows(NullPointerException.class,() -> template.delete(BirthdayPerson.class, null));
9595
assertThrows(NullPointerException.class,() -> template.delete((Class<Object>) null, filter));
9696
}
9797

@@ -105,15 +105,15 @@ void shouldDeleteWithCollectionName() {
105105
@Test
106106
void shouldDeleteWithEntity() {
107107
Bson filter = eq("name", "Poliana");
108-
template.delete(MongoDBPerson.class, filter);
108+
template.delete(BirthdayPerson.class, filter);
109109
Mockito.verify(manager).delete("Person", filter);
110110
}
111111

112112
@Test
113113
void shouldDeleteAll() {
114-
EntityMetadata metadata = entities.get(MongoDBPerson.class);
114+
EntityMetadata metadata = entities.get(BirthdayPerson.class);
115115
DeleteQuery query = DeleteQuery.delete().from(metadata.name()).build();
116-
template.deleteAll(MongoDBPerson.class);
116+
template.deleteAll(BirthdayPerson.class);
117117
Mockito.verify(manager).delete(query);
118118
}
119119

@@ -126,21 +126,21 @@ void shouldReturnErrorOnSelectMethod() {
126126
assertThrows(NullPointerException.class, () -> template.select((String) null, filter));
127127

128128
assertThrows(NullPointerException.class, () -> template.select((Class<?>) null, null));
129-
assertThrows(NullPointerException.class, () -> template.select(MongoDBPerson.class, null));
129+
assertThrows(NullPointerException.class, () -> template.select(BirthdayPerson.class, null));
130130
assertThrows(NullPointerException.class, () -> template.select((Class<?>) null, filter));
131131
}
132132

133133
@Test
134134
void shouldSelectWithCollectionName() {
135-
var entity = CommunicationEntity.of("Person", Arrays
135+
var entity = CommunicationEntity.of("BirthdayPerson", Arrays
136136
.asList(Element.of("_id", "Poliana"),
137137
Element.of("age", 30)));
138138
Bson filter = eq("name", "Poliana");
139139
Mockito.when(manager.select("Person", filter))
140140
.thenReturn(Stream.of(entity));
141-
Stream<MongoDBPerson> stream = template.select("Person", filter);
141+
Stream<BirthdayPerson> stream = template.select("Person", filter);
142142
Assertions.assertNotNull(stream);
143-
MongoDBPerson poliana = stream.findFirst()
143+
BirthdayPerson poliana = stream.findFirst()
144144
.orElseThrow(() -> new IllegalStateException("There is an issue on the test"));
145145

146146
Assertions.assertNotNull(poliana);
@@ -150,15 +150,15 @@ void shouldSelectWithCollectionName() {
150150

151151
@Test
152152
void shouldSelectWithEntity() {
153-
var entity = CommunicationEntity.of("Person", Arrays
153+
var entity = CommunicationEntity.of("BirthdayPerson", Arrays
154154
.asList(Element.of("_id", "Poliana"),
155155
Element.of("age", 30)));
156156
Bson filter = eq("name", "Poliana");
157157
Mockito.when(manager.select("Person", filter))
158158
.thenReturn(Stream.of(entity));
159-
Stream<MongoDBPerson> stream = template.select(MongoDBPerson.class, filter);
159+
Stream<BirthdayPerson> stream = template.select(BirthdayPerson.class, filter);
160160
Assertions.assertNotNull(stream);
161-
MongoDBPerson poliana = stream.findFirst()
161+
BirthdayPerson poliana = stream.findFirst()
162162
.orElseThrow(() -> new IllegalStateException("There is an issue on the test"));
163163

164164
Assertions.assertNotNull(poliana);
@@ -188,8 +188,8 @@ void shouldReturnErrorOnAggregateMethod() {
188188
assertThrows(NullPointerException.class, () -> template.aggregate((String) null, pipeline));
189189
assertThrows(NullPointerException.class, () -> template.aggregate((String) null, pipelineArray));
190190
assertThrows(NullPointerException.class, () -> template.aggregate((String) null, bson));
191-
assertThrows(NullPointerException.class, () -> template.aggregate(MongoDBPerson.class, (List<Bson>) null));
192-
assertThrows(NullPointerException.class, () -> template.aggregate(MongoDBPerson.class, (Bson[]) null));
191+
assertThrows(NullPointerException.class, () -> template.aggregate(BirthdayPerson.class, (List<Bson>) null));
192+
assertThrows(NullPointerException.class, () -> template.aggregate(BirthdayPerson.class, (Bson[]) null));
193193

194194
}
195195

@@ -211,7 +211,7 @@ void shouldAggregateWithEntity() {
211211
Aggregates.group("$stars", Accumulators.sum("count", 1))
212212
};
213213

214-
template.aggregate(MongoDBPerson.class, predicates);
214+
template.aggregate(BirthdayPerson.class, predicates);
215215
Mockito.verify(manager).aggregate("Person", predicates);
216216
}
217217

@@ -228,7 +228,7 @@ void shouldCountByFilterWithCollectionName() {
228228
void shouldCountByFilterWithEntity() {
229229
var filter = eq("name", "Poliana");
230230

231-
template.count(MongoDBPerson.class, filter);
231+
template.count(BirthdayPerson.class, filter);
232232

233233
Mockito.verify(manager).count("Person", filter);
234234
}
@@ -239,8 +239,8 @@ void shouldReturnErrorOnCountByFilterMethod() {
239239
assertThrows(NullPointerException.class, () -> template.count((String) null, null));
240240
assertThrows(NullPointerException.class, () -> template.count((String) null, filter));
241241
assertThrows(NullPointerException.class, () -> template.count("Person", null));
242-
assertThrows(NullPointerException.class, () -> template.count((Class<MongoDBPerson>) null, null));
243-
assertThrows(NullPointerException.class, () -> template.count((Class<MongoDBPerson>) null, filter));
244-
assertThrows(NullPointerException.class, () -> template.count(MongoDBPerson.class, null));
242+
assertThrows(NullPointerException.class, () -> template.count((Class<BirthdayPerson>) null, null));
243+
assertThrows(NullPointerException.class, () -> template.count((Class<BirthdayPerson>) null, filter));
244+
assertThrows(NullPointerException.class, () -> template.count(BirthdayPerson.class, null));
245245
}
246246
}
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
query.1=insert mongoDBPerson {"_id": 1, "name": "Diana"}
2-
query.2=insert mongoDBPerson {"_id": 2, "name": "Artemis"}
1+
query.1=insert birthdayPerson {"_id": 1, "name": "Diana"}
2+
query.2=insert birthdayPerson {"_id": 2, "name": "Artemis"}
33
id.name=_id

0 commit comments

Comments
 (0)