androidx.test.platform.app.InstrumentationRegistry Java Examples

The following examples show how to use androidx.test.platform.app.InstrumentationRegistry. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: TestDateUtils.java    From joda-time-android with Apache License 2.0 6 votes vote down vote up
@Test
public void testGetRelativeTimeSpanStringWithPreposition() {
    Context ctx = InstrumentationRegistry.getInstrumentation().getContext();

    LocalDate today = LocalDate.now();
    LocalDate tomorrow = today.plusDays(1);
    LocalDate nextYear = today.plusYears(1);

    assertEquals("12:35", DateUtils.getRelativeTimeSpanString(ctx, today, false));
    assertEquals("at 12:35", DateUtils.getRelativeTimeSpanString(ctx, today, true));
    assertEquals("Oct 23, 1995", DateUtils.getRelativeTimeSpanString(ctx, tomorrow, false));
    assertEquals("on Oct 23, 1995", DateUtils.getRelativeTimeSpanString(ctx, tomorrow, true));
    assertEquals("10/22/1996", DateUtils.getRelativeTimeSpanString(ctx, nextYear, false));
    assertEquals("on 10/22/1996", DateUtils.getRelativeTimeSpanString(ctx, nextYear, true));

    DateTime todayDt = DateTime.now();
    DateTime tomorrowDt = todayDt.plusDays(1);
    DateTime nextYearDt = todayDt.plusYears(1);

    assertEquals("12:35", DateUtils.getRelativeTimeSpanString(ctx, todayDt, false));
    assertEquals("at 12:35", DateUtils.getRelativeTimeSpanString(ctx, todayDt, true));
    assertEquals("Oct 23, 1995", DateUtils.getRelativeTimeSpanString(ctx, tomorrowDt, false));
    assertEquals("on Oct 23, 1995", DateUtils.getRelativeTimeSpanString(ctx, tomorrowDt, true));
    assertEquals("10/22/1996", DateUtils.getRelativeTimeSpanString(ctx, nextYearDt, false));
    assertEquals("on 10/22/1996", DateUtils.getRelativeTimeSpanString(ctx, nextYearDt, true));
}
 
Example #2
Source File: AuthenticatorActivityPart2Test.java    From google-authenticator-android with Apache License 2.0 6 votes vote down vote up
@Test
public void testDirectAccountSetupWithConfirmationRejected() throws Throwable {
  // start AuthenticatorActivity with a valid Uri for account setup.
  String secret = "CQAHUXJ2VWDI7WFF";
  String accountName = "9.99.99.999";
  AccountIndex index = new AccountIndex(accountName, null); // Use a null issuer for now
  activityTestRule.launchActivity(
      new Intent(
          Intent.ACTION_VIEW, Uri.parse("otpauth://totp/" + accountName + "?secret=" + secret)));
  // check main screen does not have focus because of save confirmation dialog.
  View contentView = activityTestRule.getActivity().findViewById(R.id.content_no_accounts);
  assertThat(contentView.hasWindowFocus()).isFalse();
  // click Cancel on the save confirmation dialog box.
  TestUtilities.tapDialogNegativeButton(InstrumentationRegistry.getInstrumentation());
  // check main screen gets focus back after dialog window disappears.
  TestUtilities.waitForWindowFocus(contentView);
  // check database has not been updated.
  assertThat(mAccountDb.getAccounts()).isEmpty();
  assertThat(mAccountDb.getSecret(index)).isNull();
}
 
Example #3
Source File: PreprocessTest.java    From cloudinary_android with MIT License 6 votes vote down vote up
@Ignore
@Test
public void testVideoChain() throws IOException, PreprocessException, PayloadNotFoundException {
    Context context = InstrumentationRegistry.getInstrumentation().getTargetContext();
    File file = assetToFile("videos/test_video.mp4");
    FilePayload payload = new FilePayload(file.getAbsolutePath());

    Parameters parameters = new Parameters();
    parameters.setRequestId("test_request_id");
    parameters.setFrameRate(30);
    parameters.setWidth(1280);
    parameters.setHeight(720);
    parameters.setKeyFramesInterval(3);
    parameters.setTargetAudioBitrateKbps(128);
    parameters.setTargetVideoBitrateKbps((int) (3.3 * 1024 * 1024));

    VideoPreprocessChain chain = VideoPreprocessChain.videoTranscodingChain(parameters);
    String outputVideoPath = chain.execute(context, payload);
    File targetVideoFile = new File(outputVideoPath);

    Assert.assertTrue(targetVideoFile.length() > 0);
}
 
