Search in sources :

Example 61 with Theory

use of org.junit.experimental.theories.Theory in project k-9 by k9mail.

the class TextBodyBuilderTest method testBuildTextPlain.

@Theory
public void testBuildTextPlain(boolean includeQuotedText, QuoteStyle quoteStyle, boolean isReplyAfterQuote, boolean isSignatureUse, boolean isSignatureBeforeQuotedText, boolean isDraft) {
    String expectedText;
    int expectedMessageLength;
    int expectedMessagePosition;
    // 3.signature
    if (quoteStyle == QuoteStyle.PREFIX && isReplyAfterQuote) {
        String expectedQuotedText = "";
        if (isDraft || includeQuotedText) {
            expectedQuotedText = "quoted text" + "\r\n";
        }
        expectedText = expectedQuotedText;
        expectedText += "message content";
        if (!isDraft && isSignatureUse) {
            expectedText += "\r\n" + "signature";
        }
        expectedMessageLength = "message content".length();
        expectedMessagePosition = expectedQuotedText.length();
    } else // 3.quoted text
    if (isSignatureBeforeQuotedText) {
        expectedText = "message content";
        if (!isDraft && isSignatureUse) {
            expectedText += "\r\n" + "signature";
        }
        if (isDraft || includeQuotedText) {
            expectedText += "\r\n\r\nquoted text";
        }
        expectedMessageLength = "message content".length();
        expectedMessagePosition = 0;
    } else // 1.message content
    // 2.quoted text
    // 3.signature
    {
        expectedText = "message content";
        if (isDraft || includeQuotedText) {
            expectedText += "\r\n\r\nquoted text";
        }
        if (!isDraft && isSignatureUse) {
            expectedText += "\r\n" + "signature";
        }
        expectedMessageLength = "message content".length();
        expectedMessagePosition = 0;
    }
    String quotedText = "quoted text";
    String messageText = "message content";
    String signatureText = "signature";
    TestingTextBodyBuilder textBodyBuilder = new TestingTextBodyBuilder(includeQuotedText, isDraft, quoteStyle, isReplyAfterQuote, isSignatureBeforeQuotedText, isSignatureUse, messageText, signatureText);
    textBodyBuilder.setQuotedText(quotedText);
    TextBody textBody = textBodyBuilder.buildTextPlain();
    assertThat(textBody, instanceOf(TextBody.class));
    assertThat(textBody.getRawText(), is(expectedText));
    assertThat(textBody.getComposedMessageLength(), is(expectedMessageLength));
    assertThat(textBody.getComposedMessageOffset(), is(expectedMessagePosition));
    assertThat(textBody.getRawText().substring(expectedMessagePosition, expectedMessagePosition + expectedMessageLength), is("message content"));
}
Also used : TextBody(com.fsck.k9.mail.internet.TextBody) Theory(org.junit.experimental.theories.Theory)

Example 62 with Theory

use of org.junit.experimental.theories.Theory in project k-9 by k9mail.

the class TextBodyBuilderTest method testBuildTextHtml.

