Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unit Test suites for AsyncTasks #244

Merged
merged 10 commits into from
Aug 12, 2022
Prev Previous commit
Next Next commit
fixed checkpointResolution test
  • Loading branch information
sanyud24 committed Aug 11, 2022
commit f2e461e962aa34d03e8018ecf8247f806d2eac0e
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.opendatakit.database.service.DbHandle;
import org.opendatakit.services.database.OdkConnectionFactoryInterface;
import org.opendatakit.services.database.OdkConnectionFactorySingleton;
import org.opendatakit.services.resolve.listener.ResolutionListener;
Expand All @@ -26,8 +25,6 @@
import org.robolectric.annotation.Config;
import org.robolectric.shadows.ShadowEnvironment;

import java.util.UUID;

@RunWith(RobolectricTestRunner.class)
@Config(sdk = {Build.VERSION_CODES.O_MR1})
public class CheckpointResolutionListTaskTest {
Expand All @@ -39,24 +36,20 @@ public class CheckpointResolutionListTaskTest {
private ResolutionListener resolutionListener;
private ArrayAdapter<ResolveRowEntry> adapter;
private String mProgress;
DbHandle dbHandleName;
private OdkConnectionFactorySingleton odkConnectionFactorySingleton;

@Before
public void setUp() {
ShadowEnvironment.setExternalStorageState(Environment.MEDIA_MOUNTED);
OdkConnectionFactoryInterface odkConnectionFactoryInterface = mock(OdkConnectionFactoryInterface.class);
dbHandleName = new DbHandle(UUID.randomUUID().toString());

odkConnectionFactoryInterface.getConnection(APP_NAME,dbHandleName);
// odkConnectionFactorySingleton= mock(OdkConnectionFactorySingleton.class);
/* OdkConnectionFactoryInterface odkConnectionFactoryInterface = mock(OdkConnectionFactoryInterface.class);
when(OdkConnectionFactorySingleton.getOdkConnectionFactoryInterface()).thenReturn(odkConnectionFactorySingleton);
when(OdkConnectionFactorySingleton.set(odkConnectionFactoryInterface)).thenReturn(odkConnectionFactoryInterface);*/

OdkConnectionFactoryInterface odkConnectionFactoryInterface =mock(OdkConnectionFactoryInterface.class);
OdkConnectionFactorySingleton.set(odkConnectionFactoryInterface);
adapter = new ArrayAdapter<>(getContext(), 1);

checkpointResolutionListTask = new CheckpointResolutionListTask(getContext(), true, APP_NAME);
checkpointResolutionListTask.setResolveRowEntryAdapter(adapter);
checkpointResolutionListTask.execute();
resolutionListener = mock(ResolutionListener.class);
adapter = new ArrayAdapter<>(getContext(), 1);

resolutionListener =mock(ResolutionListener.class);
}

@Test
Expand All @@ -81,16 +74,10 @@ public void checkIfRowEntryAdapter_isResolved() {

}

@Test
public void checkIfResolutionListener_isAvailable() {
checkpointResolutionListTask.setResolutionListener(resolutionListener);
assertNotNull(resolutionListener);
checkpointResolutionListTask.clearResolutionListener(resolutionListener);
}
@After
public void tearDown() throws Exception {
System.out.println(checkpointResolutionListTask.getStatus());
checkpointResolutionListTask.cancel(true);
checkpointResolutionListTask.cancel(false);

}
private Context getContext() {
return InstrumentationRegistry.getInstrumentation().getTargetContext();
Expand Down