Example #4
Source File: PreprocessTest.java    From cloudinary_android with MIT License 6 votes vote down vote up
@Test
public void testRotate() {
    final Context context = InstrumentationRegistry.getInstrumentation().getTargetContext();
    Bitmap originalBitmap = Bitmap.createBitmap(BitmapFactory.decodeFile(assetFile.getAbsolutePath()));

    Bitmap bitmap = new Rotate(90).execute(context, originalBitmap);
    Assert.assertEquals(bitmap.getWidth(), originalBitmap.getHeight());
    Assert.assertEquals(bitmap.getHeight(), originalBitmap.getWidth());

    bitmap = new Rotate(180).execute(context, originalBitmap);
    Assert.assertEquals(bitmap.getWidth(), originalBitmap.getWidth());
    Assert.assertEquals(bitmap.getHeight(), originalBitmap.getHeight());

    bitmap = new Rotate(360).execute(context, originalBitmap);
    Assert.assertEquals(bitmap.getGenerationId(), originalBitmap.getGenerationId());
}
 
Example #5
Source File: URIBuilderTest.java    From DeviceConnect-Android with MIT License 6 votes vote down vote up
/**
 * attributeが設定できることを確認する。
 * <pre>
 * 【期待する動作】
 * ・設定したプロファイルがgetAttributeで取得できること。
 * </pre>
 */
@Test
public void uriBuilder_toString() {
    final String host = "test.com";
    final int port = 12345;
    final String profile = "profile";
    final String attribute = "attribute";
    final String accessToken = "test-accessToken";

    final String uri = "http://" + host + ":" + port + "/gotapi/" + profile + "/" + attribute + "?accessToken=" + accessToken;

    DConnectSDK sdk = DConnectSDKFactory.create(InstrumentationRegistry.getInstrumentation().getContext(), DConnectSDKFactory.Type.HTTP);
    sdk.setAccessToken(accessToken);

    DConnectSDK.URIBuilder builder = sdk.createURIBuilder();
    builder.setHost(host);
    builder.setPort(port);
    builder.setProfile(profile);
    builder.setAttribute(attribute);

    assertThat(builder.toString(), is(uri));
}
 
Example #6
Source File: TrustKitConfigurationTest.java    From TrustKit-Android with MIT License 6 votes vote down vote up
@Test
public void testDisableDefaultReportUri() throws XmlPullParserException, IOException,
        ParseException, CertificateException {
    Context context = InstrumentationRegistry.getInstrumentation().getContext();
    String xml = "" +
            "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n" +
            "<network-security-config>\n" +
            "    <domain-config>\n" +
            "        <domain>www.datatheorem.com</domain>\n" +
            "        <pin-set>\n" +
            "            <pin digest=\"SHA-256\">AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA=</pin>\n" +
            "            <pin digest=\"SHA-256\">grX4Ta9HpZx6tSHkmCrvpApTQGo67CYDnvprLg5yRME=</pin>\n" +
            "        </pin-set>\n" +
            "        <trustkit-config disableDefaultReportUri=\"true\">\n" +
            "        </trustkit-config>\n" +
            "    </domain-config>\n" +
            "</network-security-config>";
    TrustKitConfiguration config = TrustKitConfiguration.fromXmlPolicy(context,
            parseXmlString(xml));

    // Ensure the list of report URIs is empty
    DomainPinningPolicy domainConfig = config.getPolicyForHostname("www.datatheorem.com");
    assertNotNull(domainConfig);
    assertEquals(new HashSet<>(), domainConfig.getReportUris());
}
 