@Theory
public void testBuildTextHtml(boolean includeQuotedText, QuoteStyle quoteStyle, boolean isReplyAfterQuote, boolean isSignatureUse, boolean isSignatureBeforeQuotedText, boolean isDraft) {
    String expectedText;
    int expectedMessageLength;
    int expectedMessagePosition = 0;
    String expectedHtmlContent;
    String expectedPrefix = "";
    if (includeQuotedText && quoteStyle == QuoteStyle.PREFIX && isReplyAfterQuote && !isDraft) {
        expectedPrefix = "<br clear=\"all\">";
    }
    String expectedPostfix = "";
    if (!isDraft && includeQuotedText) {
        expectedPostfix = "<br><br>";
    }
    // 3.signature
    if (quoteStyle == QuoteStyle.PREFIX && isReplyAfterQuote) {
        expectedText = expectedPrefix + "<html>message content";
        if (!isDraft && isSignatureUse) {
            expectedText += "\r\n" + "signature";
        }
        expectedText += "</html>";
        expectedMessageLength = expectedText.length();
        String quotedContent = "quoted text";
        if (isDraft || includeQuotedText) {
            expectedHtmlContent = makeExpectedHtmlContent(expectedText, quotedContent, 0, false, expectedText, expectedText + quotedContent);
            expectedText += quotedContent;
        } else {
            expectedHtmlContent = makeExpectedHtmlContent(expectedText, quotedContent, 0, true, "", quotedContent);
        // expectedText += quotedContent;
        }
    } else // 3.quoted text
    if (isSignatureBeforeQuotedText) {
        expectedText = expectedPrefix + "<html>message content";
        if (!isDraft && isSignatureUse) {
            expectedText += "\r\n" + "signature";
        }
        expectedText += "</html>";
        expectedText += expectedPostfix;
        expectedMessageLength = expectedText.length();
        String quotedContent = "quoted text";
        if (isDraft || includeQuotedText) {
            expectedHtmlContent = makeExpectedHtmlContent(expectedText, quotedContent, 0, true, expectedText, expectedText + quotedContent);
            expectedText += quotedContent;
        } else {
            expectedHtmlContent = makeExpectedHtmlContent(expectedText, quotedContent, 0, true, "", quotedContent);
        // expectedText += quotedContent;
        }
    } else // 1.message content
    // 2.quoted text
    // 3.signature
    {
        String expectedSignature = "";
        expectedText = expectedPrefix + "<html>message content";
        if (!isDraft && isSignatureUse) {
            if (!includeQuotedText) {
                expectedText += "\r\n" + "signature";
            } else {
                expectedSignature = "<html>\r\nsignature</html>";
            }
        }
        expectedText += "</html>";
        expectedText += expectedPostfix;
        expectedMessageLength = expectedText.length();
        String quotedContent = "quoted text";
        if (isDraft || includeQuotedText) {
            expectedHtmlContent = makeExpectedHtmlContent(expectedText, expectedSignature + quotedContent, expectedSignature.length(), true, expectedText, expectedText + expectedSignature + quotedContent);
            expectedText += expectedSignature + quotedContent;
        } else {
            expectedHtmlContent = makeExpectedHtmlContent(expectedText, quotedContent, 0, true, "", quotedContent);
        // expectedText += quotedContent;
        }
    }
    InsertableHtmlContent insertableHtmlContent = new InsertableHtmlContent();
    String quotedText = "quoted text";
    insertableHtmlContent.setQuotedContent(new StringBuilder(quotedText));
    String messageText = "message content";
    String signatureText = "signature";
    TestingTextBodyBuilder textBodyBuilder = new TestingTextBodyBuilder(includeQuotedText, isDraft, quoteStyle, isReplyAfterQuote, isSignatureBeforeQuotedText, isSignatureUse, messageText, signatureText);
    textBodyBuilder.setQuotedTextHtml(insertableHtmlContent);
    TextBody textBody = textBodyBuilder.buildTextHtml();
    assertThat(textBody, instanceOf(TextBody.class));
    assertThat(textBody.getRawText(), is(expectedText));
    assertThat(textBody.getComposedMessageLength(), is(expectedMessageLength));
    assertThat(textBody.getComposedMessageOffset(), is(expectedMessagePosition));
    assertThat(insertableHtmlContent.toDebugString(), is(expectedHtmlContent));
}
Also used : TextBody(com.fsck.k9.mail.internet.TextBody) InsertableHtmlContent(com.fsck.k9.message.quote.InsertableHtmlContent) Theory(org.junit.experimental.theories.Theory)

Example 63 with Theory

use of org.junit.experimental.theories.Theory in project GCViewer by chewiebug.

the class ModelChartImplTest method shouldShowOrNotDateStampAccordingToModelAndSettings.

