• 如果您觉得本站非常有看点,那么赶紧使用Ctrl+D 收藏吧

Java Present类的典型用法和代码示例

java 2次浏览

本文整理汇总了Java中org.dmfs.optional.Present的典型用法代码示例。如果您正苦于以下问题:Java Present类的具体用法?Java Present怎么用?Java Present使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。

Present类属于org.dmfs.optional包,在下文中一共展示了Present类的40个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。

示例1: parsedFragment

点赞 3

import org.dmfs.optional.Present; //导入依赖的package包/类
private Optional<Fragment> parsedFragment()
{
    final UriEncoded uriEncoded = mUriEncoded;
    final int count = uriEncoded.length();
    if (count == 0 || uriEncoded.charAt(0) != '#')
    {
        // not a fragment
        return absent();
    }

    int i = 1;
    while (i < count && FRAGMENT_CHAR.contains(uriEncoded.charAt(i)))
    {
        ++i;
    }

    if (i != count)
    {
        // illegal character in fragment
        throw new IllegalArgumentException(
                String.format("Query %s contains illegal char %c at position %d", uriEncoded.toString(), uriEncoded.charAt(i), i));
    }

    return new Present<Fragment>(new SimpleFragment(uriEncoded.subSequence(1, count)));
}
 

开发者ID:dmfs,
项目名称:uri-toolkit,
代码行数:26,
代码来源:OptionalLazyFragment.java

示例2: parsedUserInfo

点赞 3

import org.dmfs.optional.Present; //导入依赖的package包/类
private Optional<UriEncoded> parsedUserInfo()
{
    final UriEncoded encodedAuthority = mEncodedAuthority;
    final int count = encodedAuthority.length();
    int i = 0;
    while (i < count && (REG_NAME_CHAR.contains(encodedAuthority.charAt(i)) || encodedAuthority.charAt(i) == ':'))
    {
        ++i;
    }

    if (i == count || encodedAuthority.charAt(i) != '@')
    {
        // no @ -> no user info
        return absent();
    }

    mEnd = i + 1 /* account for the "@" which is not part of the user info */;
    return new Present<>(encodedAuthority.subSequence(0, i));
}
 

开发者ID:dmfs,
项目名称:uri-toolkit,
代码行数:20,
代码来源:OptionalLazyUserInfo.java

示例3: parsedScheme

点赞 3

import org.dmfs.optional.Present; //导入依赖的package包/类
private Optional<Scheme> parsedScheme()
{
    final UriEncoded uriEncoded = mUriEncoded;
    final int count = uriEncoded.length();
    if (count < 2 || !ALPHA.contains(uriEncoded.charAt(0)))
    {
        // too short (to hold an ALPHA and a colon) or doesn't start with an ALPHA, not a scheme
        return absent();
    }

    int i = 1;
    while (i < count && SCHEME_CHAR.contains(uriEncoded.charAt(i)))
    {
        ++i;
    }

    if (i < 2 || i == count || uriEncoded.charAt(i) != ':')
    {
        // a scheme needs to be at least one character long and has to be terminated by a colon
        return absent();
    }
    mEnd = i + 1 /* account for the colon which is not part of the actual scheme */;
    return new Present<Scheme>(new ParsedScheme(uriEncoded.subSequence(0, i)));
}
 

开发者ID:dmfs,
项目名称:uri-toolkit,
代码行数:25,
代码来源:OptionalLazyScheme.java

示例4: testBackReferences

点赞 3

import org.dmfs.optional.Present; //导入依赖的package包/类
@Test
public void testBackReferences()
{
    // Single matching
    Predicate.Argument argumentA = when(mock(Predicate.Argument.class).backReference()).thenReturn(new Present<>(1)).getMock();
    assertTrue(backReferences(isPresent(1)).matches(
            when(mock(Predicate.class).arguments(any(TransactionContext.class))).thenReturn(new ArrayIterable<>(argumentA)).getMock()));
    // Single non-matching
    assertFalse(backReferences(isPresent(2)).matches(
            when(mock(Predicate.class).arguments(any(TransactionContext.class))).thenReturn(new ArrayIterable<>(argumentA)).getMock()));

    // Multiple
    Predicate.Argument aB = when(mock(Predicate.Argument.class).backReference()).thenReturn(new Present<>(1)).getMock();
    Predicate.Argument aC = when(mock(Predicate.Argument.class).backReference()).thenReturn(Absent.<Integer>absent()).getMock();
    Predicate.Argument aD = when(mock(Predicate.Argument.class).backReference()).thenReturn(new Present<>(3)).getMock();
    assertTrue(backReferences(isPresent(1), AbsentMatcher.<Integer>isAbsent(), isPresent(3)).matches(
            when(mock(Predicate.class).arguments(any(TransactionContext.class))).thenReturn(new ArrayIterable<>(aB, aC, aD)).getMock()));

    // Single with TC
    TransactionContext dummyTc = dummy(TransactionContext.class);
    Predicate.Argument argumentE = when(mock(Predicate.Argument.class).backReference()).thenReturn(new Present<>(1)).getMock();
    assertTrue(backReferences(dummyTc, isPresent(1)).matches(
            when(mock(Predicate.class).arguments(dummyTc)).thenReturn(new ArrayIterable<>(argumentE)).getMock()));
}
 

开发者ID:dmfs,
项目名称:ContentPal,
代码行数:25,
代码来源:PredicateMatcherTest.java

示例5: testParameters

点赞 3

