Skip to content

Commit

Permalink
fix: sonar
Browse files Browse the repository at this point in the history
  • Loading branch information
lucas-myx committed Jan 5, 2024
1 parent 1344e44 commit c638bc9
Show file tree
Hide file tree
Showing 9 changed files with 25 additions and 25 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -56,10 +56,10 @@ public DatabaseExtractor(String dbName, String sql, String parameters, String me
this.methodName = methodName;
}

public void record(Object response) {
record(response, null);
public void recordDb(Object response) {
recordDb(response, null);
}
public void record(Object response, String serializer) {
public void recordDb(Object response, String serializer) {
MockUtils.recordMocker(makeMocker(response, serializer));
}

Expand All @@ -68,7 +68,7 @@ public MockResult replay() {
}

public MockResult replay(String serializer) {
// TODO: update after all dal components have obtained the real dbName
// update after all dal components have obtained the real dbName(temporary solution)
boolean ignoreMockResult = IgnoreUtils.ignoreMockResult("database", methodName);
Mocker replayMocker = MockUtils.replayMocker(makeMocker(null, serializer));
Object replayResult = null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ void record() {
return null;
});

target.record(new Object());
target.recordDb(new Object());
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,9 +105,9 @@ public static void onExit(

if (ContextManager.needRecord()) {
if (throwable != null) {
extractor.record(throwable);
extractor.recordDb(throwable);
} else {
extractor.record(serializable);
extractor.recordDb(serializable);
}
}
}
Expand Down Expand Up @@ -151,9 +151,9 @@ public static void onExit(
if (ContextManager.needRecord()) {
DatabaseExtractor extractor = new DatabaseExtractor(sql, object, METHOD_NAME_UPDATE);
if (throwable != null) {
extractor.record(throwable);
extractor.recordDb(throwable);
} else {
extractor.record(0);
extractor.recordDb(0);
}
}
}
Expand Down Expand Up @@ -196,9 +196,9 @@ public static void onExit(
if (ContextManager.needRecord()) {
DatabaseExtractor extractor = new DatabaseExtractor(sql, object, METHOD_NAME_DELETE);
if (throwable != null) {
extractor.record(throwable);
extractor.recordDb(throwable);
} else {
extractor.record(0);
extractor.recordDb(0);
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,9 +78,9 @@ public static void onExit(@Advice.This Loader loader,
}
if (ContextManager.needRecord()) {
if (throwable != null) {
extractor.record(throwable);
extractor.recordDb(throwable);
} else {
extractor.record(list);
extractor.recordDb(list);
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ void onUpdateOrInsertExit(Runnable recordType, Object mockResult) {
mo.set(mock);
})){
recordType.run();
Mockito.verify(mo.get(), Mockito.times(1)).record(isA(mockResult.getClass()));
Mockito.verify(mo.get(), Mockito.times(1)).recordDb(isA(mockResult.getClass()));
}
}

Expand Down Expand Up @@ -190,7 +190,7 @@ void onDeleteExit(Runnable recordType, Object mockResult) {
mo.set(mock);
})){
recordType.run();
Mockito.verify(mo.get(), Mockito.times(1)).record(isA(mockResult.getClass()));
Mockito.verify(mo.get(), Mockito.times(1)).recordDb(isA(mockResult.getClass()));
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,10 @@ public static void record(String methodName, MongoNamespace namespace, Object fi
String parameter = Serializer.serialize(filter, GSON_SERIALIZER);
final DatabaseExtractor extractor = new DatabaseExtractor(dbName, methodName, parameter, methodName);
if (throwable != null) {
extractor.record(throwable, GSON_SERIALIZER);
extractor.recordDb(throwable, GSON_SERIALIZER);
return;
}
Object actualResult = ResultWrapper.wrap(result);
extractor.record(actualResult, GSON_SERIALIZER);
extractor.recordDb(actualResult, GSON_SERIALIZER);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -65,10 +65,10 @@ void replay() {
void record() {
try(final MockedConstruction<DatabaseExtractor> construction = Mockito.mockConstruction(DatabaseExtractor.class)) {
MongoHelper.record("test", Mockito.mock(MongoNamespace.class), null, "test", null);
Mockito.verify(construction.constructed().get(0), Mockito.times(1)).record("test", "gson");
Mockito.verify(construction.constructed().get(0), Mockito.times(1)).recordDb("test", "gson");
final RuntimeException runtimeException = new RuntimeException();
MongoHelper.record("test", Mockito.mock(MongoNamespace.class), null, "test", runtimeException);
Mockito.verify(construction.constructed().get(1), Mockito.times(1)).record(runtimeException, "gson");
Mockito.verify(construction.constructed().get(1), Mockito.times(1)).recordDb(runtimeException, "gson");
}

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,9 @@ public static MockResult replay(DatabaseExtractor extractor, MappedStatement ms,
public static <U> void record(MappedStatement ms, Object o, String originalSql, U result, Throwable throwable, String methodName) {
DatabaseExtractor extractor = createExtractor(ms, originalSql, o, methodName);
if (throwable != null) {
extractor.record(throwable);
extractor.recordDb(throwable);
} else {
extractor.record(result);
extractor.recordDb(result);
}
}

Expand All @@ -43,9 +43,9 @@ public static <U> void record(DatabaseExtractor extractor,
}

if (throwable != null) {
extractor.record(throwable);
extractor.recordDb(throwable);
} else {
extractor.record(result);
extractor.recordDb(result);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,9 +98,9 @@ void record(Throwable throwable, Object result) {
Mockito.when(mappedStatement.getBoundSql(any())).thenReturn(boundSql);
target.record(mappedStatement, new Object(), null, result, throwable, "insert");
if (throwable != null) {
Mockito.verify(atomicReference.get(), Mockito.times(1)).record(throwable);
Mockito.verify(atomicReference.get(), Mockito.times(1)).recordDb(throwable);
} else {
Mockito.verify(atomicReference.get(), Mockito.times(1)).record(result);
Mockito.verify(atomicReference.get(), Mockito.times(1)).recordDb(result);
}
}
}
Expand Down

0 comments on commit c638bc9

Please sign in to comment.