Example #7
Source File: MainActivityTest.java    From media-samples with Apache License 2.0 6 votes vote down vote up
@Test
public void fullscreen_disabledOnPortrait() throws Throwable {
    rule.runOnUiThread(new Runnable() {
        @Override
        public void run() {
            rule.getActivity()
                    .setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
        }
    });
    InstrumentationRegistry.getInstrumentation().waitForIdleSync();
    rule.runOnUiThread(new Runnable() {
        @Override
        public void run() {
            final View decorView = rule.getActivity().getWindow().getDecorView();
            assertThat(decorView.getSystemUiVisibility(),
                    not(hasFlag(View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN)));
        }
    });
}
 
Example #8
Source File: SSLSocketFactoryTest.java    From TrustKit-Android with MIT License 6 votes vote down vote up
@Test
public void testPinnedDomainExpiredChain() throws IOException {
    // Initialize TrustKit
    String serverHostname = "expired.badssl.com";
    TestableTrustKit.initializeWithNetworkSecurityConfiguration(
            InstrumentationRegistry.getInstrumentation().getContext(), mockReporter);

    // Create a TrustKit SocketFactory and ensure the connection fails
    SSLSocketFactory test = TestableTrustKit.getInstance().getSSLSocketFactory(serverHostname);
    boolean didReceiveHandshakeError = false;
    try {
        test.createSocket(serverHostname, 443).getInputStream();
    } catch (SSLHandshakeException e) {
        if ((e.getCause() instanceof CertificateException
                && !(e.getCause().getMessage().startsWith("Pin verification failed")))) {
            didReceiveHandshakeError = true;
        }
    }
    assertTrue(didReceiveHandshakeError);

    if (Build.VERSION.SDK_INT < 17) {
        // TrustKit does not do anything for API level < 17 hence there is no reporting
        return;
    }

    // Ensure the background reporter was called
    verify(mockReporter).pinValidationFailed(
            eq(serverHostname),
            eq(0),
            (List<X509Certificate>) org.mockito.Matchers.isNotNull(),
            (List<X509Certificate>) org.mockito.Matchers.isNotNull(),
            eq(TestableTrustKit.getInstance().getConfiguration().getPolicyForHostname(serverHostname)),
            eq(PinningValidationResult.FAILED_CERTIFICATE_CHAIN_NOT_TRUSTED)
    );
}
 
Example #9
Source File: LPRichInterstitialMessageSnapshotTest.java    From Leanplum-Android-SDK with Apache License 2.0 6 votes vote down vote up
@Test
public void testRichInterstitial() throws InterruptedException {
  Instrumentation instrumentation = InstrumentationRegistry.getInstrumentation();
  Leanplum.setApplicationContext(getMainActivity());

  instrumentation.runOnMainSync(new Runnable() {
    @Override
    public void run() {
      messageView = createMessageView();
      setupView(messageView);
    }
  });

  Thread.sleep(7000); // wait until WebView is rendered

  instrumentation.runOnMainSync(new Runnable() {
    @Override
    public void run() {
      snapshotView(messageView);
    }
  });
}
 
Example #10
Source File: MediaSessionPlaybackActivityTest.java    From media-samples with Apache License 2.0 6 votes vote down vote up
@Test
public void movie_playingOnPip() throws Throwable {
    // The movie should be playing on start
    onView(withId(R.id.movie))
            .check(matches(allOf(isDisplayed(), isPlaying())))
            .perform(showControls());
    // Click on the button to enter Picture-in-Picture mode
    onView(withId(R.id.minimize)).perform(click());
    InstrumentationRegistry.getInstrumentation().waitForIdleSync();
    // The Activity is paused. We cannot use Espresso to test paused activities.
    rule.runOnUiThread(new Runnable() {
        @Override
        public void run() {
            // We are now in Picture-in-Picture mode
            assertTrue(rule.getActivity().isInPictureInPictureMode());
            final MovieView view = rule.getActivity().findViewById(R.id.movie);
            assertNotNull(view);
            // The video should still be playing
            assertTrue(view.isPlaying());

            // The media session state should be playing.
            assertMediaStateIs(PlaybackStateCompat.STATE_PLAYING);
        }
    });
}
 
