Skip to content
Snippets Groups Projects
Verified Commit 5dcd5f79 authored by Torsten Grote's avatar Torsten Grote
Browse files

Test PasswordFragment account creation individually

parent 8a811717
No related branches found
No related tags found
No related merge requests found
...@@ -35,6 +35,7 @@ dependencies { ...@@ -35,6 +35,7 @@ dependencies {
testCompile project(path: ':bramble-core', configuration: 'testOutput') testCompile project(path: ':bramble-core', configuration: 'testOutput')
testCompile 'org.robolectric:robolectric:3.0' testCompile 'org.robolectric:robolectric:3.0'
testCompile 'org.robolectric:shadows-support-v4:3.0'
testCompile 'org.mockito:mockito-core:2.8.9' testCompile 'org.mockito:mockito-core:2.8.9'
} }
......
package org.briarproject.briar.android.login;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import org.briarproject.briar.BuildConfig;
import org.briarproject.briar.R;
import org.briarproject.briar.android.TestBriarApplication;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mock;
import org.mockito.MockitoAnnotations;
import org.robolectric.RobolectricGradleTestRunner;
import org.robolectric.annotation.Config;
import static junit.framework.Assert.assertEquals;
import static org.briarproject.bramble.api.crypto.PasswordStrengthEstimator.STRONG;
import static org.mockito.ArgumentMatchers.anyString;
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
import static org.robolectric.shadows.support.v4.SupportFragmentTestUtil.startFragment;
@RunWith(RobolectricGradleTestRunner.class)
@Config(constants = BuildConfig.class, sdk = 21,
application = TestBriarApplication.class,
packageName = "org.briarproject.briar")
public class PasswordFragmentTest {
private PasswordFragment passwordFragment = new PasswordFragment();
private EditText passwordEntry;
private EditText passwordConfirmation;
private Button createAccountButton;
@Mock
private SetupController setupController;
@Before
public void setUp() {
MockitoAnnotations.initMocks(this);
startFragment(passwordFragment, SetupActivity.class);
View v = passwordFragment.getView();
passwordEntry = (EditText) v.findViewById(R.id.password_entry);
passwordConfirmation = (EditText) v.findViewById(R.id.password_confirm);
createAccountButton = (Button) v.findViewById(R.id.next);
}
@Test
public void testCreateAccountUI() {
passwordFragment.setupController = setupController;
when(setupController.needsDozeWhitelisting()).thenReturn(false);
when(setupController.estimatePasswordStrength(anyString()))
.thenReturn(STRONG);
String safePass = "really.safe.password";
passwordEntry.setText(safePass);
passwordConfirmation.setText(safePass);
// Confirm that the create account button is clickable
assertEquals(createAccountButton.isEnabled(), true);
createAccountButton.performClick();
// assert controller has been called properly
verify(setupController, times(1))
.setPassword(safePass);
verify(setupController, times(1))
.showDozeOrCreateAccount();
}
}
package org.briarproject.briar.android.login; package org.briarproject.briar.android.login;
import android.content.Context; import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences; import android.content.SharedPreferences;
import android.support.design.widget.TextInputLayout; import android.support.design.widget.TextInputLayout;
import android.widget.Button; import android.widget.Button;
...@@ -14,7 +13,6 @@ import org.briarproject.briar.BuildConfig; ...@@ -14,7 +13,6 @@ import org.briarproject.briar.BuildConfig;
import org.briarproject.briar.R; import org.briarproject.briar.R;
import org.briarproject.briar.android.TestBriarApplication; import org.briarproject.briar.android.TestBriarApplication;
import org.briarproject.briar.android.controller.handler.ResultHandler; import org.briarproject.briar.android.controller.handler.ResultHandler;
import org.briarproject.briar.android.navdrawer.NavDrawerActivity;
import org.junit.Assert; import org.junit.Assert;
import org.junit.Before; import org.junit.Before;
import org.junit.Test; import org.junit.Test;
...@@ -23,11 +21,8 @@ import org.mockito.MockitoAnnotations; ...@@ -23,11 +21,8 @@ import org.mockito.MockitoAnnotations;
import org.robolectric.Robolectric; import org.robolectric.Robolectric;
import org.robolectric.RobolectricGradleTestRunner; import org.robolectric.RobolectricGradleTestRunner;
import org.robolectric.annotation.Config; import org.robolectric.annotation.Config;
import org.robolectric.shadows.ShadowActivity;
import org.robolectric.shadows.ShadowLooper;
import static junit.framework.Assert.assertEquals; import static junit.framework.Assert.assertEquals;
import static junit.framework.Assert.assertNotNull;
import static org.briarproject.bramble.api.crypto.PasswordStrengthEstimator.NONE; import static org.briarproject.bramble.api.crypto.PasswordStrengthEstimator.NONE;
import static org.briarproject.bramble.api.crypto.PasswordStrengthEstimator.QUITE_STRONG; import static org.briarproject.bramble.api.crypto.PasswordStrengthEstimator.QUITE_STRONG;
import static org.briarproject.bramble.api.crypto.PasswordStrengthEstimator.QUITE_WEAK; import static org.briarproject.bramble.api.crypto.PasswordStrengthEstimator.QUITE_WEAK;
...@@ -37,7 +32,6 @@ import static org.junit.Assert.assertTrue; ...@@ -37,7 +32,6 @@ import static org.junit.Assert.assertTrue;
import static org.mockito.Mockito.mock; import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.timeout; import static org.mockito.Mockito.timeout;
import static org.mockito.Mockito.verify; import static org.mockito.Mockito.verify;
import static org.robolectric.Shadows.shadowOf;
@RunWith(RobolectricGradleTestRunner.class) @RunWith(RobolectricGradleTestRunner.class)
@Config(constants = BuildConfig.class, sdk = 21, @Config(constants = BuildConfig.class, sdk = 21,
...@@ -98,32 +92,6 @@ public class SetupActivityTest { ...@@ -98,32 +92,6 @@ public class SetupActivityTest {
assertEquals(createAccountButton.isEnabled(), true); assertEquals(createAccountButton.isEnabled(), true);
} }
@Test
public void testCreateAccountUI() {
proceedToPasswordFragment();
String safePass = "really.safe.password";
passwordEntry.setText(safePass);
passwordConfirmation.setText(safePass);
// Confirm that the create account button is clickable
assertEquals(createAccountButton.isEnabled(), true);
createAccountButton.performClick();
// wait a second since there's no easy way to get a callback
try {
Thread.sleep(1000);
} catch (InterruptedException e) {
e.printStackTrace();
}
ShadowLooper.runUiThreadTasks();
// execute the callback
assertTrue(setupActivity.isFinishing());
// Confirm that the correct Activity has been started
ShadowActivity shadowActivity = shadowOf(setupActivity);
Intent intent = shadowActivity.peekNextStartedActivity();
assertNotNull(intent.getComponent());
assertEquals(intent.getComponent().getClassName(),
NavDrawerActivity.class.getName());
}
@Test @Test
public void testAccountCreation() { public void testAccountCreation() {
SetupController controller = setupActivity.getController(); SetupController controller = setupActivity.getController();
......
...@@ -10,7 +10,4 @@ public class TestSetupActivity extends SetupActivity { ...@@ -10,7 +10,4 @@ public class TestSetupActivity extends SetupActivity {
return setupController; return setupController;
} }
void setController(SetupController setupController) {
this.setupController = setupController;
}
} }
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment