Example usage for org.apache.commons.lang.mutable MutableBoolean MutableBoolean

List of usage examples for org.apache.commons.lang.mutable MutableBoolean MutableBoolean

Introduction

In this page you can find the example usage for org.apache.commons.lang.mutable MutableBoolean MutableBoolean.

Prototype

public MutableBoolean() 

Source Link

Document

Constructs a new MutableBoolean with the default value of false.

Usage

From source file:com.aionlightning.commons.callbacks.CallbacksTest.java

@Test
public void testIntResultNoCallback() {
    final MutableBoolean beforeInvoked = new MutableBoolean();
    final MutableBoolean afterInvoked = new MutableBoolean();
    int val = 10;
    TestCallbackIntObject obj = new TestCallbackIntObject(val);
    EnhancedObject eo = (EnhancedObject) obj;
    eo.addCallback(new AbstractCallback() {
        @Override// w  ww. ja  v a  2  s .co  m
        public CallbackResult beforeCall(Object obj, Object[] args) {
            beforeInvoked.setValue(true);
            return CallbackResult.newContinue();
        }

        @Override
        public CallbackResult afterCall(Object obj, Object[] args, Object methodResult) {
            afterInvoked.setValue(true);
            return CallbackResult.newContinue();
        }
    });

    int res = obj.getValue();

    assertTrue(beforeInvoked.booleanValue());
    assertTrue(afterInvoked.booleanValue());
    assertEquals(res, val);
}

From source file:com.eviware.soapui.impl.rest.panels.request.RestRequestDesktopPanel.java

@Override
protected void initializeFields() {
    String path = getRequest().getResource().getFullPath();
    updating = new MutableBoolean();
    resourcePanel = new TextPanelWithTopLabel("Resource", path,
            new RestResourceEditor(getRequest().getResource(), updating));
    queryPanel = new ParametersField(getRequest());
}

From source file:com.aionlightning.commons.callbacks.CallbacksTest.java

@Test
public void testIntResultBeforeCallback() {
    final MutableBoolean beforeInvoked = new MutableBoolean();
    final MutableBoolean afterInvoked = new MutableBoolean();
    int val = 10;
    final int newVal = 100;
    TestCallbackIntObject obj = new TestCallbackIntObject(val);
    EnhancedObject eo = (EnhancedObject) obj;
    eo.addCallback(new AbstractCallback() {
        @Override//from w  w w.j  a v  a2 s . c  o  m
        public CallbackResult beforeCall(Object obj, Object[] args) {
            beforeInvoked.setValue(true);
            return CallbackResult.newFullBlocker(newVal);
        }

        @Override
        public CallbackResult afterCall(Object obj, Object[] args, Object methodResult) {
            afterInvoked.setValue(true);
            return CallbackResult.newContinue();
        }
    });

    int res = obj.getValue();

    assertTrue(beforeInvoked.booleanValue());
    assertTrue(afterInvoked.booleanValue());
    assertEquals(res, newVal);
}

From source file:com.eviware.soapui.impl.rest.panels.component.RestResourceEditorTest.java

@Test
public void changingPathTextForLonelyResourceShouldUpdateTheResourcePath() {
    RestResourceEditor restResourceEditor = new RestResourceEditor(lonelyResource, new MutableBoolean());
    restResourceEditor.setText("hello");
    assertThat(lonelyResource.getFullPath(), is("/hello"));
}

From source file:net.agkn.field_stripe.record.reader.SmartJsonArrayRecordReaderTest.java

/**
 * Tests multiple records (flat structure for simplicity).
 *//* w  w  w .j av a2  s . c o  m*/