Example #11
Source File: SSLSocketFactoryTest.java    From TrustKit-Android with MIT License 6 votes vote down vote up
@Test
public void testPinnedDomainInvalidPinAndPolicyExpired() throws IOException {
    String serverHostname = "www.microsoft.com";
    TestableTrustKit.initializeWithNetworkSecurityConfiguration(
            InstrumentationRegistry.getInstrumentation().getContext(), mockReporter);

    // Create a TrustKit SocketFactory and ensure the connection succeeds
    SSLSocketFactory test = TestableTrustKit.getInstance().getSSLSocketFactory(serverHostname);
    Socket socket = test.createSocket(serverHostname, 443);
    socket.getInputStream();

    assertTrue(socket.isConnected());
    socket.close();

    // Ensure the background reporter was NOT called
    verify(mockReporter, never()).pinValidationFailed(
            anyString(),
            anyInt(),
            (List<X509Certificate>) any(),
            (List<X509Certificate>) any(),
            any(DomainPinningPolicy.class),
            any(PinningValidationResult.class)
    );
}
 
Example #12
Source File: TestDateUtils.java    From joda-time-android with Apache License 2.0 5 votes vote down vote up
@After
public void tearDown() throws Exception {
    // Restore to normal "now" time
    DateTimeUtils.setCurrentMillisSystem();
    DateTimeZone.setDefault(mOldDefaultJodaTz);
    TimeZone.setDefault(mOldDefaultSystemTz);
    ContentResolver cr = InstrumentationRegistry.getInstrumentation().getContext().getContentResolver();
    Settings.System.putString(cr, Settings.System.TIME_12_24, mOldTime1224Setting);
}
 
Example #13
Source File: SettingsActivityTest.java    From zapp with MIT License 5 votes vote down vote up
@Test
public void testRecreation() {
	Context context = InstrumentationRegistry.getInstrumentation().getTargetContext();
	Intent intent = SettingsActivity.getStartIntent(context);

	ActivityScenario scenario = ActivityScenario.launch(intent);
	scenario.recreate();
}
 
Example #14
Source File: URIBuilderTest.java    From DeviceConnect-Android with MIT License 5 votes vote down vote up
/**
 * ポート番号を設定する。
 * <pre>
 * 【期待する動作】
 * ・設定したポート番号がgetPortで取得できること。
 * </pre>
 */
@Test
public void uriBuilder_port() {
    final int port = 9999;
    DConnectSDK sdk = DConnectSDKFactory.create(InstrumentationRegistry.getInstrumentation().getContext(), DConnectSDKFactory.Type.HTTP);
    DConnectSDK.URIBuilder builder = sdk.createURIBuilder();
    builder.setPort(port);
    assertThat(builder.getPort(), is(port));
}
 
Example #15
Source File: FirebaseFirestoreTest.java    From firebase-android-sdk with Apache License 2.0 5 votes vote down vote up
@NonNull
private FirebaseApp getApp(@NonNull String name) {
  return FirebaseApp.initializeApp(
      InstrumentationRegistry.getInstrumentation().getContext(),
      new FirebaseOptions.Builder()
          .setApplicationId("appid")
          .setApiKey("apikey")
          .setProjectId("projectid")
          .build(),
      name);
}
 
Example #16
Source File: ExampleInstrumentedTest.java    From smart-farmer-android with Apache License 2.0 5 votes vote down vote up
@Test
public void useAppContext() throws Exception {
    // Context of the app under test.
    Context appContext = InstrumentationRegistry.getTargetContext();

    assertEquals("com.beanu.l2_shareutil", appContext.getPackageName());
}
 
Example #17
Source File: ExampleInstrumentedTest.java    From LoadingButton with MIT License 5 votes vote down vote up
@Test
public void useAppContext() {
    // Context of the app under test.
    Context appContext = InstrumentationRegistry.getTargetContext();

    assertEquals("com.kusu.loadingbutton.test", appContext.getPackageName());
}
 
Example #18
Source File: ExampleInstrumentedTest.java    From DeviceConnect-Android with MIT License 5 votes vote down vote up
@Test
public void useAppContext() {
    // Context of the app under test.
    Context appContext = InstrumentationRegistry.getInstrumentation().getTargetContext();

    assertEquals("org.deviceconnect.android.rtspserver", appContext.getPackageName());
}
 
Example #19
Source File: URIBuilderTest.java    From DeviceConnect-Android with MIT License 5 votes vote down vote up
/**
 * アクセストークンを設定する。
 * <pre>
 * 【期待する動作】
 * ・設定したアクセストークンがgetAccessTokenで取得できること。
 * </pre>
 */
