Search in sources :

Example 26 with Observer

use of java.util.Observer in project core by jcryptool.

the class IntegratorWizardPage method makeNewKeypair.

protected void makeNewKeypair() {
    Job[] preJobs = Job.getJobManager().find(KeyStoreHelper.KEYSTOREHELPER_FAMILY);
    int preJobCount = preJobs.length;
    KeyStoreHelper.makeKeyPairByWizard(showKeyGroup).addObserver(new Observer() {

        public void update(Observable o, final Object arg) {
            if (arg != null) {
                keyFromKeystoreGroup.getDisplay().syncExec(new Runnable() {

                    public void run() {
                        KeyStoreAlias ref = (KeyStoreAlias) arg;
                        setKeyForShowcase(ref);
                    }
                });
            }
        }
    });
    Job[] jobs = Job.getJobManager().find(KeyStoreHelper.KEYSTOREHELPER_FAMILY);
    if (jobs.length > preJobCount) {
        createNewKeyButton.getDisplay().syncExec(new Runnable() {

            public void run() {
                buttonTextBeforeJobrunningMsg = createNewKeyButton.getText();
                // $NON-NLS-1$
                createNewKeyButton.setText(Messages.getString("IntegratorWizardPage.generatingButtonHint"));
                disableControls();
            }
        });
        Job job = jobs[jobs.length - 1];
        IJobChangeListener listener = new IJobChangeListener() {

            public void sleeping(IJobChangeEvent event) {
            }

            public void done(IJobChangeEvent event) {
                createNewKeyButton.getDisplay().syncExec(new Runnable() {

                    public void run() {
                        createNewKeyButton.setText(buttonTextBeforeJobrunningMsg);
                        enableControls();
                    }
                });
            }

            public void awake(IJobChangeEvent event) {
            }

            public void aboutToRun(IJobChangeEvent event) {
            }

            public void running(IJobChangeEvent event) {
            }

            public void scheduled(IJobChangeEvent event) {
            }
        };
        if (job.getState() != Job.NONE)
            job.addJobChangeListener(listener);
        else {
            listener.done(null);
        }
    }
}
Also used : KeyStoreAlias(org.jcryptool.crypto.keystore.backend.KeyStoreAlias) Observer(java.util.Observer) IJobChangeListener(org.eclipse.core.runtime.jobs.IJobChangeListener) IJobChangeEvent(org.eclipse.core.runtime.jobs.IJobChangeEvent) Job(org.eclipse.core.runtime.jobs.Job) Observable(java.util.Observable)

Example 27 with Observer

use of java.util.Observer in project core by jcryptool.

the class AbstractAlgorithmHandler method performOpenEditor.

/**
 * Tries to open the given IEditorInput in the Editor associated with the given ID. This method must be executed in
 * an async way since a Job may be used to execute the cryptographic operation.
 *
 * @param input The IEditorInput that shall be displayed
 * @param editorId The ID of the Editor that is supposed to open
 */
protected void performOpenEditor(final IEditorInput input, final String editorId) {
    Observer dummyObserver = new Observer() {

        @Override
        public void update(Observable o, Object arg) {
        }
    };
    performOpenEditor(input, editorId, dummyObserver);
}
Also used : Observer(java.util.Observer) ClassicDataObject(org.jcryptool.core.operations.dataobject.classic.ClassicDataObject) IDataObject(org.jcryptool.core.operations.dataobject.IDataObject) IClassicDataObject(org.jcryptool.core.operations.dataobject.classic.IClassicDataObject) ModernDataObject(org.jcryptool.core.operations.dataobject.modern.ModernDataObject) IModernDataObject(org.jcryptool.core.operations.dataobject.modern.IModernDataObject) Observable(java.util.Observable)

Example 28 with Observer

use of java.util.Observer in project opentest by mcdcorp.

the class SeleniumTestAction method initialize.

@Override
public void initialize() {
    super.initialize();
    if (!SeleniumTestAction.initialized) {
        SeleniumTestAction.initialized = true;
        SeleniumTestAction.config = SeleniumHelper.getConfig();
        this.getActor().addObserver(new Observer() {

            @Override
            public void update(Observable eventSource, Object eventData) {
                if (eventSource instanceof ITestActor) {
                    if (eventData == TestActorEvents.TEST_COMPLETED) {
                        SeleniumTestAction.discardActionsObject();
                        if (!SeleniumHelper.getConfig().getBoolean("selenium.reuseDriver", false)) {
                            SeleniumHelper.discardDriver();
                        }
                    }
                }
            }
        });
    }
    this.explicitWaitSec = this.readIntArgument("explicitWaitSec", SeleniumHelper.getExplicitWaitSec());
    this.driver = SeleniumHelper.getDriver();
}
Also used : Observer(java.util.Observer) ITestActor(org.getopentest.contracts.ITestActor) Observable(java.util.Observable)