import org.dmfs.optional.Present; //导入依赖的package包/类
@Test
public void testParameters() throws Exception
{
    Parametrized mockChallenge = mock(Parametrized.class);
    doReturn(new Present<>("[email protected]")).when(mockChallenge).parameter(Tokens.REALM);
    doReturn(new Present<>("dcd98b7102dd2f0e8b11d0f600bfb0c093")).when(mockChallenge).parameter(Tokens.NONCE);
    doReturn(new Present<>("5ccc069c403ebaf9f0171e9517f40e41")).when(mockChallenge).parameter(Tokens.OPAQUE);
    doReturn(new Present<>("MD5")).when(mockChallenge).parameter(Tokens.ALGORITHM);
    doReturn(absent()).when(mockChallenge).parameter(Tokens.USERHASH);

    UserCredentials mockUserCredentials = mock(UserCredentials.class);
    doReturn("Mufasa").when(mockUserCredentials).userName();
    doReturn("Circle Of Life").when(mockUserCredentials).password();

    Authorization authorization = new AuthDigestAuthorization(HttpMethod.GET, URI.create("/dir/index.html"), mockChallenge, mockUserCredentials, "0a4f113b",
            1);
    for (Pair<Token, CharSequence> param : authorization.parameters())
    {
        System.out.println(String.format("%s: %s", param.left(), param.right().toString()));
    }
    System.out.println(new SingleCredentials(authorization).value().toString());
}
 

开发者ID:dmfs,
项目名称:http-client-essentials-suite,
代码行数:23,
代码来源:AuthDigestAuthorizationTest.java

示例6: testParameters2

点赞 3

import org.dmfs.optional.Present; //导入依赖的package包/类
@Test
public void testParameters2() throws Exception
{
    Parametrized mockChallenge = mock(Parametrized.class);
    doReturn(new Present<>("[email protected]")).when(mockChallenge).parameter(Tokens.REALM);
    doReturn(new Present<>("7ypf/xlj9XXwfDPEoM4URrv/xwf94BcCAzFZH4GiTo0v")).when(mockChallenge).parameter(Tokens.NONCE);
    doReturn(new Present<>("FQhe/qaU925kfnzjCev0ciny7QMkPqMAFRtzCUYo5tdS")).when(mockChallenge).parameter(Tokens.OPAQUE);
    doReturn(new Present<>("SHA-256")).when(mockChallenge).parameter(Tokens.ALGORITHM);
    doReturn(absent()).when(mockChallenge).parameter(Tokens.USERHASH);

    UserCredentials mockUserCredentials = mock(UserCredentials.class);
    doReturn("Mufasa").when(mockUserCredentials).userName();
    doReturn("Circle Of Life").when(mockUserCredentials).password();

    Authorization authorization = new AuthDigestAuthorization(HttpMethod.GET, URI.create("/dir/index.html"), mockChallenge, mockUserCredentials,
            "f2/wE4q74E6zIJEtWaHKaf5wv/H5QzzpXusqGemxURZJ", 1);
    for (Pair<Token, CharSequence> param : authorization.parameters())
    {
        System.out.println(String.format("%s: %s", param.left(), param.right().toString()));
    }
    System.out.println(new SingleCredentials(authorization).value().toString());
}
 

开发者ID:dmfs,
项目名称:http-client-essentials-suite,
代码行数:23,
代码来源:AuthDigestAuthorizationTest.java

示例7: testParameters3

点赞 3

import org.dmfs.optional.Present; //导入依赖的package包/类
@Test
public void testParameters3() throws Exception
{
    Parametrized mockChallenge = mock(Parametrized.class);
    doReturn(new Present<>("[email protected]")).when(mockChallenge).parameter(Tokens.REALM);
    doReturn(new Present<>("7ypf/xlj9XXwfDPEoM4URrv/xwf94BcCAzFZH4GiTo0v")).when(mockChallenge).parameter(Tokens.NONCE);
    doReturn(new Present<>("FQhe/qaU925kfnzjCev0ciny7QMkPqMAFRtzCUYo5tdS")).when(mockChallenge).parameter(Tokens.OPAQUE);
    doReturn(new Present<>("MD5")).when(mockChallenge).parameter(Tokens.ALGORITHM);
    doReturn(absent()).when(mockChallenge).parameter(Tokens.USERHASH);

    UserCredentials mockUserCredentials = mock(UserCredentials.class);
    doReturn("Mufasa").when(mockUserCredentials).userName();
    doReturn("Circle Of Life").when(mockUserCredentials).password();

    Authorization authorization = new AuthDigestAuthorization(HttpMethod.GET, URI.create("/dir/index.html"), mockChallenge, mockUserCredentials,
            "f2/wE4q74E6zIJEtWaHKaf5wv/H5QzzpXusqGemxURZJ", 1);
    for (Pair<Token, CharSequence> param : authorization.parameters())
    {
        System.out.println(String.format("%s: %s", param.left(), param.right().toString()));
    }
    System.out.println(new SingleCredentials(authorization).value().toString());
}
 

开发者ID:dmfs,
项目名称:http-client-essentials-suite,
代码行数:23,
代码来源:AuthDigestAuthorizationTest.java

示例8: testParameters4

点赞 3

import org.dmfs.optional.Present; //导入依赖的package包/类
@Test
public void testParameters4() throws Exception
{
    Parametrized mockChallenge = mock(Parametrized.class);
    doReturn(new Present<>("[email protected]")).when(mockChallenge).parameter(Tokens.REALM);
    doReturn(new Present<>("7ypf/xlj9XXwfDPEoM4URrv/xwf94BcCAzFZH4GiTo0v")).when(mockChallenge).parameter(Tokens.NONCE);
    doReturn(new Present<>("FQhe/qaU925kfnzjCev0ciny7QMkPqMAFRtzCUYo5tdS")).when(mockChallenge).parameter(Tokens.OPAQUE);
    doReturn(new Present<>("SHA-256")).when(mockChallenge).parameter(Tokens.ALGORITHM);
    doReturn(new Present<>("true")).when(mockChallenge).parameter(Tokens.USERHASH);

    UserCredentials mockUserCredentials = mock(UserCredentials.class);
    doReturn("Mufasa").when(mockUserCredentials).userName();
    doReturn("Circle Of Life").when(mockUserCredentials).password();

    Authorization authorization = new AuthDigestAuthorization(HttpMethod.GET, URI.create("/dir/index.html"), mockChallenge, mockUserCredentials,
            "f2/wE4q74E6zIJEtWaHKaf5wv/H5QzzpXusqGemxURZJ", 1);
    for (Pair<Token, CharSequence> param : authorization.parameters())
    {
        System.out.println(String.format("%s: %s", param.left(), param.right().toString()));
    }
    System.out.println(new SingleCredentials(authorization).value().toString());
}
 

开发者ID:dmfs,
项目名称:http-client-essentials-suite,
代码行数:23,
代码来源:AuthDigestAuthorizationTest.java

示例9: testParameters

点赞 3

import org.dmfs.optional.Present; //导入依赖的package包/类
@Test
public void testParameters() throws Exception
{
    Parametrized mockChallenge = mock(Parametrized.class);
    doReturn(new Present<>("[email protected]")).when(mockChallenge).parameter(Tokens.REALM);
    doReturn(new Present<>("dcd98b7102dd2f0e8b11d0f600bfb0c093")).when(mockChallenge).parameter(Tokens.NONCE);
    doReturn(new Present<>("5ccc069c403ebaf9f0171e9517f40e41")).when(mockChallenge).parameter(Tokens.OPAQUE);
    doReturn(absent()).when(mockChallenge).parameter(Tokens.ALGORITHM);

    UserCredentials mockUserCredentials = mock(UserCredentials.class);
    doReturn("Mufasa").when(mockUserCredentials).userName();
    doReturn("CircleOfLife").when(mockUserCredentials).password();

    Authorization authorization = new DigestAuthorization(HttpMethod.GET, URI.create("/dir/index.html"), mockChallenge, mockUserCredentials);
    for (Pair<Token, CharSequence> param : authorization.parameters())
    {
        System.out.println(String.format("%s: %s", param.left(), param.right().toString()));
    }
    System.out.println(new SingleCredentials(authorization).value().toString());
}
 

开发者ID:dmfs,
项目名称:http-client-essentials-suite,
代码行数:21,
代码来源:DigestAuthorizationTest.java

示例10: testWithDateAndOriginalTime

点赞 3

import org.dmfs.optional.Present; //导入依赖的package包/类
@Test
public void testWithDateAndOriginalTime() throws Exception
{
    DateTime start = DateTime.now();
    DateTime due = start.addDuration(Duration.parse("P1DT1H"));
    DateTime original = start.addDuration(Duration.parse("P2DT2H"));
    assertThat(new InstanceTestData(start, due, new Present<>(original), 5),
            builds(
                    withValuesOnly(
                            containing(TaskContract.Instances.INSTANCE_START, start.getTimestamp()),
                            containing(TaskContract.Instances.INSTANCE_START_SORTING, start.swapTimeZone(TimeZone.getDefault()).getInstance()),
                            containing(TaskContract.Instances.INSTANCE_DUE, due.getTimestamp()),
                            containing(TaskContract.Instances.INSTANCE_DUE_SORTING, due.swapTimeZone(TimeZone.getDefault()).getInstance()),
                            containing(TaskContract.Instances.INSTANCE_DURATION, due.getTimestamp() - start.getTimestamp()),
                            containing(TaskContract.Instances.INSTANCE_ORIGINAL_TIME, original.getTimestamp()),
                            containing(TaskContract.Instances.DISTANCE_FROM_CURRENT, 5),
                            containing(TaskContract.Instances.DTSTART, start.getTimestamp()),
                            containing(TaskContract.Instances.DUE, due.getTimestamp()),
                            containing(TaskContract.Instances.ORIGINAL_INSTANCE_TIME, original.getTimestamp()),
                            withNullValue(TaskContract.Instances.DURATION),
                            withNullValue(TaskContract.Instances.RRULE),
                            withNullValue(TaskContract.Instances.RDATE),
                            withNullValue(TaskContract.Instances.EXDATE)
                    )
            ));
}
 

开发者ID:dmfs,
项目名称:opentasks,
代码行数:27,
代码来源:InstanceTestDataTest.java

示例11: testWithStartDateAndOriginalTime

点赞 3

import org.dmfs.optional.Present; //导入依赖的package包/类
@Test
public void testWithStartDateAndOriginalTime() throws Exception
{
    DateTime start = DateTime.now();
    DateTime original = start.addDuration(Duration.parse("P2DT2H"));
    assertThat(new InstanceTestData(new Present<>(start), absent(), new Present<>(original), 5),
            builds(
                    withValuesOnly(
                            containing(TaskContract.Instances.INSTANCE_START, start.getTimestamp()),
                            containing(TaskContract.Instances.INSTANCE_START_SORTING, start.swapTimeZone(TimeZone.getDefault()).getInstance()),
                            withNullValue(TaskContract.Instances.INSTANCE_DUE),
                            withNullValue(TaskContract.Instances.INSTANCE_DUE_SORTING),
                            withNullValue(TaskContract.Instances.INSTANCE_DURATION),
                            containing(TaskContract.Instances.INSTANCE_ORIGINAL_TIME, original.getTimestamp()),
                            containing(TaskContract.Instances.DISTANCE_FROM_CURRENT, 5),
                            containing(TaskContract.Instances.DTSTART, start.getTimestamp()),
                            containing(TaskContract.Instances.ORIGINAL_INSTANCE_TIME, original.getTimestamp()),
                            withNullValue(TaskContract.Instances.DUE),
                            withNullValue(TaskContract.Instances.DURATION),
                            withNullValue(TaskContract.Instances.RRULE),
                            withNullValue(TaskContract.Instances.RDATE),
                            withNullValue(TaskContract.Instances.EXDATE)
                    )
            ));
}
 

开发者ID:dmfs,
项目名称:opentasks,
代码行数:26,
代码来源:InstanceTestDataTest.java

示例12: testWithDueDateAndOriginalTime

点赞 3

import org.dmfs.optional.Present; //导入依赖的package包/类
@Test
public void testWithDueDateAndOriginalTime() throws Exception
{
    DateTime due = DateTime.now();
    DateTime original = due.addDuration(Duration.parse("P2DT2H"));
    assertThat(new InstanceTestData(absent(), new Present<>(due), new Present<>(original), 5),
            builds(
                    withValuesOnly(
                            withNullValue(TaskContract.Instances.INSTANCE_START),
                            withNullValue(TaskContract.Instances.INSTANCE_START_SORTING),
                            containing(TaskContract.Instances.INSTANCE_DUE, due.getTimestamp()),
                            containing(TaskContract.Instances.INSTANCE_DUE_SORTING, due.swapTimeZone(TimeZone.getDefault()).getInstance()),
                            withNullValue(TaskContract.Instances.INSTANCE_DURATION),
                            containing(TaskContract.Instances.INSTANCE_ORIGINAL_TIME, original.getTimestamp()),
                            containing(TaskContract.Instances.DISTANCE_FROM_CURRENT, 5),
                            withNullValue(TaskContract.Instances.DTSTART),
                            containing(TaskContract.Instances.DUE, due.getTimestamp()),
                            containing(TaskContract.Instances.ORIGINAL_INSTANCE_TIME, original.getTimestamp()),
                            withNullValue(TaskContract.Instances.DURATION),
                            withNullValue(TaskContract.Instances.RRULE),
                            withNullValue(TaskContract.Instances.RDATE),
                            withNullValue(TaskContract.Instances.EXDATE)
                    )
            ));
}
 

开发者ID:dmfs,
项目名称:opentasks,
代码行数:26,
代码来源:InstanceTestDataTest.java

示例13: test_whenDueIsAbsent_startIsPresent_durationIsPresent_shouldUseStartPlusDuration

点赞 3

import org.dmfs.optional.Present; //导入依赖的package包/类
@Test
public void test_whenDueIsAbsent_startIsPresent_durationIsPresent_shouldUseStartPlusDuration()
{
    long timestamp = System.currentTimeMillis();

    RowDataSnapshot<Tasks> mockData = failingMock(RowDataSnapshot.class);
    doReturn(absent()).when(mockData).data(eq(Tasks.DUE), any());
    doReturn(new Present<>(timestamp)).when(mockData).data(eq(Tasks.DTSTART), any());
    doReturn(new Present<>(Duration.parse("PT2H"))).when(mockData).data(eq(Tasks.DURATION), any());
    doReturn(new Present<>(false)).when(mockData).data(eq(Tasks.IS_ALLDAY), any());
    doReturn(new Present<>(TimeZone.getTimeZone("Europe/Berlin"))).when(mockData).data(eq(Tasks.TZ), any());

    DateTime actual = new EffectiveDueDate(mockData).value();
    assertEquals(timestamp + TimeUnit.HOURS.toMillis(2), actual.getTimestamp());
    assertFalse(actual.isAllDay());
    assertEquals("Europe/Berlin", actual.getTimeZone().getID());
}
 

开发者ID:dmfs,
项目名称:opentasks,
代码行数:18,
代码来源:EffectiveDueDateTest.java

示例14: parsedAuthority

点赞 2

import org.dmfs.optional.Present; //导入依赖的package包/类
private Optional<Authority> parsedAuthority()
{
    if (mUriEncoded.length() < 2 || mUriEncoded.charAt(0) != '/' || mUriEncoded.charAt(1) != '/')
    {
        // too short or not starting with "//", not an authority
        return absent();
    }
    // this looks like an authority
    return new Present<Authority>(new EncodedAuthority(mUriEncoded.subSequence(2, mUriEncoded.length())));
}
 

开发者ID:dmfs,
项目名称:uri-toolkit,
代码行数:11,
代码来源:OptionalLazyAuthority.java

示例15: parsedPort

点赞 2

import org.dmfs.optional.Present; //导入依赖的package包/类
private Optional<Integer> parsedPort()
{
    final UriEncoded authority = mAuthority;
    final int count = authority.length();
    final int portPos = host().length() + userInfo().parsedLength();
    if (portPos + 1 >= count || authority.charAt(portPos) != ':')
    {
        mEnd = portPos;
        // no port
        return absent();
    }
    int port = 0;
    int i = portPos + 1;
    while (i < count && DIGIT.contains(authority.charAt(i)))
    {
        port = port * 10 + authority.charAt(i) - '0';
        ++i;
    }
    mEnd = i;
    if (i == count)
    {
        // end of string
        return new Present<>(port);
    }
    char next = authority.charAt(i);
    if (next != '/' && next != '?' && next != '#')
    {
        // port not followed by a valid character
        throw new IllegalArgumentException(
                String.format("Authority %s contains illegal char %c at position %d", mAuthority.toString(), next, i));
    }
    return new Present<>(port);

}
 

开发者ID:dmfs,
项目名称:uri-toolkit,
代码行数:35,
代码来源:EncodedAuthority.java

示例16: parsedQuery

点赞 2

import org.dmfs.optional.Present; //导入依赖的package包/类
private Optional<Query> parsedQuery()
{
    final UriEncoded encoded = mUriEncoded;
    final int count = encoded.length();

    if (count == 0 || encoded.charAt(0) != '?')
    {
        // not a query
        return absent();
    }

    int i = 1;
    while (i < count && QUERY_CHAR.contains(encoded.charAt(i)))
    {
        ++i;
    }

    if (i < count && encoded.charAt(i) != '#')
    {
        // the query can only be terminated by the end of the string or a fragment
        throw new IllegalArgumentException(
                String.format("Query %s contains illegal char %c at position %d", encoded.toString(), encoded.charAt(i), i));
    }

    mEnd = i;
    return new Present<Query>(new SimpleQuery(encoded.subSequence(1 /* don't include the "?" */, i)));
}
 