@Theory
public void shouldShowOrNotDateStampAccordingToModelAndSettings(TestCase testCase) throws Exception {
    //given
    ModelChartImpl modelChart = new ModelChartImpl();
    GCPreferences preferences = new GCPreferences();
    GCModel gcModel = Mockito.mock(GCModel.class);
    Mockito.when(gcModel.hasDateStamp()).thenReturn(testCase.hasDateStamp());
    Mockito.when(gcModel.getFirstDateStamp()).thenReturn(ZonedDateTime.now());
    Mockito.when(gcModel.getPause()).thenReturn(new DoubleData());
    preferences.setShowDateStamp(testCase.isShowDateStamp());
    //when
    modelChart.setModel(gcModel, preferences);
    //then
    assertThat(modelChart.isShowDateStamp(), equalTo(testCase.isExpectedShowDateStamp()));
}
Also used : GCPreferences(com.tagtraum.perf.gcviewer.view.model.GCPreferences) ModelChartImpl(com.tagtraum.perf.gcviewer.view.ModelChartImpl) GCModel(com.tagtraum.perf.gcviewer.model.GCModel) DoubleData(com.tagtraum.perf.gcviewer.math.DoubleData) Theory(org.junit.experimental.theories.Theory)

Example 64 with Theory

use of org.junit.experimental.theories.Theory in project zeppelin by apache.

the class ElasticsearchInterpreterTest method testMisc.

@Theory
public void testMisc(ElasticsearchInterpreter interpreter) {
    InterpreterResult res = interpreter.interpret(null, null);
    assertEquals(Code.SUCCESS, res.code());
    res = interpreter.interpret("   \n \n ", null);
    assertEquals(Code.SUCCESS, res.code());
}
Also used : InterpreterResult(org.apache.zeppelin.interpreter.InterpreterResult) Theory(org.junit.experimental.theories.Theory)

Example 65 with Theory

use of org.junit.experimental.theories.Theory in project zeppelin by apache.

the class ElasticsearchInterpreterTest method testCompletion.

@Theory
public void testCompletion(ElasticsearchInterpreter interpreter) {
    final List<InterpreterCompletion> expectedResultOne = Arrays.asList(new InterpreterCompletion("count", "count"));
    final List<InterpreterCompletion> expectedResultTwo = Arrays.asList(new InterpreterCompletion("help", "help"));
    final List<InterpreterCompletion> resultOne = interpreter.completion("co", 0);
    final List<InterpreterCompletion> resultTwo = interpreter.completion("he", 0);
    final List<InterpreterCompletion> resultAll = interpreter.completion("", 0);
    Assert.assertEquals(expectedResultOne, resultOne);
    Assert.assertEquals(expectedResultTwo, resultTwo);
    final List<String> allCompletionList = new ArrayList<>();
    for (final InterpreterCompletion ic : resultAll) {
        allCompletionList.add(ic.getName());
    }
    Assert.assertEquals(ElasticsearchInterpreter.COMMANDS, allCompletionList);
}
Also used : InterpreterCompletion(org.apache.zeppelin.interpreter.thrift.InterpreterCompletion) ArrayList(java.util.ArrayList) Theory(org.junit.experimental.theories.Theory)

Aggregations

Theory (org.junit.experimental.theories.Theory)107 DataPoint (org.junit.experimental.theories.DataPoint)23 Test (org.junit.Test)22 Header (io.aeron.logbuffer.Header)15 DirectBuffer (org.agrona.DirectBuffer)15 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)13 DebugReceiveChannelEndpoint (io.aeron.driver.ext.DebugReceiveChannelEndpoint)11 DebugSendChannelEndpoint (io.aeron.driver.ext.DebugSendChannelEndpoint)11 UdpChannel (io.aeron.driver.media.UdpChannel)11 MediaDriver (io.aeron.driver.MediaDriver)8 Lock (java.util.concurrent.locks.Lock)7 InterpreterResult (org.apache.zeppelin.interpreter.InterpreterResult)7 LongAdder (java.util.concurrent.atomic.LongAdder)6 UnsafeBuffer (org.agrona.concurrent.UnsafeBuffer)6 PrimitiveCollection (org.neo4j.collection.primitive.PrimitiveCollection)6 InOrder (org.mockito.InOrder)5 InputStream (java.io.InputStream)4 BaseStream (java.util.stream.BaseStream)4 InterpreterContext (org.apache.zeppelin.interpreter.InterpreterContext)4 Metric (org.springframework.boot.actuate.metrics.Metric)4