@Test
public void uriBuilder_accessToken() {
    final String accessToken = "abc";
    DConnectSDK sdk = DConnectSDKFactory.create(InstrumentationRegistry.getInstrumentation().getContext(), DConnectSDKFactory.Type.HTTP);
    sdk.setAccessToken("test-accessToken");

    DConnectSDK.URIBuilder builder = sdk.createURIBuilder();
    builder.setAccessToken(accessToken);
    assertThat(builder.getAccessToken(), is(accessToken));
}
 
Example #20
Source File: HttpDConnectSDKTest.java    From DeviceConnect-Android with MIT License 5 votes vote down vote up
/**
 * getを呼び出し、レスポンスを受け取れることを確認する。
 * <pre>
 * 【期待する動作】
 * ・DConnectResponseMessageが返却されること。
 * ・resultに0が返却されること。
 * ・productにtest-managerが返却されること。
 * ・versionに1.1が返却されること。
 * ・nameにmanagerが返却されること。
 * ・uuidにuuidが返却されること。
 * </pre>
 */
@Test
public void get() {
    final String version = "1.1";
    final String product = "test-manager";
    final String name = "manager";
    final String uuid = "uuid";
    mTestServer.setServerCallback(new TestServer.ServerCallback() {
        @Override
        public NanoHTTPD.Response serve(final String uri, final NanoHTTPD.Method method, final Map<String, String> headers,
                                        final Map<String, String> parms, final Map<String, String> files) {
            if (!method.equals(NanoHTTPD.Method.GET)) {
                return newBadRequest("Method is not GET.");
            }

            try {
                JSONObject jsonObject = new JSONObject();
                jsonObject.put(DConnectMessage.EXTRA_RESULT, DConnectMessage.RESULT_OK);
                jsonObject.put(DConnectProfileConstants.PARAM_VERSION, version);
                jsonObject.put(DConnectProfileConstants.PARAM_PRODUCT, product);
                jsonObject.put(AvailabilityProfileConstants.PARAM_NAME, name);
                jsonObject.put(AvailabilityProfileConstants.PARAM_UUID, uuid);
                return newJsonResponse(jsonObject);
            } catch (JSONException e) {
                return newInternalServerError(e.getMessage());
            }
        }
    });

    DConnectSDK sdk = DConnectSDKFactory.create(InstrumentationRegistry.getInstrumentation().getContext(), DConnectSDKFactory.Type.HTTP);
    DConnectResponseMessage response = sdk.get("http://localhost:4035/gotapi/availability");
    assertThat(response, notNullValue());
    assertThat(response.getResult(), is(DConnectMessage.RESULT_OK));
    assertThat(response.getString(DConnectProfileConstants.PARAM_VERSION), is(version));
    assertThat(response.getString(DConnectProfileConstants.PARAM_PRODUCT), is(product));
    assertThat(response.getString(AvailabilityProfileConstants.PARAM_NAME), is(name));
    assertThat(response.getString(AvailabilityProfileConstants.PARAM_UUID), is(uuid));
}
 
Example #21
Source File: UploaderTest.java    From cloudinary_android with MIT License 5 votes vote down vote up
@BeforeClass
public static void setUp() throws Exception {
    String url = Utils.cloudinaryUrlFromContext(InstrumentationRegistry.getInstrumentation().getContext());
    cloudinary = new Cloudinary(url);
    if (StringUtils.isBlank(url)) {
        throw new IllegalArgumentException("UploaderTest - No cloudinary url configured");
    }

    if (!url.startsWith("cloudinary://")){
        throw new IllegalArgumentException("UploaderTest - malformed cloudinary url");
    }
}
 