开发者ID:dmfs,
项目名称:uri-toolkit,
代码行数:28,
代码来源:OptionalLazyQuery.java

示例17: absentBackReferences

点赞 2

import org.dmfs.optional.Present; //导入依赖的package包/类
@Factory
public static Matcher<Predicate> absentBackReferences(TransactionContext tc, int noOfPredicateArguments)
{
    Matcher[] matchers = new Matcher[noOfPredicateArguments];
    Arrays.fill(matchers, isAbsent());
    return new ArgumentBackReferences(new Present<>(tc), matchers);
}
 

开发者ID:dmfs,
项目名称:ContentPal,
代码行数:8,
代码来源:PredicateMatcher.java

示例18: contentLength

点赞 2

import org.dmfs.optional.Present; //导入依赖的package包/类
@Override
public Optional<Long> contentLength()
{
    try
    {
        return new Present<>((long) toString().getBytes(ENCODING).length);
    }
    catch (UnsupportedEncodingException e)
    {
        throw new RuntimeException(String.format(Locale.ENGLISH, "%s encoding not supported by runtime", ENCODING));
    }
}
 

开发者ID:dmfs,
项目名称:oauth2-essentials,
代码行数:13,
代码来源:XWwwFormUrlEncodedEntity.java

示例19: contentLength

点赞 2

import org.dmfs.optional.Present; //导入依赖的package包/类
@Override
public Optional<Long> contentLength()
{
    long length;
    try
    {
        length = mConnection.getContentLengthLong();
    }
    catch (NoSuchMethodError e)
    {
        // getContentLengthLong has been added in Java 7 and Android SDK 24, fall back to integer on older runtime engines
        length = mConnection.getContentLength();
    }
    return length < 0 ? Absent.<Long>absent() : new Present<>(length);
}
 

开发者ID:dmfs,
项目名称:http-client-essentials-suite,
代码行数:16,
代码来源:HttpUrlConnectionResponseEntity.java

示例20: responseEntity

点赞 2

import org.dmfs.optional.Present; //导入依赖的package包/类
@Override
public HttpResponseEntity responseEntity()
{
    return new HttpResponseEntity()
    {

        @Override
        public Optional<MediaType> contentType()
        {
            return new NullSafe<>(mResponseMediaType);
        }


        @Override
        public InputStream contentStream() throws IOException
        {
            return new ByteArrayInputStream(mResponse);
        }


        @Override
        public Optional<Long> contentLength()
        {
            return mContentLength < 0 ? Absent.<Long>absent() : new Present<Long>((long) mContentLength);
        }
    };
}
 

开发者ID:dmfs,
项目名称:http-client-essentials-suite,
代码行数:28,
代码来源:StringResponseHandlerTest.java

示例21: authorization

点赞 2

import org.dmfs.optional.Present; //导入依赖的package包/类
@Override
public Optional<Authorization> authorization()
{
    if (!mDigestChallenge.parameter(Tokens.QOP).isPresent() || !mDigestChallenge.parameter(Tokens.OPAQUE)
            .isPresent() || !mDigestChallenge.parameter(Tokens.REALM).isPresent())
    {
        return new Present<Authorization>(new DigestAuthorization(mHttpMethod, mUri, mDigestChallenge, mCredentials));
    }
    // qop must be auth, we don't support auth-int and wouldn't be here if auth wasn't an option
    return new Present<Authorization>(
            new AuthDigestAuthorization(mHttpMethod, mUri, mDigestChallenge, mCredentials, new Hex(new SecureRandom().generateSeed(16)), mNonceCount));
}
 

开发者ID:dmfs,
项目名称:http-client-essentials-suite,
代码行数:13,
代码来源:AuthenticatedDigestAuthState.java

示例22: testAuthState

点赞 2

import org.dmfs.optional.Present; //导入依赖的package包/类
/**
 * Test regular authorization with credentials.
 */
@Test
public void testAuthState() throws Exception
{
    final URI mockUri = URI.create("https://example.com");
    AuthState mockAuthState = failingMock(AuthState.class);
    AuthState mockNextAuthState = failingMock(AuthState.class);
    Iterable<Challenge> mockChallenges = failingMock(Iterable.class);
    doReturn(mockNextAuthState).when(mockAuthState).withChallenges(mockChallenges);

    UserCredentials mockCredentials = failingMock(UserCredentials.class);
    doReturn("x").when(mockCredentials).userName();
    doReturn("y").when(mockCredentials).password();

    CredentialsStore<UserCredentials> mockStore = failingMock(CredentialsStore.class);
    doReturn(new Present<>(mockCredentials)).when(mockStore).credentials(argThat(new ArgumentMatcher<AuthScope>()
    {
        @Override
        public boolean matches(AuthScope argument)
        {
            return argument.uri() == mockUri && !argument.realm().isPresent();
        }
    }));

    // get an AuthState from the strategy
    AuthState result = new PrematureBasicAuthStrategy(mockStore).authState(dummy(HttpMethod.class), mockUri, mockAuthState);

    // AuthState should fall back to the fallback state if presented with challenges
    assertThat(result.withChallenges(mockChallenges), sameInstance(mockNextAuthState));
    // It should return a Basic Authorization with the given credentials
    assertThat(result.authorization().value().scheme().toString(), is("Basic"));
    assertThat(result.authorization().value().parameters(), Matchers.<Pair<Token, CharSequence>>emptyIterable());
    assertThat(result.authorization().value().token().value().toString(), is("eDp5"));
    // it should also return a prematureAuthStrategy which behaves exactly the same
    AuthState prematureAuth = result.prematureAuthStrategy(Absent.<AuthInfo>absent()).authState(dummy(HttpMethod.class), mockUri, mockAuthState);
    assertThat(prematureAuth.withChallenges(mockChallenges), sameInstance(mockNextAuthState));
    assertThat(prematureAuth.authorization().value().scheme().toString(), is("Basic"));
    assertThat(prematureAuth.authorization().value().parameters(), Matchers.<Pair<Token, CharSequence>>emptyIterable());
    assertThat(prematureAuth.authorization().value().token().value().toString(), is("eDp5"));
}
 

