Android Open Source - android-nfc-lib Abstract Fails Tests Async






From Project

Back to project page android-nfc-lib.

License

The source code is released under:

MIT License

If you think the Android project android-nfc-lib listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

/*
 * AbstractFailsTestsAsync.java/*from  w  w  w .  j  a v a  2 s .  c o  m*/
 * NfcLibrary project.
 *
 * Created by : Daneo van Overloop - 17/6/2014.
 *
 * The MIT License (MIT)
 *
 * Copyright (c) 2014 AppFoundry. All rights reserved.
 *
 * Permission is hereby granted, free of charge, to any person obtaining a copy
 * of this software and associated documentation files (the "Software"), to deal
 * in the Software without restriction, including without limitation the rights
 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
 * copies of the Software, and to permit persons to whom the Software is
 * furnished to do so, subject to the following conditions:
 *
 * The above copyright notice and this permission notice shall be included in all
 * copies or substantial portions of the Software.
 */

package be.appfoundry.nfclibrary.utilities.async;

import android.nfc.FormatException;
import android.os.HandlerThread;
import android.test.InstrumentationTestCase;

import java.util.concurrent.Semaphore;

import be.appfoundry.nfclibrary.exceptions.InsufficientCapacityException;
import be.appfoundry.nfclibrary.exceptions.ReadOnlyTagException;
import be.appfoundry.nfclibrary.exceptions.TagNotPresentException;
import be.appfoundry.nfclibrary.tasks.interfaces.AsyncOperationCallback;
import be.appfoundry.nfclibrary.tasks.interfaces.AsyncUiCallback;
import be.appfoundry.nfclibrary.utilities.TestUtilities;
import be.appfoundry.nfclibrary.utilities.interfaces.AsyncNfcWriteOperation;
import be.appfoundry.nfclibrary.utilities.async.WriteEmailNfcAsync;
import be.appfoundry.nfclibrary.utilities.interfaces.NfcWriteUtility;

/**
 * NfcLibrary by daneo
 * Created on 30/05/14.
 */
public class AbstractFailsTestsAsync extends InstrumentationTestCase {
    protected HandlerThread mHandlerThread;
    protected TestUtilities mTestUtilities = new TestUtilities();
    protected AsyncNfcWriteOperation mAsyncNfcWriteOperation;
    protected Semaphore mSemaphore;

    protected void performAsyncTaskWithReturnValue(AsyncUiCallback asyncUiCallback, NfcWriteUtility nfcWriteUtility, final boolean returnValue) throws InterruptedException {
        mSemaphore = new Semaphore(0);

        this.mAsyncNfcWriteOperation = new WriteEmailNfcAsync(asyncUiCallback,
                new AsyncOperationCallback() {
                    @Override
                    public boolean performWrite(NfcWriteUtility writeUtility) throws ReadOnlyTagException, InsufficientCapacityException, TagNotPresentException, FormatException {
                        return returnValue;
                    }
                }
                ,
                nfcWriteUtility
        );

        mHandlerThread.start();
        mSemaphore.acquire();
    }

    protected void performAsyncTaskWithReturnValue(AsyncUiCallback asyncUiCallback, AsyncOperationCallback asyncOperationCallback, NfcWriteUtility nfcWriteUtility) throws InterruptedException {
        mSemaphore = new Semaphore(0);

        this.mAsyncNfcWriteOperation = new WriteEmailNfcAsync(asyncUiCallback,
                asyncOperationCallback,
                nfcWriteUtility
        );

        // TODO : Thread in thread. mAsyncWriteOperation launches a thread on its own, so we lose control.

        //this.mAsyncNfcWriteOperation;
        mSemaphore.acquire();
    }

    protected boolean checkResult(String value) {
        return mTestUtilities.checkResult(value);
    }

    protected AsyncUiCallback getSucceedingAsyncUiCallback() {
        return new AsyncUiCallback() {
            @Override
            public void callbackWithReturnValue(Boolean result) {
                assertTrue(result);
            }

            @Override
            public void onProgressUpdate(Boolean... values) {
                assertTrue(values[0]);
            }

            @Override
            public void onError(Exception e) {
                fail(e.getMessage());
            }
        };
    }