@Test
public void multipleRecordTest() throws Exception {
    // no record
    { // locally scoped for sanity
        final String input = ""/*no record*/;
        final IRecordReader recordReader = new SmartJsonArrayRecordReader(new StringReader(input));

        try {
            recordReader.startRecord();
            assert false : "Expected an exception.";
        } catch (final InvalidDataException ide) {
            assertEquals(ide.getLocalizedMessage(), "There are no more records to read.");
        }
    }
    { // locally scoped for sanity
        final String input = ""/*no record*/;
        final IRecordReader recordReader = new SmartJsonArrayRecordReader(new StringReader(input));

        assertFalse(recordReader.hasMoreRecords(), "No records to read");
        assertFalse(recordReader.hasMoreRecords(), "No records to read")/*called again for sanity*/;
    }

    // one record with no trailing newline
    { // locally scoped for sanity
        final String input = "[1]";
        final IRecordReader recordReader = new SmartJsonArrayRecordReader(new StringReader(input));

        assertTrue(recordReader.hasMoreRecords(), "There is a record to read");
        assertTrue(recordReader.hasMoreRecords(), "There is a record to read")/*called again for sanity*/;

        final MutableBoolean isSet = new MutableBoolean();
        recordReader.startRecord();
        assertEquals(recordReader.readIntField(isSet), 1);
        assertEquals(isSet.booleanValue(), true/*is set*/);
        recordReader.endRecord();

        assertFalse(recordReader.hasMoreRecords(), "No more records to read");
        assertFalse(recordReader.hasMoreRecords(), "No more records to read")/*called again for sanity*/;
    }
    // one record with trailing newline
    { // locally scoped for sanity
        final String input = "[2]\n"/*trailing newline*/;
        final IRecordReader recordReader = new SmartJsonArrayRecordReader(new StringReader(input));

        assertTrue(recordReader.hasMoreRecords(), "There is a record to read");
        assertTrue(recordReader.hasMoreRecords(), "There is a record to read")/*called again for sanity*/;

        final MutableBoolean isSet = new MutableBoolean();
        recordReader.startRecord();
        assertEquals(recordReader.readIntField(isSet), 2);
        assertEquals(isSet.booleanValue(), true/*is set*/);
        recordReader.endRecord();

        assertFalse(recordReader.hasMoreRecords(), "No more records to read");
        assertFalse(recordReader.hasMoreRecords(), "No more records to read")/*called again for sanity*/;
    }

    // multiple records
    { // locally scoped for sanity
      // CHECK:  is the case "[1]\nnull\n[3]" supported?
        final String input = "[1]\n" + "[2]\n" + "[3]";
        final IRecordReader recordReader = new SmartJsonArrayRecordReader(new StringReader(input));

        assertTrue(recordReader.hasMoreRecords(), "There is a record to read");
        assertTrue(recordReader.hasMoreRecords(), "There is a record to read")/*called again for sanity*/;

        final MutableBoolean isSet = new MutableBoolean();
        recordReader.startRecord();
        assertEquals(recordReader.readIntField(isSet), 1);
        assertEquals(isSet.booleanValue(), true/*is set*/);
        recordReader.endRecord();
        assertTrue(recordReader.hasMoreRecords(), "There is a record to read");
        assertTrue(recordReader.hasMoreRecords(), "There is a record to read")/*called again for sanity*/;

        recordReader.startRecord();
        assertEquals(recordReader.readIntField(isSet), 2);
        assertEquals(isSet.booleanValue(), true/*is set*/);
        recordReader.endRecord();
        assertTrue(recordReader.hasMoreRecords(), "There is a record to read");
        assertTrue(recordReader.hasMoreRecords(), "There is a record to read")/*called again for sanity*/;

        recordReader.startRecord();
        assertEquals(recordReader.readIntField(isSet), 3);
        assertEquals(isSet.booleanValue(), true/*is set*/);
        recordReader.endRecord();
        assertFalse(recordReader.hasMoreRecords(), "No more records to read");
        assertFalse(recordReader.hasMoreRecords(), "No more records to read")/*called again for sanity*/;
    }
}

From source file:com.eviware.soapui.impl.rest.panels.component.RestResourceEditorTest.java

@Test
public void displaysBasePathOfServiceInField() {
    lonelyResource.getInterface().setBasePath("/base");
    lonelyResource.setPath("resource");
    RestResourceEditor restResourceEditor = new RestResourceEditor(lonelyResource, new MutableBoolean());
    assertThat(restResourceEditor.getText(), is("/base/resource"));
}

From source file:com.qspin.qtaste.testapi.impl.generic.UtilityImpl.java

@Override
public boolean getUserConfirmation(final String title, final String message) throws QTasteException {
    final MutableBoolean confirmed = new MutableBoolean();
    try {//w w w  .  ja  va  2  s . c om
        SwingUtilities.invokeAndWait(new Runnable() {
            @Override
            public void run() {
                int result = JOptionPane.showConfirmDialog(null, message, title, JOptionPane.YES_NO_OPTION);
                confirmed.setValue(result == JOptionPane.YES_OPTION);
            }
        });
    } catch (Exception e) {
        throw new QTasteException("Error while showing user confirmation dialog", e);
    }
    return confirmed.booleanValue();
}

From source file:com.aionlightning.commons.services.CronServiceTest.java

@Test
public void testCancelledRunableGC() throws Exception {
    final MutableBoolean collected = new MutableBoolean();
    Runnable r = new Runnable() {

        @Override/*ww  w. j a  v  a2 s.  c  om*/
        public void run() {
            cronService.cancel(this);
        }

        public void finalize() throws Throwable {
            collected.setValue(true);
            super.finalize();
        }
    };

    cronService.schedule(r, "0/2 * * * * ?");
    r = null;
    sleep(5);
    for (int i = 0; i < 100; i++) {
        System.gc();
    }
    assertEquals(collected.booleanValue(), true);
}

From source file:com.eviware.soapui.impl.rest.panels.component.RestResourceEditorTest.java

@Test
public void displaysResourcePopupIfHasBasePath() {
    lonelyResource.getInterface().setBasePath("/base");
    lonelyResource.setPath("resource");
    RestResourceEditor restResourceEditor = new RestResourceEditor(lonelyResource, new MutableBoolean());

    assertThat(restResourceEditor.mouseListener, is(notNullValue()));
}

From source file:mitm.common.util.SizeLimitedOutputStreamTest.java

@Test
public void testClose() throws IOException {
    final MutableBoolean closeCalled = new MutableBoolean();

    ByteArrayOutputStream bos = new ByteArrayOutputStream() {
        @Override//  w w  w  . j a  v a 2s .  co  m
        public void close() {
            closeCalled.setValue(true);
        }
    };

    SizeLimitedOutputStream slo = new SizeLimitedOutputStream(bos, 100);

    assertFalse(closeCalled.booleanValue());

    slo.close();

    assertTrue(closeCalled.booleanValue());
}