开发者ID:dmfs,
项目名称:http-client-essentials-suite,
代码行数:43,
代码来源:PrematureBasicAuthStrategyTest.java

示例23: testExecuteDigest

点赞 2

import org.dmfs.optional.Present; //导入依赖的package包/类
@Test
public void testExecuteDigest() throws Exception
{
    HttpRequestExecutor executor = new Authorizing(new HttpUrlConnectionExecutor(), new Composite(new UserCredentialsAuthStrategy(
            new CredentialsStore<UserCredentials>()
            {
                @Override
                public Optional<UserCredentials> credentials(AuthScope authScope)
                {
                    return new Present<UserCredentials>(new UserCredentials()
                    {
                        @Override
                        public CharSequence userName()
                        {
                            return "user";
                        }


                        @Override
                        public CharSequence password()
                        {
                            return "passwd";
                        }
                    });
                }
            })));

    String response = executor.execute(URI.create("http://localhost:5000/digest-auth/auth/user/passwd/MD5/never"), new StringHttpRequest());
    response = executor.execute(URI.create("http://localhost:5000/digest-auth/auth/user/passwd/MD5/never"), new StringHttpRequest());
    response = executor.execute(URI.create("http://localhost:5000/digest-auth/auth/user/passwd/MD5/never"), new StringHttpRequest());

    System.out.println(response);
}
 

开发者ID:dmfs,
项目名称:http-client-essentials-suite,
代码行数:34,
代码来源:AuthorizingTest.java

示例24: testExecuteBasic

点赞 2

import org.dmfs.optional.Present; //导入依赖的package包/类
@Test
public void testExecuteBasic() throws Exception
{
    HttpRequestExecutor executor = new Authorizing(new HttpUrlConnectionExecutor(), new Composite(new UserCredentialsAuthStrategy(
            new CredentialsStore<UserCredentials>()
            {
                @Override
                public Optional<UserCredentials> credentials(AuthScope authScope)
                {
                    return new Present<UserCredentials>(new UserCredentials()
                    {
                        @Override
                        public CharSequence userName()
                        {
                            return "user";
                        }


                        @Override
                        public CharSequence password()
                        {
                            return "passwd";
                        }
                    });
                }
            })));

    String response = executor.execute(URI.create("http://localhost:5000/basic-auth/user/passwd"), new StringHttpRequest());
    response = executor.execute(URI.create("http://localhost:5000/basic-auth/user/passwd"), new StringHttpRequest());
    response = executor.execute(URI.create("http://localhost:5000/basic-auth/user/passwd"), new StringHttpRequest());

    System.out.println(response);
}
 

开发者ID:dmfs,
项目名称:http-client-essentials-suite,
代码行数:34,
代码来源:AuthorizingTest.java

示例25: testStartEurope

点赞 2

import org.dmfs.optional.Present; //导入依赖的package包/类
@Test
public void testStartEurope() throws Exception
{
    DateTime start = DateTime.parse("Europe/Berlin", "20171208T125500");

    ContentValues instanceData = new DueDated(new Present<>(start), ContentValues::new).value();

    assertThat(instanceData, new ContentValuesWithLong(TaskContract.Instances.INSTANCE_DUE, start.getTimestamp()));
    assertThat(instanceData,
            new ContentValuesWithLong(TaskContract.Instances.INSTANCE_DUE_SORTING, start.shiftTimeZone(TimeZone.getDefault()).getInstance()));
    assertThat(instanceData.size(), is(2));
}
 

开发者ID:dmfs,
项目名称:opentasks,
代码行数:13,
代码来源:DueDatedTest.java

示例26: testStartAmerica

点赞 2

import org.dmfs.optional.Present; //导入依赖的package包/类
@Test
public void testStartAmerica() throws Exception
{
    DateTime start = DateTime.parse("America/New_York", "20171208T125500");

    ContentValues instanceData = new DueDated(new Present<>(start), ContentValues::new).value();

    assertThat(instanceData, new ContentValuesWithLong(TaskContract.Instances.INSTANCE_DUE, start.getTimestamp()));
    assertThat(instanceData,
            new ContentValuesWithLong(TaskContract.Instances.INSTANCE_DUE_SORTING, start.shiftTimeZone(TimeZone.getDefault()).getInstance()));
    assertThat(instanceData.size(), is(2));
}
 

开发者ID:dmfs,
项目名称:opentasks,
代码行数:13,
代码来源:DueDatedTest.java

示例27: testPresent

点赞 2

import org.dmfs.optional.Present; //导入依赖的package包/类
@Test
public void testPresent() throws Exception
{
    DateTime start = DateTime.parse("Europe/Berlin", "20171208T125500");

    ContentValues instanceData = new Dated(new Present<>(start), "ts", "sorting", ContentValues::new).value();

    assertThat(instanceData, new ContentValuesWithLong("ts", start.getTimestamp()));
    assertThat(instanceData, new ContentValuesWithLong("sorting", start.getInstance()));
    assertThat(instanceData.size(), is(2));
}
 

开发者ID:dmfs,
项目名称:opentasks,
代码行数:12,
代码来源:DatedTest.java

示例28: testPresent

点赞 2

import org.dmfs.optional.Present; //导入依赖的package包/类
@Test
public void testPresent() throws Exception
{

    ContentValues instanceData = new Overridden(new Present<>(new DateTime(40)), ContentValues::new).value();
    assertThat(instanceData, new ContentValuesWithLong(TaskContract.Instances.INSTANCE_ORIGINAL_TIME, 40));
    assertThat(instanceData.size(), is(1));
}
 