Example 29 with Observer

use of java.util.Observer in project openkit-java by Dynatrace.

the class BeaconCacheEvictorTest method triggeringEvictionStrategiesInThread.

@Test
public void triggeringEvictionStrategiesInThread() throws Exception {
    // given
    final Observer[] observers = new Observer[] { null };
    final CountDownLatch addObserverLatch = new CountDownLatch(1);
    final CyclicBarrier strategyInvokedBarrier = new CyclicBarrier(2);
    doAnswer(new Answer<Void>() {

        @Override
        public Void answer(InvocationOnMock invocation) throws Throwable {
            observers[0] = (Observer) invocation.getArguments()[0];
            addObserverLatch.countDown();
            return null;
        }
    }).when(mockBeaconCache).addObserver(org.mockito.Matchers.any(Observer.class));
    doAnswer(new Answer<Void>() {

        @Override
        public Void answer(InvocationOnMock invocation) throws Throwable {
            strategyInvokedBarrier.await();
            return null;
        }
    }).when(mockStrategyTwo).execute();
    // first step start the eviction thread
    evictor = new BeaconCacheEvictor(mockLogger, mockBeaconCache, mockStrategyOne, mockStrategyTwo);
    evictor.start();
    // wait until the eviction thread registered itself as observer
    addObserverLatch.await();
    // verify the observer was set
    assertThat(observers[0], is(notNullValue()));
    // do some updates
    for (int i = 0; i < 10; i++) {
        observers[0].update(mock(Observable.class), null);
        strategyInvokedBarrier.await();
        strategyInvokedBarrier.reset();
    }
    // stop the stuff and ensure it's invoked
    boolean stopped = evictor.stop();
    assertThat(stopped, is(true));
    assertThat(evictor.isAlive(), is(false));
    verify(mockStrategyOne, times(10)).execute();
    verify(mockStrategyTwo, times(10)).execute();
}
Also used : CountDownLatch(java.util.concurrent.CountDownLatch) Observable(java.util.Observable) CyclicBarrier(java.util.concurrent.CyclicBarrier) InvocationOnMock(org.mockito.invocation.InvocationOnMock) Observer(java.util.Observer) Test(org.junit.Test)

Example 30 with Observer

use of java.util.Observer in project mockito by mockito.

the class DetectingMisusedMatchersTest method should_report_argument_locations_when_argument_matchers_misused.

@Test
public void should_report_argument_locations_when_argument_matchers_misused() {
    try {
        Observer observer = mock(Observer.class);
        misplaced_anyInt_argument_matcher();
        misplaced_any_argument_matcher();
        misplaced_anyBoolean_argument_matcher();
        observer.update(null, null);
        validateMockitoUsage();
        fail();
    } catch (InvalidUseOfMatchersException e) {
        assertThat(e).hasMessageContaining("DetectingMisusedMatchersTest.misplaced_anyInt_argument_matcher").hasMessageContaining("DetectingMisusedMatchersTest.misplaced_any_argument_matcher").hasMessageContaining("DetectingMisusedMatchersTest.misplaced_anyBoolean_argument_matcher");
    }
}
Also used : InvalidUseOfMatchersException(org.mockito.exceptions.misusing.InvalidUseOfMatchersException) Observer(java.util.Observer) Test(org.junit.Test)

Aggregations

Observer (java.util.Observer)36 Observable (java.util.Observable)29 Test (org.junit.Test)12 ContentQueryMap (android.content.ContentQueryMap)6 ContentResolver (android.content.ContentResolver)6 ContentValues (android.content.ContentValues)6 Cursor (android.database.Cursor)6 Handler (android.os.Handler)6 MediumTest (android.test.suitebuilder.annotation.MediumTest)6 CountDownLatch (java.util.concurrent.CountDownLatch)5 Map (java.util.Map)2 Properties (java.util.Properties)2 IJobChangeEvent (org.eclipse.core.runtime.jobs.IJobChangeEvent)2 IJobChangeListener (org.eclipse.core.runtime.jobs.IJobChangeListener)2 Job (org.eclipse.core.runtime.jobs.Job)2 ITestActor (org.getopentest.contracts.ITestActor)2 IDataObject (org.jcryptool.core.operations.dataobject.IDataObject)2 KeyStoreAlias (org.jcryptool.crypto.keystore.backend.KeyStoreAlias)2 ParameterizedConstructorInstantiator (org.mockito.internal.util.reflection.FieldInitializer.ParameterizedConstructorInstantiator)2 CvsBundle (com.intellij.CvsBundle)1