public SparseArrayAssert<E> hasKey(int key) { isNotNull(); assertThat(actual.indexOfKey(key)) // .overridingErrorMessage("Expected key <%s> to be present but was not.", key) // .isGreaterThanOrEqualTo(0); return this; }
public LongSparseArrayAssert hasKey(int key) { isNotNull(); assertThat(actual.indexOfKey(key)) // .overridingErrorMessage("Expected key <%s> to be present but was not.", key) // .isGreaterThanOrEqualTo(0); return this; }
public SparseIntArrayAssert hasKey(int key) { isNotNull(); assertThat(actual.indexOfKey(key)) // .overridingErrorMessage("Expected key <%s> to be present but was not.", key) // .isGreaterThanOrEqualTo(0); return this; }
public SparseBooleanArrayAssert hasKey(int key) { isNotNull(); assertThat(actual.indexOfKey(key)) // .overridingErrorMessage("Expected key <%s> to be present but was not.") // .isGreaterThanOrEqualTo(0); return this; }
public SparseLongArrayAssert hasKey(int key) { isNotNull(); assertThat(actual.indexOfKey(key)) // .overridingErrorMessage("Expected key <%s> to be present but was not.", key) // .isGreaterThanOrEqualTo(0); return this; }
public SparseArrayCompatAssert<E> hasKey(int key) { isNotNull(); assertThat(actual.indexOfKey(key)) // .overridingErrorMessage("Expected key <%s> to be present but was not present.", key) // .isGreaterThanOrEqualTo(0); return this; }
@Test public void parseArguments() { System.setProperty("CommandLineParserTest.unused", "unused"); System.setProperty("sonar.CommandLineParserTest.used", "used"); Properties p = CommandLineParser.parseArguments(new String[] {"-Dsonar.foo=bar"}); // test environment can already declare some system properties prefixed by "sonar." // so we can't test the exact number "2" assertThat(p.size()).isGreaterThanOrEqualTo(2); assertThat(p.getProperty("sonar.foo")).isEqualTo("bar"); assertThat(p.getProperty("sonar.CommandLineParserTest.used")).isEqualTo("used"); }
@Test public void bufferPositionAndLimitForReadAreCorrectAfterExpansion() throws Exception { ByteBuffer buffer = ByteBuffer.allocate(33842); buffer.position(7); buffer.limit(16384); ByteBuffer newBuffer = Buffers.expandReadBufferIfNeeded(Buffers.BufferType.UNTRACKED, buffer, 40899, mock(DMStats.class)); assertThat(newBuffer.capacity()).isGreaterThanOrEqualTo(40899); // buffer should be ready to read the same amount of data assertThat(newBuffer.position()).isEqualTo(0); assertThat(newBuffer.limit()).isEqualTo(16384 - 7); }
@Test public void bufferPositionAndLimitForWriteAreCorrectAfterExpansion() throws Exception { ByteBuffer buffer = ByteBuffer.allocate(33842); buffer.position(16384); buffer.limit(buffer.capacity()); ByteBuffer newBuffer = Buffers.expandWriteBufferIfNeeded(Buffers.BufferType.UNTRACKED, buffer, 40899, mock(DMStats.class)); assertThat(newBuffer.capacity()).isGreaterThanOrEqualTo(40899); // buffer should have the same amount of data as the old one assertThat(newBuffer.position()).isEqualTo(16384); assertThat(newBuffer.limit()).isEqualTo(newBuffer.capacity()); } }
@Test public void encodeDataAsAddressShouldReturnZeroIfValueIsGreaterThanSevenBytes() { Long value = Long.MAX_VALUE; byte[] valueInBytes = ByteBuffer.allocate(Long.SIZE / Byte.SIZE).putLong(value).array(); boolean isSerialized = false; boolean isCompressed = false; assertThat(valueInBytes.length) .isGreaterThanOrEqualTo(OffHeapRegionEntryHelper.MAX_LENGTH_FOR_DATA_AS_ADDRESS); long encodedAddress = OffHeapRegionEntryHelper.encodeDataAsAddress(valueInBytes, isSerialized, isCompressed); assertThat(encodedAddress).isEqualTo(VALUE_IS_NOT_ENCODABLE); }
@Test public void ensureUnwrappedCapacity() { ByteBuffer wrappedBuffer = ByteBuffer.allocate(netBufferSize); int requestedCapacity = nioSslEngine.getUnwrappedBuffer(wrappedBuffer).capacity() * 2; ByteBuffer unwrappedBuffer = nioSslEngine.ensureUnwrappedCapacity(requestedCapacity); assertThat(unwrappedBuffer.capacity()).isGreaterThanOrEqualTo(requestedCapacity); }
@Test public void ensureWrappedCapacity() { ByteBuffer wrappedBuffer = ByteBuffer.allocate(100); wrappedBuffer.put(new byte[] {0, 1, 2, 3, 4, 5, 6, 7, 8, 9}); nioEngine.lastReadPosition = 10; int requestedCapacity = 210; ByteBuffer result = nioEngine.ensureWrappedCapacity(requestedCapacity, wrappedBuffer, Buffers.BufferType.UNTRACKED, mockStats); assertThat(result.capacity()).isGreaterThanOrEqualTo(requestedCapacity); assertThat(result).isNotSameAs(wrappedBuffer); // make sure that data was transferred to the new buffer for (int i = 0; i < 10; i++) { assertThat(result.get(i)).isEqualTo(wrappedBuffer.get(i)); } }
@Test public void load_version_from_file_in_classpath() { Version version = ApiVersion.load(System2.INSTANCE); assertThat(version).isNotNull(); assertThat(version.major()).isGreaterThanOrEqualTo(5); }
@Test public void silently_catch_error_when_url_is_incorrect() { Webhook webhook = new Webhook(WEBHOOK_UUID, PROJECT_UUID, CE_TASK_UUID, RandomStringUtils.randomAlphanumeric(40),"my-webhook", "this_is_not_an_url"); WebhookDelivery delivery = newSender().call(webhook, PAYLOAD); assertThat(delivery.getHttpStatus()).isEmpty(); assertThat(delivery.getDurationInMs().get()).isGreaterThanOrEqualTo(0); assertThat(delivery.getError().get()).isInstanceOf(IllegalArgumentException.class); assertThat(delivery.getErrorMessage().get()).isEqualTo("Webhook URL is not valid: this_is_not_an_url"); assertThat(delivery.getAt()).isEqualTo(NOW); assertThat(delivery.getWebhook()).isSameAs(webhook); assertThat(delivery.getPayload()).isSameAs(PAYLOAD); }
@Test public void findAvailablePidShouldReturnGreaterThanOrEqualToLowerBound() throws Exception { availablePid = new AvailablePid(new AvailablePid.Bounds(1, 10)); Stopwatch stopwatch = Stopwatch.createStarted(); do { assertThat(availablePid.findAvailablePid()).isGreaterThanOrEqualTo(1); } while (stopwatch.elapsed(SECONDS) < 2); }
@Test public void testInsertMixedContentWithSingleViewCreator() { List<Integer> viewItems = Arrays.asList(3, 6, 7, 11); prepareMixedLoadedBinder( 30, new HashSet<>(viewItems), new ViewCreatorProvider() { @Override public ViewCreator get() { return VIEW_CREATOR_1; } }); assertThat(mRecyclerBinder.mRenderInfoViewCreatorController.mViewTypeToViewCreator.size()) .isEqualTo(1); assertThat(mRecyclerBinder.mRenderInfoViewCreatorController.mViewCreatorToViewType.size()) .isEqualTo(1); ViewCreator obtainedViewCreator = mRecyclerBinder .mRenderInfoViewCreatorController .mViewCreatorToViewType .keySet() .iterator() .next(); assertThat(obtainedViewCreator).isEqualTo(VIEW_CREATOR_1); assertThat( mRecyclerBinder.mRenderInfoViewCreatorController.mViewTypeToViewCreator.indexOfValue( obtainedViewCreator)) .isGreaterThanOrEqualTo(0); }
@Test public void silently_catch_error_when_external_server_does_not_answer() throws Exception { Webhook webhook = new Webhook(WEBHOOK_UUID, PROJECT_UUID, CE_TASK_UUID, RandomStringUtils.randomAlphanumeric(40),"my-webhook", server.url("/ping").toString()); server.shutdown(); WebhookDelivery delivery = newSender().call(webhook, PAYLOAD); assertThat(delivery.getHttpStatus()).isEmpty(); assertThat(delivery.getDurationInMs().get()).isGreaterThanOrEqualTo(0); // message can be "Connection refused" or "connect timed out" assertThat(delivery.getErrorMessage().get()).matches("(.*Connection refused.*)|(.*connect timed out.*)"); assertThat(delivery.getAt()).isEqualTo(NOW); assertThat(delivery.getWebhook()).isSameAs(webhook); assertThat(delivery.getPayload()).isSameAs(PAYLOAD); }
@Test public void send_posts_payload_to_http_server() throws Exception { Webhook webhook = new Webhook(WEBHOOK_UUID, PROJECT_UUID, CE_TASK_UUID, RandomStringUtils.randomAlphanumeric(40),"my-webhook", server.url("/ping").toString()); server.enqueue(new MockResponse().setBody("pong").setResponseCode(201)); WebhookDelivery delivery = newSender().call(webhook, PAYLOAD); assertThat(delivery.getHttpStatus()).hasValue(201); assertThat(delivery.getWebhook().getUuid()).isEqualTo(WEBHOOK_UUID); assertThat(delivery.getDurationInMs().get()).isGreaterThanOrEqualTo(0); assertThat(delivery.getError()).isEmpty(); assertThat(delivery.getAt()).isEqualTo(NOW); assertThat(delivery.getWebhook()).isSameAs(webhook); assertThat(delivery.getPayload()).isSameAs(PAYLOAD); RecordedRequest recordedRequest = server.takeRequest(); assertThat(recordedRequest.getMethod()).isEqualTo("POST"); assertThat(recordedRequest.getPath()).isEqualTo("/ping"); assertThat(recordedRequest.getBody().readUtf8()).isEqualTo(PAYLOAD.getJson()); assertThat(recordedRequest.getHeader("User-Agent")).isEqualTo("SonarQube/6.2"); assertThat(recordedRequest.getHeader("Content-Type")).isEqualTo("application/json; charset=utf-8"); assertThat(recordedRequest.getHeader("X-SonarQube-Project")).isEqualTo(PAYLOAD.getProjectKey()); }
/** * SONAR-8799 */ @Test public void redirects_should_be_followed_with_POST_method() throws Exception { Webhook webhook = new Webhook(WEBHOOK_UUID, PROJECT_UUID, CE_TASK_UUID, RandomStringUtils.randomAlphanumeric(40),"my-webhook", server.url("/redirect").toString()); // /redirect redirects to /target server.enqueue(new MockResponse().setResponseCode(307).setHeader("Location", server.url("target"))); server.enqueue(new MockResponse().setResponseCode(200)); WebhookDelivery delivery = newSender().call(webhook, PAYLOAD); assertThat(delivery.getHttpStatus().get()).isEqualTo(200); assertThat(delivery.getDurationInMs().get()).isGreaterThanOrEqualTo(0); assertThat(delivery.getError()).isEmpty(); assertThat(delivery.getAt()).isEqualTo(NOW); assertThat(delivery.getWebhook()).isSameAs(webhook); assertThat(delivery.getPayload()).isSameAs(PAYLOAD); takeAndVerifyPostRequest("/redirect"); takeAndVerifyPostRequest("/target"); }
@Test public void executes_deletes_data_in_all_children_tables_of_component_for_usurper_root_components() throws SQLException { long usurperId = 12L; String usurperUuid = "usurper_uuid"; insertComponent(Scopes.PROJECT, Qualifiers.MODULE, usurperId, usurperUuid, usurperUuid); Long snapshotId = insertSnapshot(usurperUuid, usurperUuid); insertDuplicationsIndex(snapshotId); insertProjectMeasures(usurperUuid, dontCareLong()); insertCeActivity(usurperUuid, dontCareLong()); insertEvent(usurperUuid, dontCareLong()); insertSnapshot(usurperUuid, dontCare()); insertSnapshot(dontCare(), usurperUuid); insertProjectLinks(usurperUuid); insertIssue(usurperUuid, null); insertIssue(null, usurperUuid); insertIssue(usurperUuid, usurperUuid); insertFileSource(null, usurperUuid); insertFileSource(usurperUuid, null); insertFileSource(usurperUuid, usurperUuid); insertGroupRole(usurperId); insertUserRole(usurperId); insertProperties(usurperId); insertWidget(usurperId); TABLES.stream() .forEach(s -> assertThat(db.countRowsOfTable(s)).describedAs("table " + s).isGreaterThanOrEqualTo(1)); underTest.execute(); TABLES.stream() .forEach(s -> assertThat(db.countRowsOfTable(s)).describedAs("table " + s).isEqualTo(0)); }