开发者ID:dmfs,
项目名称:opentasks,
代码行数:9,
代码来源:OverriddenTest.java

示例29: testPresentWithStartAndDue

点赞 2

import org.dmfs.optional.Present; //导入依赖的package包/类
@Test
public void testPresentWithStartAndDue() throws Exception
{
    ContentValues values = new ContentValues();
    values.put(TaskContract.Instances.INSTANCE_START, 10);
    values.put(TaskContract.Instances.INSTANCE_DUE, 20);

    ContentValues instanceData = new Overridden(new Present<>(new DateTime(40)), () -> new ContentValues(values)).value();
    assertThat(instanceData, new ContentValuesWithLong(TaskContract.Instances.INSTANCE_ORIGINAL_TIME, 40));
    assertThat(instanceData.size(), is(3));
}
 

开发者ID:dmfs,
项目名称:opentasks,
代码行数:12,
代码来源:OverriddenTest.java

示例30: testStartEurope

点赞 2

import org.dmfs.optional.Present; //导入依赖的package包/类
@Test
public void testStartEurope() throws Exception
{
    DateTime start = DateTime.parse("Europe/Berlin", "20171208T125500");

    ContentValues instanceData = new StartDated(new Present<>(start), ContentValues::new).value();

    assertThat(instanceData, new ContentValuesWithLong(TaskContract.Instances.INSTANCE_START, start.getTimestamp()));
    assertThat(instanceData,
            new ContentValuesWithLong(TaskContract.Instances.INSTANCE_START_SORTING, start.shiftTimeZone(TimeZone.getDefault()).getInstance()));
    assertThat(instanceData.size(), is(2));
}
 

开发者ID:dmfs,
项目名称:opentasks,
代码行数:13,
代码来源:StartDatedTest.java

示例31: testStartAmerica

点赞 2

import org.dmfs.optional.Present; //导入依赖的package包/类
@Test
public void testStartAmerica() throws Exception
{
    DateTime start = DateTime.parse("America/New_York", "20171208T125500");

    ContentValues instanceData = new StartDated(new Present<>(start), ContentValues::new).value();

    assertThat(instanceData, new ContentValuesWithLong(TaskContract.Instances.INSTANCE_START, start.getTimestamp()));
    assertThat(instanceData,
            new ContentValuesWithLong(TaskContract.Instances.INSTANCE_START_SORTING, start.shiftTimeZone(TimeZone.getDefault()).getInstance()));
    assertThat(instanceData.size(), is(2));
}
 

开发者ID:dmfs,
项目名称:opentasks,
代码行数:13,
代码来源:StartDatedTest.java

示例32: testPresent

点赞 2

import org.dmfs.optional.Present; //导入依赖的package包/类
@Test
public void testPresent()
{
    Object dummyPresentValue = new Object();
    Object dummySingleValue = new Object();
    Object dummyResult = new Object();
    BiFunction<Object, Object, Object> mockFunction = failingMock(BiFunction.class);
    doReturn(dummyResult).when(mockFunction).value(dummyPresentValue, dummySingleValue);
    assertThat(new Zipped<>(new Present<>(dummyPresentValue), new ValueSingle<>(dummySingleValue), mockFunction), hasValue(sameInstance(dummyResult)));
}
 

开发者ID:dmfs,
项目名称:opentasks,
代码行数:11,
代码来源:ZippedTest.java

示例33: test_whenTaskColorIsPresent_shouldReturnThat

点赞 2

import org.dmfs.optional.Present; //导入依赖的package包/类
@Test
public void test_whenTaskColorIsPresent_shouldReturnThat()
{
    RowDataSnapshot<Tasks> mockData = failingMock(RowDataSnapshot.class);
    doReturn(new Present<>(new ValueColor(123))).when(mockData).data(eq(Tasks.TASK_COLOR), any());
    doReturn(absent()).when(mockData).data(eq(Tasks.LIST_COLOR), any());

    assertThat(new EffectiveTaskColor(mockData).argb(), is(123));
}
 

开发者ID:dmfs,
项目名称:opentasks,
代码行数:10,
代码来源:EffectiveTaskColorTest.java

示例34: test_whenTaskColorIsAbsent_shouldReturnTaskListColor

点赞 2

import org.dmfs.optional.Present; //导入依赖的package包/类
@Test
public void test_whenTaskColorIsAbsent_shouldReturnTaskListColor()
{
    RowDataSnapshot<Tasks> mockData = failingMock(RowDataSnapshot.class);
    doReturn(absent()).when(mockData).data(eq(Tasks.TASK_COLOR), any());
    doReturn(new Present<>(new ValueColor(567))).when(mockData).data(eq(Tasks.LIST_COLOR), any());

    assertThat(new EffectiveTaskColor(mockData).argb(), is(567));
}
 

开发者ID:dmfs,
项目名称:opentasks,
代码行数:10,
代码来源:EffectiveTaskColorTest.java

示例35: test_whenIsAllDayIsPresentAndTrue_shouldReturnAllDayDateTime

点赞 2

import org.dmfs.optional.Present; //导入依赖的package包/类
@Test
public void test_whenIsAllDayIsPresentAndTrue_shouldReturnAllDayDateTime()
{
    long timeStamp = System.currentTimeMillis();

    RowDataSnapshot<Tasks> mockData = failingMock(RowDataSnapshot.class);
    doReturn(new Present<>(timeStamp)).when(mockData).data(eq(Tasks.DTSTART), any());
    doReturn(new Present<>(true)).when(mockData).data(eq(Tasks.IS_ALLDAY), any());

    DateTime actual = new TaskDateTime(Tasks.DTSTART, mockData).value();
    assertTrue(actual.isAllDay());
    assertEquals(new DateTime(timeStamp).toAllDay(), actual);
}
 

开发者ID:dmfs,
项目名称:opentasks,
代码行数:14,
代码来源:TaskDateTimeTest.java

