@Test public void addIfStartupLeader_always_returns_the_same_instance() { underTest.add(Mockito.mock(WebServer.class)); PlatformLevel.AddIfStartupLeader addIfStartupLeader = underTest.addIfStartupLeader(); IntStream.range(0, 1 + new Random().nextInt(4)).forEach(i -> assertThat(underTest.addIfStartupLeader()).isSameAs(addIfStartupLeader)); }
@Test public void should_use_loader() { when(mockLoader.load("key")).thenReturn(mockBranches); ProjectBranches branches = provider.provide(mockLoader, () -> "key"); assertThat(branches).isSameAs(mockBranches); }
@Test public void getMetric() { Collection<MetricDto> metrics = asList(METRIC_1, METRIC_2); MeasureMatrix underTest = new MeasureMatrix(asList(PROJECT, FILE), metrics, new ArrayList<>()); assertThat(underTest.getMetric(METRIC_2.getId())).isSameAs(METRIC_2); }
@Test public void shouldDelegate() { LoginPasswordAuthenticator authenticator = mock(LoginPasswordAuthenticator.class); CompatibilityRealm realm = new CompatibilityRealm(authenticator); realm.init(); verify(authenticator).init(); assertThat(realm.getLoginPasswordAuthenticator()).isSameAs(authenticator); assertThat(realm.getName()).isEqualTo("CompatibilityRealm[" + authenticator.getClass().getName() + "]"); }
@Test public void should_cache_config() { BranchConfiguration configuration = provider.provide(null, globalConfiguration, reactor, globalServerSettings, projectServerSettings, branches, pullRequests); assertThat(provider.provide(null, globalConfiguration, reactor, globalServerSettings, projectServerSettings, branches, pullRequests)).isSameAs(configuration); }
@Test public void createComponentKey_delegates_to_delegate_if_characteristics_is_not_empty() { String projectKey = randomAlphanumeric(12); Map<String, String> nonEmptyMap = newRandomNonEmptyMap(); ComponentKey expected = mock(ComponentKey.class); when(branchSupportDelegate.createComponentKey(projectKey, nonEmptyMap)).thenReturn(expected); ComponentKey componentKey = underTestWithBranch.createComponentKey(projectKey, null, nonEmptyMap); assertThat(componentKey).isSameAs(expected); }
@Test public void shouldRegisterItself() { ComponentContainer container = new ComponentContainer(); assertThat(container.getComponentByType(ComponentContainer.class)).isSameAs(container); }
@Test public void cache_pull_requests() { ProjectPullRequests pullRequests = provider.provide(null, () -> "project"); assertThat(provider.provide(null, () -> "project")).isSameAs(pullRequests); }
@Test public void verify_setRoots_getRoot() { underTest.setRoots(SOME_REPORT_COMPONENT_TREE, DUMB_PROJECT); assertThat(underTest.getRoot()).isSameAs(SOME_REPORT_COMPONENT_TREE); }
@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); }
private void readLineAndAssertLatestChanges(ScmLineReader lineScm, int line, Changeset expectedChangeset, Changeset expectedChangesetWithRevision) { DbFileSources.Line.Builder lineBuilder = DbFileSources.Data.newBuilder().addLinesBuilder().setLine(line); assertThat(lineScm.read(lineBuilder)).isEmpty(); assertThat(lineScm.getLatestChange()).isSameAs(expectedChangeset); assertThat(lineScm.getLatestChangeWithRevision()).isSameAs(expectedChangesetWithRevision); }
@Test public void test_default_result() { Result<Object> result = Result.of(); assertThat(result.ok()).isTrue(); assertThat(result.errors()).isEmpty(); assertThat(result.httpStatus()).isEqualTo(200); assertThat(result.get()).isNull(); Object obj = new Object(); result.set(obj); assertThat(result.get()).isSameAs(obj); }
@Test public void verify_getters() { String error = "error threshold"; Condition condition = new Condition(SOME_METRIC, SOME_OPERATOR, error); assertThat(condition.getMetric()).isSameAs(SOME_METRIC); assertThat(condition.getOperator()).isSameAs(Condition.Operator.LESS_THAN); assertThat(condition.getErrorThreshold()).isEqualTo(error); }
@Test public void getForTask_returns_TaskProcessor_even_if_it_is_not_specific() { CeTaskProcessor taskProcessor = createCeTaskProcessor(SOME_CE_TASK_TYPE + "_1", SOME_CE_TASK_TYPE, SOME_CE_TASK_TYPE + "_3"); CeTaskProcessorRepositoryImpl underTest = new CeTaskProcessorRepositoryImpl(new CeTaskProcessor[] {taskProcessor}); assertThat(underTest.getForCeTask(createCeTask(SOME_CE_TASK_TYPE, SOME_COMPONENT_KEY)).get()).isSameAs(taskProcessor); }
@Test public void update_updates_the_stored_value() { Measure newMeasure = Measure.updatedMeasureBuilder(SOME_MEASURE).create(); underTest.add(FILE_COMPONENT, metric1, SOME_MEASURE); underTest.update(FILE_COMPONENT, metric1, newMeasure); assertThat(underTest.getRawMeasure(FILE_COMPONENT, metric1).get()).isSameAs(newMeasure); }
@Test public void create_http_client() { HttpConnector connector = HttpConnector.newBuilder().url("http://localhost:9000").build(); WsClient client = WsClientFactories.getDefault().newClient(connector); assertThat(client).isInstanceOf(DefaultWsClient.class); assertThat(client.wsConnector()).isSameAs(connector); }
/** * SONAR-2928 */ @Test public void no_lines_and_different_messages_match() { FakeInput baseInput = new FakeInput("H1", "H2", "H3"); Issue base = baseInput.createIssue(RULE_SYSTEM_PRINT, "msg1"); FakeInput rawInput = new FakeInput("H10", "H11", "H12"); Issue raw = rawInput.createIssue(RULE_SYSTEM_PRINT, "msg2"); Tracking<Issue, Issue> tracking = tracker.trackNonClosed(rawInput, baseInput); assertThat(tracking.baseFor(raw)).isSameAs(base); }
@Test public void similar_issues_except_line_match() { FakeInput baseInput = new FakeInput("H1", "H2"); Issue base = baseInput.createIssueOnLine(1, RULE_SYSTEM_PRINT, "msg"); FakeInput rawInput = new FakeInput("H2", "H1"); Issue raw = rawInput.createIssueOnLine(2, RULE_SYSTEM_PRINT, "msg"); Tracking<Issue, Issue> tracking = tracker.trackNonClosed(rawInput, baseInput); assertThat(tracking.baseFor(raw)).isSameAs(base); }
@Test public void checkComponentUuidPermission_succeeds_if_user_has_permission_for_specified_uuid_in_db() { UserDto root = db.users().insertUser(); root = db.users().makeRoot(root); OrganizationDto organization = db.organizations().insert(); ComponentDto project = db.components().insertPrivateProject(organization); ComponentDto file = db.components().insertComponent(newFileDto(project)); UserSession underTest = newUserSession(root); assertThat(underTest.checkComponentUuidPermission(UserRole.USER, file.uuid())).isSameAs(underTest); assertThat(underTest.checkComponentUuidPermission("whatever", "who cares?")).isSameAs(underTest); }
@Test public void loadQualityGate_returns_hardcoded_gate_for_pull_requests() { OrganizationDto organization = db.organizations().insert(); ComponentDto project = db.components().insertPublicProject(organization); BranchDto pullRequest = newBranchDto(project).setBranchType(BranchType.PULL_REQUEST); db.components().insertProjectBranch(project, pullRequest); QualityGate result = underTest.loadQualityGate(db.getSession(), organization, project, pullRequest); assertThat(result).isSameAs(ShortLivingBranchQualityGate.GATE); }