    protected AsyncUiCallback getFailingAsyncUiCallback(){
        return new AsyncUiCallback() {
            @Override
            public void callbackWithReturnValue(Boolean result) {
                assertFalse(result);
            }

            @Override
            public void onProgressUpdate(Boolean... values) {
                assertTrue(values[0]);
            }

            @Override
            public void onError(Exception e) {
                fail(e.getMessage());
            }
        };
    }
    protected void release() {
        mSemaphore.release();
    }
}




Java Source Code List

be.appfoundry.nfclibrary.activities.NfcActivity.java
be.appfoundry.nfclibrary.constants.NfcPayloadHeader.java
be.appfoundry.nfclibrary.constants.NfcType.java
be.appfoundry.nfclibrary.exceptions.InsufficientCapacityException.java
be.appfoundry.nfclibrary.exceptions.ReadOnlyTagException.java
be.appfoundry.nfclibrary.exceptions.TagNotPresentException.java
be.appfoundry.nfclibrary.exceptions.TagNotWritableException.java
be.appfoundry.nfclibrary.implementation.NfcActivity.java
be.appfoundry.nfclibrary.implementation.TestEmptyFieldsNfcActivity.java
be.appfoundry.nfclibrary.implementation.TestFilledFieldsNfcActivity.java
be.appfoundry.nfclibrary.tasks.GenericTask.java
be.appfoundry.nfclibrary.tasks.interfaces.AsyncOperationCallback.java
be.appfoundry.nfclibrary.tasks.interfaces.AsyncUiCallback.java
be.appfoundry.nfclibrary.utilities.TestUtilities.java
be.appfoundry.nfclibrary.utilities.async.AbstractFailsTestsAsync.java
be.appfoundry.nfclibrary.utilities.async.AbstractNfcAsync.java
be.appfoundry.nfclibrary.utilities.async.GenericTaskTestsAsync.java
be.appfoundry.nfclibrary.utilities.async.WriteBluetoothNfcAsync.java
be.appfoundry.nfclibrary.utilities.async.WriteCallbackNfcAsync.java
be.appfoundry.nfclibrary.utilities.async.WriteEmailNfcAsync.java
be.appfoundry.nfclibrary.utilities.async.WriteGeoLocationNfcAsync.java
be.appfoundry.nfclibrary.utilities.async.WritePhoneNfcAsync.java
be.appfoundry.nfclibrary.utilities.async.WriteSmsNfcAsync.java
be.appfoundry.nfclibrary.utilities.async.WriteUriNfcAsync.java
be.appfoundry.nfclibrary.utilities.interfaces.AsyncNfcWriteOperation.java
be.appfoundry.nfclibrary.utilities.interfaces.NdefWrite.java
be.appfoundry.nfclibrary.utilities.interfaces.NfcMessageUtility.java
be.appfoundry.nfclibrary.utilities.interfaces.NfcReadUtility.java
be.appfoundry.nfclibrary.utilities.interfaces.NfcWriteUtility.java
be.appfoundry.nfclibrary.utilities.interfaces.WriteUtility.java
be.appfoundry.nfclibrary.utilities.sync.NdefWriteImpl.java
be.appfoundry.nfclibrary.utilities.sync.NfcMessageUtilityImpl.java
be.appfoundry.nfclibrary.utilities.sync.NfcReadUtilityImpl.java
be.appfoundry.nfclibrary.utilities.sync.NfcWriteUtilityImpl.java
be.appfoundry.nfclibrary.utilities.sync.WriteEmailFailsTests.java
be.appfoundry.nfclibrary.utilities.sync.WriteEmailSucceedsTests.java
be.appfoundry.nfclibrary.utilities.sync.WriteGeolocationFailsTests.java
be.appfoundry.nfclibrary.utilities.sync.WriteGeolocationSucceedsTests.java
be.appfoundry.nfclibrary.utilities.sync.WritePhoneFailsTests.java
be.appfoundry.nfclibrary.utilities.sync.WritePhoneSucceedsTests.java
be.appfoundry.nfclibrary.utilities.sync.WriteUriFailsTests.java
be.appfoundry.nfclibrary.utilities.sync.WriteUriSucceedsTests.java
be.appfoundry.nfclibrary.utilities.sync.WriteUtilityImpl.java