示例36: test_whenIsAllDayIsPresentAndFalse_shouldReturnNotAllDayDateTime

点赞 2

import org.dmfs.optional.Present; //导入依赖的package包/类
@Test
public void test_whenIsAllDayIsPresentAndFalse_shouldReturnNotAllDayDateTime()
{
    long timeStamp = System.currentTimeMillis();

    RowDataSnapshot<Tasks> mockData = failingMock(RowDataSnapshot.class);
    doReturn(new Present<>(timeStamp)).when(mockData).data(eq(Tasks.DTSTART), any());
    doReturn(new Present<>(false)).when(mockData).data(eq(Tasks.IS_ALLDAY), any());
    doReturn(new Present<>(TimeZone.getTimeZone("UTC"))).when(mockData).data(eq(Tasks.TZ), any());

    DateTime actual = new TaskDateTime(Tasks.DTSTART, mockData).value();
    assertFalse(actual.isAllDay());
    assertEquals(timeStamp, actual.getTimestamp());
}
 

开发者ID:dmfs,
项目名称:opentasks,
代码行数:15,
代码来源:TaskDateTimeTest.java

示例37: test_whenIsAllDayIsFalse_shouldReturnDateTimeWithTimeZoneShifted

点赞 2

import org.dmfs.optional.Present; //导入依赖的package包/类
@Test
public void test_whenIsAllDayIsFalse_shouldReturnDateTimeWithTimeZoneShifted()
{
    long timeStamp = System.currentTimeMillis();

    RowDataSnapshot<Tasks> mockData = failingMock(RowDataSnapshot.class);
    doReturn(new Present<>(timeStamp)).when(mockData).data(eq(Tasks.DTSTART), any());
    doReturn(new Present<>(false)).when(mockData).data(eq(Tasks.IS_ALLDAY), any());
    doReturn(new Present<>(TimeZone.getTimeZone("Europe/Berlin"))).when(mockData).data(eq(Tasks.TZ), any());

    DateTime actual = new TaskDateTime(Tasks.DTSTART, mockData).value();
    assertFalse(actual.isAllDay());
    assertEquals(timeStamp, actual.getTimestamp());
    assertEquals("Europe/Berlin", actual.getTimeZone().getID());
}
 

开发者ID:dmfs,
项目名称:opentasks,
代码行数:16,
代码来源:TaskDateTimeTest.java

示例38: test_whenDueIsPresent_shouldUseThat

点赞 2

import org.dmfs.optional.Present; //导入依赖的package包/类
@Test
public void test_whenDueIsPresent_shouldUseThat()
{
    long timestamp = System.currentTimeMillis();

    RowDataSnapshot<Tasks> mockData = failingMock(RowDataSnapshot.class);
    doReturn(new Present<>(timestamp)).when(mockData).data(eq(Tasks.DUE), any());
    doReturn(absent()).when(mockData).data(eq(Tasks.DTSTART), any());
    doReturn(absent()).when(mockData).data(eq(Tasks.DURATION), any());
    doReturn(new Present<>(false)).when(mockData).data(eq(Tasks.IS_ALLDAY), any());
    doReturn(new Present<>(TimeZone.getTimeZone("UTC"))).when(mockData).data(eq(Tasks.TZ), any());

    DateTime actual = new EffectiveDueDate(mockData).value();
    assertEquals(timestamp, actual.getTimestamp());
}
 

开发者ID:dmfs,
项目名称:opentasks,
代码行数:16,
代码来源:EffectiveDueDateTest.java

示例39: test_whenDueIsAbsent_startIsAbsent_durationIsAbsent_shouldBeAbsent

点赞 2

import org.dmfs.optional.Present; //导入依赖的package包/类
@Test
public void test_whenDueIsAbsent_startIsAbsent_durationIsAbsent_shouldBeAbsent()
{
    RowDataSnapshot<Tasks> mockData = failingMock(RowDataSnapshot.class);
    doReturn(absent()).when(mockData).data(eq(Tasks.DUE), any());
    doReturn(absent()).when(mockData).data(eq(Tasks.DTSTART), any());
    doReturn(absent()).when(mockData).data(eq(Tasks.DURATION), any());
    doReturn(new Present<>(false)).when(mockData).data(eq(Tasks.IS_ALLDAY), any());
    doReturn(new Present<>(TimeZone.getTimeZone("UTC"))).when(mockData).data(eq(Tasks.TZ), any());

    assertThat(new EffectiveDueDate(mockData), AbsentMatcher.<DateTime>isAbsent());
}
 

开发者ID:dmfs,
项目名称:opentasks,
代码行数:13,
代码来源:EffectiveDueDateTest.java

示例40: test_whenDueIsAbsent_startIsPresent_durationIsAbsent_shouldBeAbsent

点赞 2

import org.dmfs.optional.Present; //导入依赖的package包/类
@Test
public void test_whenDueIsAbsent_startIsPresent_durationIsAbsent_shouldBeAbsent()
{
    RowDataSnapshot<Tasks> mockData = failingMock(RowDataSnapshot.class);
    doReturn(absent()).when(mockData).data(eq(Tasks.DUE), any());
    doReturn(new Present<>(234234)).when(mockData).data(eq(Tasks.DTSTART), any());
    doReturn(absent()).when(mockData).data(eq(Tasks.DURATION), any());
    doReturn(new Present<>(false)).when(mockData).data(eq(Tasks.IS_ALLDAY), any());
    doReturn(new Present<>(TimeZone.getTimeZone("UTC"))).when(mockData).data(eq(Tasks.TZ), any());

    assertThat(new EffectiveDueDate(mockData), AbsentMatcher.<DateTime>isAbsent());
}
 

开发者ID:dmfs,
项目名称:opentasks,
代码行数:13,
代码来源:EffectiveDueDateTest.java


版权声明:本文转自网络文章,转载此文章仅为分享知识,如有侵权,请联系管理员进行删除。
喜欢 (0)