Example #22
Source File: Base64EncodingHelperAndroidTest.java    From firebase-android-client with Apache License 2.0 5 votes vote down vote up
@Test
public void base64Encode_24Khz_Success() throws IOException {
    String expectedFilePath = "assets/speech-recording-24khz.b64";
    InputStream expectedInputStream = this.getClass().getClassLoader().getResourceAsStream(expectedFilePath);
    InputStreamReader expectedInputStreamReader = new InputStreamReader(expectedInputStream);
    BufferedReader expectedBufferedReader = new BufferedReader(expectedInputStreamReader);
    StringBuilder expected = new StringBuilder();

    String line;
    while((line = expectedBufferedReader.readLine()) != null) {
        expected.append(line);
    }

    String actualFilePath = "assets/speech-recording-24khz.wav";
    InputStream actualInputStream = this.getClass().getClassLoader().getResourceAsStream(actualFilePath);

    Context context = InstrumentationRegistry.getInstrumentation().getTargetContext();
    File actualFile = new File(context.getCacheDir(), "speech-recording-24khz.wav");
    OutputStream output = new FileOutputStream(actualFile);
    byte[] buffer = new byte[1024];
    int read;
    while ((read = actualInputStream.read(buffer)) != -1) {
        output.write(buffer, 0, read);
    }
    output.flush();
    output.close();
    actualInputStream.close();

    String actual = Base64EncodingHelper.encode(actualFile);

    Assert.assertEquals(expected.toString(), actual);
}
 
Example #23
Source File: ExampleInstrumentedTest.java    From SlidesRemote with Apache License 2.0 5 votes vote down vote up
@Test
public void useAppContext() {
    // Context of the app under test.
    Context appContext = InstrumentationRegistry.getInstrumentation().getTargetContext();

    assertEquals("com.houarizegai.slidesremote", appContext.getPackageName());
}
 
Example #24
Source File: ImageRowScreenshotTest.java    From screenshot-tests-for-android with Apache License 2.0 5 votes vote down vote up
@Test
public void testDefault() {
  Context targetContext = InstrumentationRegistry.getInstrumentation().getTargetContext();
  LayoutInflater inflater = LayoutInflater.from(targetContext);
  LithoView view = (LithoView) inflater.inflate(R.layout.litho_view, null, false);

  view.setComponent(ImageRow.create(view.getComponentContext()).build());

  ViewHelpers.setupView(view).setExactWidthDp(300).layout();
  Screenshot.snap(view).record();
}
 
Example #25
Source File: TrustKitTest.java    From TrustKit-Android with MIT License 5 votes vote down vote up
@Test
public void testInitializeWithValidXmlFile() {
    Context context = InstrumentationRegistry.getInstrumentation().getContext();
    int networkSecurityConfigId = context.getResources().getIdentifier(
            "network_security_config", "xml", context.getPackageName());
    TrustKit trustkit = TrustKit.initializeWithNetworkSecurityConfiguration(context,
            networkSecurityConfigId);
    assertNotNull(trustkit);
}
 
Example #26
Source File: ExampleInstrumentedTest.java    From AndroidDemo with MIT License 5 votes vote down vote up
@Test
public void useAppContext() {
    // Context of the app under test.
    Context appContext = InstrumentationRegistry.getInstrumentation().getTargetContext();

    assertEquals("cn.hbu.cs.databasedemo", appContext.getPackageName());
}
 
Example #27
Source File: ExampleInstrumentedTest.java    From tysq-android with GNU General Public License v3.0 5 votes vote down vote up
@Test
public void useAppContext() {
    // Context of the app under test.
    Context appContext = InstrumentationRegistry.getInstrumentation().getTargetContext();

    assertEquals("com.abc.lib_websocket.test", appContext.getPackageName());
}
 
