Skip to content

Commit

Permalink
fix test
Browse files Browse the repository at this point in the history
  • Loading branch information
MikhailSuendukov committed Aug 17, 2023
1 parent e1f44b5 commit b5df261
Showing 1 changed file with 7 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,9 @@
import org.json.JSONObject;
import org.json.JSONStringer;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.powermock.core.classloader.annotations.PrepareForTest;
import org.powermock.modules.junit4.PowerMockRunner;

import java.util.Date;
import java.util.UUID;
Expand All @@ -33,15 +35,14 @@
import static org.mockito.Mockito.never;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
import static org.powermock.api.mockito.PowerMockito.mockStatic;
import static org.powermock.api.mockito.PowerMockito.verifyStatic;

@SuppressWarnings("unused")
@RunWith(PowerMockRunner.class)
@PrepareForTest({ JSONUtils.class })
public class AbstractLogTest {

@PrepareForTest({
JSONUtils.class
})

@SuppressWarnings("InstantiationOfUtilityClass")
@Test
public void utilsCoverage() {
Expand Down Expand Up @@ -187,16 +188,13 @@ public void readNotNullDataResidencyRegionTest() throws JSONException {
mockLog.read(mockJsonObject);

assertEquals(dataResidencyRegion, mockLog.getDataResidencyRegion());

// Additional verification to ensure mock interactions
verify(mockJsonObject).has(DATA_RESIDENCY_REGION);
verify(mockJsonObject).optString(DATA_RESIDENCY_REGION, null);
}


@Test
public void writeNotNullDataResidencyRegionTest() throws JSONException {
JSONStringer mockJsonStringer = mock(JSONStringer.class);
mockStatic(JSONUtils.class);
when(mockJsonStringer.key(anyString())).thenReturn(mockJsonStringer);
when(mockJsonStringer.value(anyString())).thenReturn(mockJsonStringer);

Expand All @@ -205,9 +203,8 @@ public void writeNotNullDataResidencyRegionTest() throws JSONException {
mockLog.setDataResidencyRegion("RG");
mockLog.write(mockJsonStringer);


verifyStatic(JSONUtils.class);
JSONUtils.write(mockJsonStringer, DATA_RESIDENCY_REGION, anyString());
JSONUtils.write(mockJsonStringer, DATA_RESIDENCY_REGION, "RG");
}

private static class MockLog extends AbstractLog {
Expand Down

0 comments on commit b5df261

Please sign in to comment.