Example usage for javax.swing.text AbstractDocument insertString

List of usage examples for javax.swing.text AbstractDocument insertString

Introduction

In this page you can find the example usage for javax.swing.text AbstractDocument insertString.

Prototype

public void insertString(int offs, String str, AttributeSet a) throws BadLocationException 

Source Link

Document

Inserts some content into the document.

Usage

From source file:nl.xs4all.home.freekdb.b52reader.gui.MainGuiTest.java

private void testFilter(FilterTestType testType)
        throws BadLocationException, InterruptedException, ReflectiveOperationException {
    MainGui mainGui = new MainGui(mockManyBrowsersPanel);
    mainGui.setMainCallbacks(mockMainCallbacks);

    Mockito.when(mockConfiguration.useSpanTable()).thenReturn(testType == CHANGE_TEXT);

    mainGui.initializeBackgroundBrowsersPanel(mockFrame, mockConfiguration);
    mainGui.initializeGui(TestUtilities.getSixTestArticles());

    waitForGuiTasks();//  www.  j a  v a2 s  . com

    JTable table = (JTable) findComponent(mockContentPane, JTable.class);
    assertNotNull(table);

    assertEquals(mockConfiguration.useSpanTable() ? 12 : 6, table.getRowCount());

    JTextField filterTextField = (JTextField) findComponent(mockContentPane, JTextField.class);
    assertNotNull(filterTextField);
    AbstractDocument document = (AbstractDocument) filterTextField.getDocument();

    document.insertString(0, "title:title1", null);

    assertEquals(mockConfiguration.useSpanTable() ? 2 : 1, table.getRowCount());

    if (testType == REMOVE_TEXT) {
        document.remove(0, document.getLength());
    } else if (testType == CHANGE_TEXT) {
        document.replace(6, 6, "title2", null);

        // Since change is implemented as remove and insert, the fireChangedUpdate method is called with reflection.
        AbstractDocument.DefaultDocumentEvent mockEvent = Mockito
                .mock(AbstractDocument.DefaultDocumentEvent.class);
        Method method = AbstractDocument.class.getDeclaredMethod("fireChangedUpdate", DocumentEvent.class);
        method.setAccessible(true);
        method.invoke(document, mockEvent);
    } else if (testType == NO_MATCHES) {
        document.insertString(document.getLength(), "-some-nonsense", null);
    }

    checkArticlesInGui(testType, mainGui, table.getRowCount());
}