Example #28
Source File: GattServerTests.java    From bitgatt with Mozilla Public License 2.0 5 votes vote down vote up
@BeforeClass
public static void before() {
    Timber.plant(new Timber.DebugTree());
    mockContext = InstrumentationRegistry.getInstrumentation().getContext();
    main = new BluetoothGattService(UUID.fromString("adabfb00-6e7d-4601-bda2-bffaa68956ba"), BluetoothGattService.SERVICE_TYPE_PRIMARY);
    BluetoothGattCharacteristic txChar = new BluetoothGattCharacteristic(UUID.fromString("ADABFB01-6E7D-4601-BDA2-BFFAA68956BA"),
        BluetoothGattCharacteristic.PROPERTY_WRITE | BluetoothGattCharacteristic.PROPERTY_NOTIFY,
        BluetoothGattCharacteristic.PERMISSION_WRITE | BluetoothGattCharacteristic.PERMISSION_WRITE_ENCRYPTED);
    main.addCharacteristic(txChar);
    BluetoothGattCharacteristic rxChar = new BluetoothGattCharacteristic(UUID.fromString("ADABFB02-6E7D-4601-BDA2-BFFAA68956BA"),
        BluetoothGattCharacteristic.PROPERTY_INDICATE | BluetoothGattCharacteristic.PROPERTY_NOTIFY | BluetoothGattCharacteristic.PROPERTY_READ,
        BluetoothGattCharacteristic.PERMISSION_READ | BluetoothGattCharacteristic.PERMISSION_READ_ENCRYPTED);
    main.addCharacteristic(rxChar);
    liveData = new BluetoothGattService(UUID.fromString("558dfa00-4fa8-4105-9f02-4eaa93e62980"), BluetoothGattService.SERVICE_TYPE_PRIMARY);
    BluetoothGattCharacteristic ldChar = new BluetoothGattCharacteristic(UUID.fromString("558DFA01-4FA8-4105-9F02-4EAA93E62980"),
        BluetoothGattCharacteristic.PROPERTY_INDICATE | BluetoothGattCharacteristic.PROPERTY_READ,
        BluetoothGattCharacteristic.PERMISSION_READ | BluetoothGattCharacteristic.PERMISSION_READ_ENCRYPTED);
    liveData.addCharacteristic(ldChar);
    dncs = new BluetoothGattService(UUID.fromString("16bcfd00-253f-c348-e831-0db3e334d580"), BluetoothGattService.SERVICE_TYPE_PRIMARY);
    BluetoothGattCharacteristic notifChar = new BluetoothGattCharacteristic(UUID.fromString("16BCFD02-253F-C348-E831-0DB3E334D580"),
        BluetoothGattCharacteristic.PROPERTY_NOTIFY | BluetoothGattCharacteristic.PROPERTY_READ,
        BluetoothGattCharacteristic.PERMISSION_READ_ENCRYPTED | BluetoothGattCharacteristic.PERMISSION_WRITE);
    dncs.addCharacteristic(notifChar);
    cpChar = new BluetoothGattCharacteristic(UUID.fromString("16BCFD01-253F-C348-E831-0DB3E334D580"),
        BluetoothGattCharacteristic.PROPERTY_WRITE | BluetoothGattCharacteristic.PROPERTY_READ,
        BluetoothGattCharacteristic.PERMISSION_READ | BluetoothGattCharacteristic.PERMISSION_WRITE);
    dncs.addCharacteristic(cpChar);
    BluetoothGattCharacteristic flsChar = new BluetoothGattCharacteristic(UUID.fromString("16BCFD04-253F-C348-E831-0DB3E334D580"),
        BluetoothGattCharacteristic.PROPERTY_WRITE | BluetoothGattCharacteristic.PROPERTY_READ,
        BluetoothGattCharacteristic.PERMISSION_READ | BluetoothGattCharacteristic.PERMISSION_WRITE);
    dncs.addCharacteristic(flsChar);
}
 
Example #29
Source File: AuthenticatorActivityPart2Test.java    From google-authenticator-android with Apache License 2.0 5 votes vote down vote up
@Before
public void setUp() throws Exception {
  DependencyInjector.resetForIntegrationTesting(
      InstrumentationRegistry.getInstrumentation().getTargetContext());
  mAccountDb = DependencyInjector.getAccountDb();

  initMocks(this);
  DaggerInjector.init(new MockModule());
}
 
Example #30
Source File: URIBuilderTest.java    From DeviceConnect-Android with MIT License 5 votes vote down vote up
/**
 * profileが設定できることを確認する。
 * <pre>
 * 【期待する動作】
 * ・設定したプロファイルがgetProfileで取得できること。
 * </pre>
 */
@Test
public void uriBuilder_profile() {
    final String profile = "profile";

    DConnectSDK sdk = DConnectSDKFactory.create(InstrumentationRegistry.getInstrumentation().getContext(), DConnectSDKFactory.Type.HTTP);
    sdk.setAccessToken("test-accessToken");

    DConnectSDK.URIBuilder builder = sdk.createURIBuilder();
    builder.setProfile(profile);

    assertThat(builder.getProfile(), is(profile));
}