How to use Long.shouldBeNegative method of io.kotest.matchers.longs.long class

Best Kotest code snippet using io.kotest.matchers.longs.long.Long.shouldBeNegative

CacheEntryMetadataTest.kt

Source:CacheEntryMetadataTest.kt Github

copy

Full Screen

1/*2 * Copyright (C) 2022 Edgar Asatryan3 *4 * Licensed under the Apache License, Version 2.0 (the "License");5 * you may not use this file except in compliance with the License.6 * You may obtain a copy of the License at7 *8 * http://www.apache.org/licenses/LICENSE-2.09 *10 * Unless required by applicable law or agreed to in writing, software11 * distributed under the License is distributed on an "AS IS" BASIS,12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.13 * See the License for the specific language governing permissions and14 * limitations under the License.15 */16package io.github.nstdio.http.ext17import io.kotest.matchers.booleans.shouldBeFalse18import io.kotest.matchers.booleans.shouldBeTrue19import io.kotest.matchers.longs.shouldBeNegative20import org.junit.jupiter.api.Assertions.assertFalse21import org.junit.jupiter.api.Disabled22import org.junit.jupiter.api.Nested23import org.junit.jupiter.api.Test24import java.net.URI25import java.net.http.HttpRequest26import java.time.Clock27import java.time.Duration28import java.time.Instant29import java.time.ZoneId30import java.time.ZoneOffset31import java.time.temporal.ChronoUnit32import java.util.concurrent.Executors33import java.util.concurrent.TimeUnit34internal class CacheEntryMetadataTest {35 @Test36 fun varyHeaders() {37 val headers = mutableMapOf(38 "Vary" to "Accept, Accept-Encoding, User-Agent"39 )40 val r = HttpRequest.newBuilder(URI.create("https://example.com"))41 .headers(42 "Accept", "text/plain",43 "Accept-Encoding", "gzip",44 "User-Agent", "Java/11",45 "Accept-Language", "en-EN"46 )47 .build()48 val m = CacheEntryMetadata(0, 0, Helpers.responseInfo(headers), r, Clock.systemDefaultZone())49 //when50 val actual = m.varyHeaders()51 //then52 Assertions.assertThat(actual)53 .hasHeaderWithValues("Accept", "text/plain")54 .hasHeaderWithValues("Accept-Encoding", "gzip")55 .hasHeaderWithValues("User-Agent", "Java/11")56 }57 @Test58 fun shouldGenerateHeuristicExpirationWarning() {59 //given60 val tickDuration = Duration.ofSeconds(1)61 val baseInstant = Instant.ofEpochSecond(0)62 val clock = FixedRateTickClock(baseInstant, ZoneOffset.UTC, tickDuration)63 // Creating Last-Modified just about to exceed 24 hour limit64 val lastModified = baseInstant.minus(241, ChronoUnit.HOURS)65 val expectedExpirationTime = baseInstant.plus(2, ChronoUnit.DAYS)66 val info = Helpers.responseInfo(67 mutableMapOf(68 "Last-Modified" to Headers.toRFC1123(lastModified),69 "Date" to Headers.toRFC1123(Instant.ofEpochSecond(0))70 )71 )72 val request1 = HttpRequest.newBuilder().uri(URI.create("https://www.example.com")).build()73 val request2 = HttpRequest.newBuilder().uri(URI.create("https://www.example.com/path?query")).build()74 val metadata1 = CacheEntryMetadata(0, 1000, info, request1, clock)75 val metadata2 = CacheEntryMetadata(0, 1000, info, request2, clock)76 tickUntil(clock, expectedExpirationTime)77 val executor = Executors.newFixedThreadPool(12)78 //when79 for (i in 0 until (1 shl 16)) {80 executor.submit { metadata1.updateWarnings() }81 }82 executor.shutdown()83 executor.awaitTermination(3, TimeUnit.SECONDS)84 //then85 metadata2.maxAge().shouldBeNegative()86 metadata2.isApplicable.shouldBeFalse()87 Assertions.assertThat(metadata1.response().headers())88 .hasHeaderWithOnlyValue("Warning", "113 - \"Heuristic Expiration\"")89 }90 private fun tickUntil(clock: FixedRateTickClock, expectedExpirationTime: Instant) {91 @Suppress("ControlFlowWithEmptyBody")92 while (clock.instant().isBefore(expectedExpirationTime)) {93 }94 }95 /**96 * https://httpwg.org/specs/rfc7234.html#rfc.section.5.2.2.197 */98 @Test99 fun shouldRespectMustRevalidateResponseDirective() {100 //given101 val baseClock = Clock.systemUTC()102 val dateHeader = baseClock.instant()103 val clock = FixedRateTickClock.of(baseClock, Duration.ofSeconds(1))104 val info = Helpers.responseInfo(105 mutableMapOf(106 "Cache-Control" to "max-age=1,must-revalidate",107 "Date" to Headers.toRFC1123(dateHeader)108 )109 )110 val request = HttpRequest.newBuilder().uri(URI.create("https://www.example.com")).build()111 val requestTimeMs = dateHeader.minusMillis(50).toEpochMilli()112 val responseTimeMs = dateHeader.plusMillis(50).toEpochMilli()113 val metadata = CacheEntryMetadata(requestTimeMs, responseTimeMs, info, request, clock)114 //when + then115 assertFalse(metadata.isFresh(CacheControl.parse("max-stale=1")))116 }117 @Test118 @Disabled("https://httpwg.org/specs/rfc7234.html#rfc.section.4.2.4")119 fun shouldAddStaleResponseWarning() {120 }121 @Nested122 internal inner class FreshnessTest {123 private val uri = URI.create("https://www.example.com")124 @Test125 fun shouldBeFresh() {126 //given127 val requestTimeMs: Long = 100128 val responseTimeMs: Long = 350129 val serverDate = responseTimeMs - 50130 val clock = Clock.fixed(Instant.ofEpochMilli(responseTimeMs + 5), ZoneId.systemDefault())131 val info = Helpers.responseInfo(132 mutableMapOf(133 "Cache-Control" to "max-age=1",134 "Date" to Headers.toRFC1123(Instant.ofEpochMilli(serverDate))135 )136 )137 val request = HttpRequest.newBuilder().uri(uri).build()138 val e = CacheEntryMetadata(requestTimeMs, responseTimeMs, info, request, clock)139 //when + then140 e.isFresh(CacheControl.builder().build()).shouldBeTrue()141 }142 }143}...

Full Screen

Full Screen

LongMatchersTest.kt

Source:LongMatchersTest.kt Github

copy

Full Screen

1package com.sksamuel.kotest.matchers.numerics2import io.kotest.assertions.throwables.shouldThrow3import io.kotest.matchers.comparables.beGreaterThan4import io.kotest.matchers.comparables.beGreaterThanOrEqualTo5import io.kotest.matchers.comparables.beLessThan6import io.kotest.matchers.comparables.beLessThanOrEqualTo7import io.kotest.matchers.longs.between8import io.kotest.matchers.longs.shouldBeNegative9import io.kotest.matchers.longs.shouldBePositive10import io.kotest.matchers.longs.shouldBeZero11import io.kotest.matchers.longs.shouldNotBeZero12import io.kotest.core.spec.style.StringSpec13import io.kotest.matchers.should14import io.kotest.matchers.shouldBe15import io.kotest.data.forAll16import io.kotest.data.forNone17import io.kotest.data.headers18import io.kotest.data.row19import io.kotest.data.table20class LongMatchersTest : StringSpec() {21 init {22 "be positive" {23 1L.shouldBePositive()24 shouldThrow<AssertionError> {25 (-1L).shouldBePositive()26 }.message shouldBe "-1 should be > 0"27 shouldThrow<AssertionError> {28 (0L).shouldBePositive()29 }.message shouldBe "0 should be > 0"30 }31 "be negative" {32 (-1L).shouldBeNegative()33 shouldThrow<AssertionError> {34 1L.shouldBeNegative()35 }.message shouldBe "1 should be < 0"36 shouldThrow<AssertionError> {37 0L.shouldBeNegative()38 }.message shouldBe "0 should be < 0"39 }40 "Ge should be valid" {41 1L should beGreaterThan(0L)42 }43 "beGreaterThan" {44 1L should beGreaterThan(0L)45 shouldThrow<AssertionError> {46 2L should beGreaterThan(3L)47 }48 }49 "beLessThan" {50 1L should beLessThan(2L)51 shouldThrow<AssertionError> {52 2L should beLessThan(1L)53 }54 }55 "beLessThanOrEqualTo" {56 1L should beLessThanOrEqualTo(2L)57 shouldThrow<AssertionError> {58 2L should beLessThanOrEqualTo(1L)59 }60 }61 "greaterThan" {62 1L should beGreaterThanOrEqualTo(0L)63 shouldThrow<AssertionError> {64 2L should beGreaterThanOrEqualTo(3L)65 }66 }67 "between should test for valid interval" {68 val table = table(69 headers("a", "b"),70 row(0L, 2L),71 row(1L, 2L),72 row(0L, 1L),73 row(1L, 1L)74 )75 forAll(table) { a, b ->76 1 shouldBe between(a, b)77 }78 }79 "between should test for invalid interval" {80 val table = table(81 headers("a", "b"),82 row(0L, 2L),83 row(2L, 2L),84 row(4L, 5L),85 row(4L, 6L)86 )87 forNone(table) { a, b ->88 3 shouldBe between(a, b)89 }90 }91 "shouldBeZero" {92 (0L).shouldBeZero()93 (1L).shouldNotBeZero()94 Long.MIN_VALUE.shouldNotBeZero()95 Long.MAX_VALUE.shouldNotBeZero()96 }97 }98}...

Full Screen

Full Screen

long.kt

Source:long.kt Github

copy

Full Screen

1package io.kotest.matchers.longs2import io.kotest.matchers.Matcher3import io.kotest.matchers.MatcherResult4import io.kotest.matchers.comparables.gt5import io.kotest.matchers.comparables.gte6import io.kotest.matchers.comparables.lt7import io.kotest.matchers.comparables.lte8import io.kotest.matchers.should9import io.kotest.matchers.shouldBe10import io.kotest.matchers.shouldNot11import io.kotest.matchers.shouldNotBe12fun Long.shouldBePositive() = this shouldBe positiveL()13fun positiveL() = object : Matcher<Long> {14 override fun test(value: Long) = MatcherResult(value > 0, "$value should be > 0", "$value should not be > 0")15}16fun Long.shouldBeNegative() = this shouldBe negativeL()17fun negativeL() = object : Matcher<Long> {18 override fun test(value: Long) = MatcherResult(value < 0, "$value should be < 0", "$value should not be < 0")19}20fun Long.shouldBeEven() = this should lbeEven()21fun Long.shouldNotBeEven() = this shouldNot lbeEven()22fun lbeEven() = object : Matcher<Long> {23 override fun test(value: Long): MatcherResult =24 MatcherResult(value % 2 == 0L, "$value should be even", "$value should be odd")25}26fun Long.shouldBeOdd() = this should lbeOdd()27fun Long.shouldNotBeOdd() = this shouldNot lbeOdd()28fun lbeOdd() = object : Matcher<Long> {29 override fun test(value: Long): MatcherResult =30 MatcherResult(value % 2 == 1L, "$value should be odd", "$value should be even")31}32infix fun Long.shouldBeLessThan(x: Long) = this shouldBe lt(x)33infix fun Long.shouldNotBeLessThan(x: Long) = this shouldNotBe lt(x)34infix fun Long.shouldBeLessThanOrEqual(x: Long) = this shouldBe lte(x)35infix fun Long.shouldNotBeLessThanOrEqual(x: Long) = this shouldNotBe lte(x)36infix fun Long.shouldBeGreaterThan(x: Long) = this shouldBe gt(x)37infix fun Long.shouldNotBeGreaterThan(x: Long) = this shouldNotBe gt(x)38infix fun Long.shouldBeGreaterThanOrEqual(x: Long) = this shouldBe gte(x)39infix fun Long.shouldNotBeGreaterThanOrEqual(x: Long) = this shouldNotBe gte(x)40infix fun Long.shouldBeExactly(x: Long) = this shouldBe exactly(x)41infix fun Long.shouldNotBeExactly(x: Long) = this shouldNotBe exactly(x)42fun Long.shouldBeZero() = this shouldBeExactly 0L43fun Long.shouldNotBeZero() = this shouldNotBeExactly 0L...

Full Screen

Full Screen

Long.shouldBeNegative

Using AI Code Generation

copy

Full Screen

1Long.shouldBeNegative()2Long.shouldBePositive()3Long.shouldBeZero()4Long.shouldBeOne()5Long.shouldBeBetween(1, 2)6Long.shouldBeBetweenClosed(1, 2)7Long.shouldBeBetweenClosedInclusive(1, 2)8Long.shouldBeBetweenClosedInclusive(1, 2)9Long.shouldBeBetweenClosedInclusive(1, 2)10Long.shouldBeBetweenClosedInclusive(1, 2)11Long.shouldBeBetweenClosedInclusive(1, 2)12Long.shouldBeBetweenClosedInclusive(1, 2)13Long.shouldBeBetweenClosedInclusive(1, 2)14Long.shouldBeBetweenClosedInclusive(1, 2)15Long.shouldBeBetweenClosedInclusive(1, 2)

Full Screen

Full Screen

Long.shouldBeNegative

Using AI Code Generation

copy

Full Screen

1 4L.shouldBeNegative()2 4L.shouldBePositive()3 4L.shouldBeZero()4 4L.shouldBeInRange(1L..5L)5 4L.shouldBeLessThan(5L)6 4L.shouldBeLessThanOrEqual(5L)7 4L.shouldBeGreaterThan(5L)8 4L.shouldBeGreaterThanOrEqual(5L)9 4L.shouldBeOneOf(1L, 2L, 3L, 4L, 5L)10 4L.shouldBeBetween(1L, 5L)11 4L.shouldBeBetweenClosed(1L, 5L)12 4L.shouldBeBetweenClosedInclusive(1L, 5L)13 4L.shouldBeBetweenInclusive(1L, 5L)14 4L.shouldBeBetweenExclusive(1L, 5L)

Full Screen

Full Screen

Long.shouldBeNegative

Using AI Code Generation

copy

Full Screen

1 longs.shouldBeNegative(-1L)2 longs.shouldBePositive(1L)3 longs.shouldBeZero(0L)4 longs.shouldBeInRange(0L..10L, 5L)5 longs.shouldNotBeInRange(0L..10L, 11L)6 longs.shouldBeLessThan(0L, -1L)7 longs.shouldBeLessThanOrEqual(0L, 0L)8 longs.shouldBeGreaterThan(0L, 1L)9 longs.shouldBeGreaterThanOrEqual(0L, 0L)10 longs.shouldBeBetween(0L, 10L, 5L)11 longs.shouldNotBeBetween(0L, 10L, 11L)12 longs.shouldBeBetweenClosed(0L, 10L, 5L)13 longs.shouldNotBeBetweenClosed(0L, 10L, 11L)

Full Screen

Full Screen

Long.shouldBeNegative

Using AI Code Generation

copy

Full Screen

1 1L.shouldBeNegative()2 1.shouldBePositive()3 1.shouldBeNegative()4 1.0.shouldBePositive()5 1.0.shouldBeNegative()6 1.0f.shouldBePositive()7 1.0f.shouldBeNegative()8 1.toShort().shouldBePositive()9 1.toShort().shouldBeNegative()10 1.toByte().shouldBePositive()11 1.toByte().shouldBeNegative()12 1UL.shouldBePositive()13 1UL.shouldBeNegative()14 1U.shouldBePositive()15 1U.shouldBeNegative()16 1U.toShort().shouldBePositive()17 1U.toShort().shouldBeNegative()

Full Screen

Full Screen

Long.shouldBeNegative

Using AI Code Generation

copy

Full Screen

1 fun `should be negative`() {2 (-1L).shouldBeNegative()3 }4 fun `should be positive`() {5 1L.shouldBePositive()6 }7 fun `should be zero`() {8 0L.shouldBeZero()9 }10 fun `should be in range`() {11 1L.shouldBeInRange(0L..2L)12 }13 fun `should not be in range`() {14 1L.shouldNotBeInRange(2L..3L)15 }16 fun `should be between`() {17 1L.shouldBeBetween(0L, 2L)18 }19 fun `should be between inclusive`() {20 1L.shouldBeBetweenInclusive(0L, 1L)21 }22 fun `should be between closed`() {23 1L.shouldBeBetweenClosed(0L, 2L)24 }25 fun `should be between closed inclusive`() {26 1L.shouldBeBetweenClosedInclusive(0L, 1L)27 }28 fun `should not be between`() {29 1L.shouldNotBeBetween(2L, 3L)30 }

Full Screen

Full Screen

Long.shouldBeNegative

Using AI Code Generation

copy

Full Screen

1 fun `should be negative`() {2 1L.shouldBeNegative()3 }4 fun `should be positive`() {5 1L.shouldBePositive()6 }7 fun `should be zero`() {8 0L.shouldBeZero()9 }10 fun `should be between`() {11 1L.shouldBeBetween(0L, 2L)12 }13 fun `should be between closed`() {14 1L.shouldBeBetweenClosed(0L, 2L)15 }16 fun `should be between exclusive`() {17 1L.shouldBeBetweenExclusive(0L, 2L)18 }19 fun `should be between inclusive`() {20 1L.shouldBeBetweenInclusive(0L, 2L)21 }22 fun `should be between inclusive end`() {23 1L.shouldBeBetweenInclusiveEnd(0L, 2L)24 }25 fun `should be between inclusive start`() {26 1L.shouldBeBetweenInclusiveStart(0L, 2L)27 }28 fun `should be between inclusive start end`() {29 1L.shouldBeBetweenInclusiveStartEnd(0L

Full Screen

Full Screen

Long.shouldBeNegative

Using AI Code Generation

copy

Full Screen

1 }2 fun `should be positive`(){3 }4 fun `should be zero`(){5 }6 fun `should be between`(){7 }8 fun `should be in `(){9 }10 fun `should not be in `(){11 }12 fun `should be one of`(){13 }14 fun `should be negative`(){15 }16 fun `should be positive`(){17 }18 fun `should be zero`(){19 }20 fun `should be between`(){21 }

Full Screen

Full Screen

Long.shouldBeNegative

Using AI Code Generation

copy

Full Screen

1 }2 fun `should be negative with message`(){3 }4 fun `should be negative with message and lambda`(){5 }6 fun `should not be negative`(){7 }8 fun `should not be negative with message`(){9 }10 fun `should not be negative with message and lambda`(){11 }12 fun `should be positive`(){13 }14 fun `should be positive with message`(){15 }16 fun `should be positive with message and lambda`(){17 }18 fun `should not be positive`(){19 }20 fun `should not be positive with message`(){21 }22 fun `should not be positive with message and lambda`(){23 }24 fun `should be zero`(){25 }

Full Screen

Full Screen

Long.shouldBeNegative

Using AI Code Generation

copy

Full Screen

1 }2}3 }4}5 }6}7 }8}9 }10}11 }12}13 }14}15 }16}17 }18}

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run Kotest automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful