@Test public void shouldUseSuiteNameIfPresent() throws Exception { process( "junitdata/with-timestamp.xml", "TEST-test.SampleTest.xml" ); final ArgumentCaptor<TestResult> captor = ArgumentCaptor.forClass(TestResult.class); verify(visitor, times(1)).visitTestResult(captor.capture()); assertThat(captor.getAllValues()) .flatExtracting(TestResult::getLabels) .filteredOn("name", "suite") .extracting(Label::getValue) .containsExactly("LocalSuiteIDOL"); }
@Test public void shouldUseHostnameIfPresent() throws Exception { process( "junitdata/with-timestamp.xml", "TEST-test.SampleTest.xml" ); final ArgumentCaptor<TestResult> captor = ArgumentCaptor.forClass(TestResult.class); verify(visitor, times(1)).visitTestResult(captor.capture()); assertThat(captor.getAllValues()) .flatExtracting(TestResult::getLabels) .filteredOn("name", "host") .extracting(Label::getValue) .containsExactly("cbgtalosbld02"); }
@Test public void shouldSetFramework() throws Exception { process( "xunitdata/framework-test.xml", "passed-test.xml" ); final ArgumentCaptor<TestResult> captor = ArgumentCaptor.forClass(TestResult.class); verify(visitor, times(1)).visitTestResult(captor.capture()); assertThat(captor.getAllValues()) .hasSize(1) .flatExtracting(TestResult::getLabels) .filteredOn(label -> label.getName().equals(LabelName.FRAMEWORK.value())) .extracting(Label::getValue) .containsExactly("junit"); }
@Test public void initialize_matches_Sonar_Way_default_with_case_sensitivity() { String sonarWayInOtherCase = SONAR_WAY_QP_NAME.toUpperCase(); BuiltInQProfileRepository underTest = new BuiltInQProfileRepositoryImpl( dbClient, new Languages(FOO_LANGUAGE), new DummyProfileDefinition("foo", "goo", false), new DummyProfileDefinition("foo", sonarWayInOtherCase, false)); underTest.initialize(); assertThat(underTest.get()) .filteredOn(b -> FOO_LANGUAGE.getKey().equals(b.getLanguage())) .filteredOn(BuiltInQProfile::isDefault) .extracting(BuiltInQProfile::getName) .containsExactly("goo"); }
@Test public void shouldCopyLabelsFromSuite() throws Exception { Set<TestResult> testCases = process( "allure1/sample-testsuite.json", generateTestSuiteJsonName() ).getResults(); assertThat(testCases) .hasSize(1) .flatExtracting(TestResult::getLabels) .filteredOn(label -> LabelName.STORY.value().equals(label.getName())) .hasSize(2) .extracting(Label::getValue) .containsExactlyInAnyOrder("SuccessStory", "OtherStory"); }
@Test public void initialize_does_not_create_Sonar_Way_as_default_if_other_profile_is_defined_as_default() { BuiltInQProfileRepository underTest = new BuiltInQProfileRepositoryImpl( dbClient, new Languages(FOO_LANGUAGE), new DummyProfileDefinition("foo", SONAR_WAY_QP_NAME, false), new DummyProfileDefinition("foo", "goo", true)); underTest.initialize(); assertThat(underTest.get()) .filteredOn(b -> FOO_LANGUAGE.getKey().equals(b.getLanguage())) .filteredOn(BuiltInQProfile::isDefault) .extracting(BuiltInQProfile::getName) .containsExactly("goo"); }
.filteredOn("name", "c") .flatExtracting("children") .extracting("name")
@Test public void initialize_creates_profile_Sonar_Way_as_default_if_none_other_is_defined_default_for_a_given_language() { BuiltInQProfileRepository underTest = new BuiltInQProfileRepositoryImpl( dbClient, new Languages(FOO_LANGUAGE), new DummyProfileDefinition("foo", "doh", false), new DummyProfileDefinition("foo", "boo", false), new DummyProfileDefinition("foo", SONAR_WAY_QP_NAME, false), new DummyProfileDefinition("foo", "goo", false)); underTest.initialize(); assertThat(underTest.get()) .filteredOn(b -> FOO_LANGUAGE.getKey().equals(b.getLanguage())) .filteredOn(BuiltInQProfile::isDefault) .extracting(BuiltInQProfile::getName) .containsExactly(SONAR_WAY_QP_NAME); }
@Test public void loadLatestDiffChangesForReopeningOfClosedIssues_adds_2_diff_changes_if_most_recent_status_and_resolution_are_not_the_same_diff() { ComponentDto project = dbTester.components().insertPublicProject(); ComponentDto file = dbTester.components().insertComponent(ComponentTesting.newFileDto(project)); RuleDefinitionDto rule = dbTester.rules().insert(); IssueDto issue = dbTester.issues().insert(rule, project, file); dbTester.issues().insertChange(issue, t -> t.setChangeData(randomDiffWith("status", "valStatus1")).setIssueChangeCreationDate(5)); dbTester.issues().insertChange(issue, t -> t.setChangeData(randomDiffWith("status", "valStatus2", "resolution", "valRes2")).setIssueChangeCreationDate(19)); dbTester.issues().insertChange(issue, t -> t.setChangeData(randomDiffWith("status", "valStatus3")).setIssueChangeCreationDate(20)); dbTester.issues().insertChange(issue, t -> t.setChangeData(randomDiffWith("resolution", "valRes4")).setIssueChangeCreationDate(13)); ComponentIssuesLoader underTest = new ComponentIssuesLoader(dbClient, null /* not used in method */, null /* not used in method */, newConfiguration("0"), null /* not used by method */); DefaultIssue defaultIssue = new DefaultIssue().setKey(issue.getKey()); underTest.loadLatestDiffChangesForReopeningOfClosedIssues(ImmutableList.of(defaultIssue)); assertThat(defaultIssue.changes()) .hasSize(2); assertThat(defaultIssue.changes()) .extracting(t -> t.get("status")) .filteredOn(t -> hasValue(t, "valStatus3")) .hasSize(1); assertThat(defaultIssue.changes()) .extracting(t -> t.get("resolution")) .filteredOn(t -> hasValue(t, "valRes2")) .hasSize(1); }
.filteredOn("name", "f2") .flatExtracting("children") .filteredOn("name", "s1") .flatExtracting("children") .extracting("name") .filteredOn("name", "f2") .flatExtracting("children") .filteredOn("name", "s2") .flatExtracting("children") .extracting("name") .filteredOn("name", "f2") .flatExtracting("children") .filteredOn("name", "s3") .flatExtracting("children") .extracting("name")
@Test public void loadLatestDiffChangesForReopeningOfClosedIssues_add_single_diff_change_when_most_recent_status_and_resolution_is_the_same_diff() { ComponentDto project = dbTester.components().insertPublicProject(); ComponentDto file = dbTester.components().insertComponent(ComponentTesting.newFileDto(project)); RuleDefinitionDto rule = dbTester.rules().insert(); IssueDto issue = dbTester.issues().insert(rule, project, file); dbTester.issues().insertChange(issue, t -> t.setChangeData(randomDiffWith("status", "valStatus1")).setIssueChangeCreationDate(5)); dbTester.issues().insertChange(issue, t -> t.setChangeData(randomDiffWith("status", "valStatus2")).setIssueChangeCreationDate(19)); dbTester.issues().insertChange(issue, t -> t.setChangeData(randomDiffWith("status", "valStatus3", "resolution", "valRes3")).setIssueChangeCreationDate(20)); dbTester.issues().insertChange(issue, t -> t.setChangeData(randomDiffWith("resolution", "valRes4")).setIssueChangeCreationDate(13)); ComponentIssuesLoader underTest = new ComponentIssuesLoader(dbClient, null /* not used in method */, null /* not used in method */, newConfiguration("0"), null /* not used by method */); DefaultIssue defaultIssue = new DefaultIssue().setKey(issue.getKey()); underTest.loadLatestDiffChangesForReopeningOfClosedIssues(ImmutableList.of(defaultIssue)); assertThat(defaultIssue.changes()) .hasSize(1); assertThat(defaultIssue.changes()) .extracting(t -> t.get("status")) .filteredOn(t -> hasValue(t, "valStatus3")) .hasSize(1); assertThat(defaultIssue.changes()) .extracting(t -> t.get("resolution")) .filteredOn(t -> hasValue(t, "valRes3")) .hasSize(1); }
@Test @UseDataProvider("statusOrResolutionFieldName") public void loadLatestDiffChangesForReopeningOfClosedIssues_add_diff_change_with_most_recent_status_or_resolution(String statusOrResolutionFieldName) { ComponentDto project = dbTester.components().insertPublicProject(); ComponentDto file = dbTester.components().insertComponent(ComponentTesting.newFileDto(project)); RuleDefinitionDto rule = dbTester.rules().insert(); IssueDto issue = dbTester.issues().insert(rule, project, file); dbTester.issues().insertChange(issue, t -> t.setChangeData(randomDiffWith(statusOrResolutionFieldName, "val1")).setIssueChangeCreationDate(5)); dbTester.issues().insertChange(issue, t -> t.setChangeData(randomDiffWith(statusOrResolutionFieldName, "val2")).setIssueChangeCreationDate(20)); dbTester.issues().insertChange(issue, t -> t.setChangeData(randomDiffWith(statusOrResolutionFieldName, "val3")).setIssueChangeCreationDate(13)); ComponentIssuesLoader underTest = new ComponentIssuesLoader(dbClient, null /* not used in method */, null /* not used in method */, newConfiguration("0"), null /* not used by method */); DefaultIssue defaultIssue = new DefaultIssue().setKey(issue.getKey()); underTest.loadLatestDiffChangesForReopeningOfClosedIssues(ImmutableList.of(defaultIssue)); assertThat(defaultIssue.changes()) .hasSize(1); assertThat(defaultIssue.changes()) .extracting(t -> t.get(statusOrResolutionFieldName)) .filteredOn(t -> hasValue(t, "val2")) .hasSize(1); }
@Test public void testDependentEnumIndexing() throws Exception { final String carFQN = "com.myteam.repro.Car"; final Path testedPath = Paths.get(getClass().getResource("cars/src/main/resources/com/myteam/repro/cars.enumeration").toURI()); final Set<KProperty<?>> properties = indexer.fillIndexBuilder(testedPath).build(); final ModuleDataModelOracle oracle = indexer.getModuleDataModelOracle(testedPath); Assertions.assertThat(oracle.getModuleModelFields().keySet()).contains(carFQN); final AbstractListAssert carFields = Assertions.assertThat(properties).filteredOn("name", "ref:field:" + carFQN); carFields.filteredOn("value", "price").hasSize(1); carFields.filteredOn("value", "color").hasSize(1); final AbstractListAssert javaClasses = Assertions.assertThat(properties).filteredOn("name", "ref:java"); javaClasses.filteredOn("value", carFQN).hasSize(1); } }
@SafeVarargs private final void assertRenderingCommands(final List<RendererCommand> actualCommands, final Class<? extends RendererCommand>... expectedTypes) { assertThat(actualCommands).asList().hasOnlyElementsOfTypes(expectedTypes); Arrays.asList(expectedTypes).forEach(type -> assertThat(actualCommands).asList().filteredOn(type::isInstance).hasSize(1)); }
@SafeVarargs private final void assertRenderingCommands(final List<GridRenderer.RendererCommand> actualCommands, final Class<? extends GridRenderer.RendererCommand>... expectedTypes) { assertThat(actualCommands).asList().hasOnlyElementsOfTypes(expectedTypes); Arrays.asList(expectedTypes).forEach(type -> assertThat(actualCommands).asList().filteredOn(type::isInstance).hasSize(1)); } }
@SafeVarargs private final void assertRenderingCommands(final List<RendererCommand> actualCommands, final Class<? extends RendererCommand>... expectedTypes) { assertThat(actualCommands).asList().hasOnlyElementsOfTypes(expectedTypes); Arrays.asList(expectedTypes).forEach(type -> assertThat(actualCommands).asList().filteredOn(type::isInstance).hasSize(1)); } }
@SafeVarargs private final void assertRenderingCommands(final List<GridRenderer.RendererCommand> actualCommands, final Class<? extends GridRenderer.RendererCommand>... expectedTypes) { assertThat(actualCommands).asList().hasOnlyElementsOfTypes(expectedTypes); Arrays.asList(expectedTypes).forEach(type -> assertThat(actualCommands).asList().filteredOn(type::isInstance).hasSize(1)); } }
@SafeVarargs private final void assertRenderingCommands(final List<RendererCommand> actualCommands, final Class<? extends RendererCommand>... expectedTypes) { assertThat(actualCommands).asList().hasOnlyElementsOfTypes(expectedTypes); Arrays.asList(expectedTypes).forEach(type -> assertThat(actualCommands).asList().filteredOn(type::isInstance).hasSize(1)); } }
@SafeVarargs private final void assertRenderingCommands(final List<RendererCommand> actualCommands, final Class<? extends RendererCommand>... expectedTypes) { assertThat(actualCommands).asList().hasOnlyElementsOfTypes(expectedTypes); Arrays.asList(expectedTypes).forEach(type -> assertThat(actualCommands).asList().filteredOn(type::isInstance).hasSize(1)); }
.filteredOn(obj -> obj.getString("type").equals("counter")) .hasSize(6) .flatExtracting(JsonObject::fieldNames) .filteredOn(obj -> obj.getString("type").equals("summary")) .hasSize(4) .flatExtracting(JsonObject::fieldNames) .filteredOn(obj -> obj.getString("type").equals("timer")) .hasSize(4) .flatExtracting(JsonObject::fieldNames)