Skip to content

Commit

Permalink
Update tests with dependencies
Browse files Browse the repository at this point in the history
  • Loading branch information
tomasz-strzelecki-vml committed Oct 29, 2024
1 parent 4b3ea13 commit 6c39760
Show file tree
Hide file tree
Showing 48 changed files with 332 additions and 385 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ jobs:

strategy:
matrix:
java-version: [ 11, 17 ]
java-version: [ 11 ]

steps:
- uses: actions/checkout@v4
Expand Down
2 changes: 1 addition & 1 deletion local-docker-image/conf/sonar.properties
Original file line number Diff line number Diff line change
Expand Up @@ -446,4 +446,4 @@
# We don't collect source code or IP addresses. And we don't share the data with anyone else.
#sonar.telemetry.enable=true

sonar.web.javaAdditionalOpts=-agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=*:5005
sonar.web.javaAdditionalOpts=-agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=*:8000
2 changes: 1 addition & 1 deletion local-docker-image/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ services:
context: .
ports:
- "9000:9000"
- "5005:5005"
- "8000:8000"
restart: unless-stopped
volumes:
- ./extensions/plugins:/opt/sonarqube/extensions/plugins:ro
Expand Down
35 changes: 15 additions & 20 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@
<sonar.testingHarnessVersion>10.7.0.96327</sonar.testingHarnessVersion>
<sonar.javaCheksTestkitVersion>7.30.1.34514</sonar.javaCheksTestkitVersion>
<jdk.min.version>11</jdk.min.version>
<sonar.sources>src/main/java,src/main/js</sonar.sources>
<sonar.sources>src/main/java</sonar.sources>
<coveralls.repo.token>4rVf3NGV0jyQ3EGrc8L86oEDoHWm6MgDD</coveralls.repo.token>
<tagName>v${project.version}</tagName>
</properties>
Expand Down Expand Up @@ -215,40 +215,34 @@
<version>${sonar.testingHarnessVersion}</version>
</dependency>
<dependency>
<artifactId>junit</artifactId>
<groupId>junit</groupId>
<artifactId>junit-jupiter-api</artifactId>
<groupId>org.junit.jupiter</groupId>
<scope>test</scope>
<version>4.13.2</version>
<version>5.11.3</version>
</dependency>
<dependency>
<artifactId>junit-jupiter-params</artifactId>
<groupId>org.junit.jupiter</groupId>
<scope>test</scope>
<version>5.11.3</version>
</dependency>
<dependency>
<artifactId>mockito-core</artifactId>
<groupId>org.mockito</groupId>
<scope>test</scope>
<version>5.12.0</version>
<version>5.14.2</version>
</dependency>
<dependency>
<artifactId>assertj-core</artifactId>
<groupId>org.assertj</groupId>
<scope>test</scope>
<version>3.26.0</version>
</dependency>
<dependency>
<artifactId>fest-assert</artifactId>
<groupId>org.easytesting</groupId>
<scope>test</scope>
<version>1.4</version>
</dependency>
<dependency>
<artifactId>hamcrest-all</artifactId>
<groupId>org.hamcrest</groupId>
<scope>test</scope>
<version>1.3</version>
<version>3.26.3</version>
</dependency>
<dependency>
<artifactId>guava</artifactId>
<groupId>com.google.guava</groupId>
<scope>test</scope>
<version>32.0.0-jre</version>
<version>33.3.1-jre</version>
</dependency>
<dependency>
<artifactId>sonar-plugin-api-impl</artifactId>
Expand All @@ -272,8 +266,9 @@
<artifactId>logback-classic</artifactId>
<groupId>ch.qos.logback</groupId>
<scope>test</scope>
<version>1.2.13</version>
<version>1.5.12</version>
</dependency>
<!-- aem dependencies-->
<dependency>
<artifactId>aem-api</artifactId>
<groupId>com.adobe.aem</groupId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -255,4 +255,4 @@ public boolean match(int character) {
}
}

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ private void visitMethodWithMVM(IdentifierTree modifiableValueMapUsageIdentifier
int argumentNumber = ((Arguments) usageOfMVM).indexOf(modifiableValueMapUsageIdentifier);
MethodInvocationTree methodInvocationWithMVM = (MethodInvocationTree) usageOfMVM.parent();
if (methodInvocationWithMVM != null) {
MethodTree methodWithMVM = (MethodTree) methodInvocationWithMVM.methodSymbol().declaration();
MethodTree methodWithMVM = methodInvocationWithMVM.methodSymbol().declaration();
if (methodWithMVM != null && methodWithMVM.is(Tree.Kind.METHOD)) {
MethodWithMVMVisitor methodWithMVMVisitor = new MethodWithMVMVisitor(this, argumentNumber);
methodWithMVM.accept(methodWithMVMVisitor);
Expand Down Expand Up @@ -128,4 +128,4 @@ public void visitMethod(MethodTree tree) {
}

}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ public void visitReturnStatement(ReturnStatementTree tree) {
IdentifierTree identifier = (IdentifierTree) tree.expression();
Tree declaration = identifier.symbol().declaration();
if (resourceResolvers.contains(declaration)) {
resourceResolvers.remove(declaration);
resourceResolvers.remove(declaration);
}
}
super.visitReturnStatement(tree);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ public void visitReturnStatement(ReturnStatementTree tree) {
IdentifierTree identifier = (IdentifierTree) tree.expression();
Tree declaration = getDeclaration(identifier);
if (sessions.contains(declaration)) {
sessions.remove(declaration);
sessions.remove(declaration);
}
}
super.visitReturnStatement(tree);
Expand Down Expand Up @@ -188,4 +188,4 @@ public Tree getDeclarationOfReturnedVariable() {

}

}
}
8 changes: 7 additions & 1 deletion src/main/java/com/vml/aemrules/utils/Throwables.java
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public static Throwable getRootCause(Throwable throwable) {

public static RuntimeException propagate(Throwable throwable) {
throwIfUnchecked(throwable);
throw new RuntimeException(throwable);
throw new AemRulesTestRuntimeException(throwable);
}

public static void throwIfUnchecked(Throwable throwable) {
Expand All @@ -47,4 +47,10 @@ public static void throwIfUnchecked(Throwable throwable) {
throw (Error) throwable;
}
}

private static class AemRulesTestRuntimeException extends RuntimeException {
public AemRulesTestRuntimeException(Throwable throwable) {
super(throwable);
}
}
}
2 changes: 1 addition & 1 deletion src/main/java/com/vml/aemrules/version/Version.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@

public class Version {

private static final Pattern VERSION_PATTERN = Pattern.compile("(?<major>[0-9]+)\\.(?<minor>[0-9])");
private static final Pattern VERSION_PATTERN = Pattern.compile("(?<major>\\d+)\\.(?<minor>\\d)");

private final int major;

Expand Down
6 changes: 3 additions & 3 deletions src/test/java/com/vml/aemrules/AemRulesSonarPluginTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
*/
package com.vml.aemrules;

import org.junit.Test;
import org.junit.jupiter.api.Test;
import org.sonar.api.Plugin;
import org.sonar.api.SonarEdition;
import org.sonar.api.SonarQubeSide;
Expand All @@ -28,10 +28,10 @@

import static org.assertj.core.api.Assertions.assertThat;

public class AemRulesSonarPluginTest {
class AemRulesSonarPluginTest {

@Test
public void webPluginTester() {
void webPluginTester() {
Plugin.Context context = new Plugin.Context(SonarRuntimeImpl.forSonarQube(Version.create(6, 7), SonarQubeSide.SERVER, SonarEdition.COMMUNITY));

new AemRulesSonarPlugin().define(context);
Expand Down
15 changes: 7 additions & 8 deletions src/test/java/com/vml/aemrules/htl/HtlProfileTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,8 @@
*/
package com.vml.aemrules.htl;


import org.junit.Before;
import org.junit.Test;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.sonar.api.server.profile.BuiltInQualityProfilesDefinition.BuiltInActiveRule;
import org.sonar.api.server.profile.BuiltInQualityProfilesDefinition.BuiltInQualityProfile;
import org.sonar.api.server.profile.BuiltInQualityProfilesDefinition.Context;
Expand All @@ -32,23 +31,23 @@
import java.util.function.Function;
import java.util.stream.Collectors;

import static org.fest.assertions.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThat;

public class HtlProfileTest {
class HtlProfileTest {

private HtlProfile profile;

private Context context;

@Before
@BeforeEach
public void setUp() {
profile = new HtlProfile();
this.context = new Context();

}

@Test
public void sanity() {
void sanity() {
profile.define(context);
Map<String, BuiltInActiveRule> activeRules = getActiveRulesByRuleKey(context);

Expand All @@ -57,7 +56,7 @@ public void sanity() {
}

@Test
public void rulesLoaded() {
void rulesLoaded() {
profile.define(context);
Map<String, BuiltInActiveRule> activeRules = getActiveRulesByRuleKey(context);

Expand Down
24 changes: 12 additions & 12 deletions src/test/java/com/vml/aemrules/htl/HtlSensorTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@

import com.vml.aemrules.htl.checks.HtlAttributesShouldBeAtTheEndCheck;
import com.vml.aemrules.htl.rules.HtlRulesDefinition;
import org.junit.Before;
import org.junit.Test;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.mockito.Mockito;
import org.sonar.api.SonarEdition;
import org.sonar.api.SonarQubeSide;
Expand Down Expand Up @@ -59,16 +59,16 @@
import static org.mockito.Mockito.when;


public class HtlSensorTest {
class HtlSensorTest {

private static final File TEST_DIR = new File("src/test/resources/sensor");

private HtlSensor sensor;

private SensorContextTester tester;

@Before
public void setUp() {
@BeforeEach
void setUp() {
SonarRuntime sonarRuntime = SonarRuntimeImpl.forSonarQube(Version.create(8, 9), SonarQubeSide.SERVER, SonarEdition.COMMUNITY);
RulesDefinition rulesDefinition = new HtlRulesDefinition(sonarRuntime);
RulesDefinition.Context context = new RulesDefinition.Context();
Expand Down Expand Up @@ -105,7 +105,7 @@ private FileLinesContextFactory getMockedFileLinesContextFactory() {
}

@Test
public void checkIncorrectFile_issuesFound() throws Exception {
void checkIncorrectFile_issuesFound() throws Exception {
DefaultInputFile inputFile = createInputFile(TEST_DIR, "test.html");
tester.fileSystem().add(inputFile);
sensor.execute(tester);
Expand All @@ -119,7 +119,7 @@ public void checkIncorrectFile_issuesFound() throws Exception {
}

@Test
public void checkCancellation_noIssueFound() throws Exception {
void checkCancellation_noIssueFound() throws Exception {
DefaultInputFile inputFile = createInputFile(TEST_DIR, "test.html");
tester.fileSystem().add(inputFile);
tester.setCancelled(true);
Expand All @@ -128,7 +128,7 @@ public void checkCancellation_noIssueFound() throws Exception {
}

@Test
public void sonarlintCheck() throws Exception {
void sonarlintCheck() throws Exception {
DefaultInputFile inputFile = createInputFile(TEST_DIR, "test.html");
tester.fileSystem().add(inputFile);
sensor.execute(tester);
Expand All @@ -139,31 +139,31 @@ public void sonarlintCheck() throws Exception {
}

@Test
public void checkFileWithError_analysisErrorFound() throws Exception {
void checkFileWithError_analysisErrorFound() throws Exception {
DefaultInputFile inputFile = createInputFile(TEST_DIR, "error.html");
tester.fileSystem().add(inputFile);
sensor.execute(tester);
assertThat(tester.allAnalysisErrors()).isNotEmpty();
}

@Test
public void checkExpressionWithinHtmlComment_noErrorsFound() throws Exception {
void checkExpressionWithinHtmlComment_noErrorsFound() throws Exception {
DefaultInputFile inputFile = createInputFile(TEST_DIR, "comment.html");
tester.fileSystem().add(inputFile);
sensor.execute(tester);
assertThat(tester.allAnalysisErrors()).isNotEmpty();
}

@Test
public void checkNestedTags_noErrorsFound() throws IOException {
void checkNestedTags_noErrorsFound() throws IOException {
DefaultInputFile inputFile = createInputFile(TEST_DIR, "nestedTags.html");
tester.fileSystem().add(inputFile);
sensor.execute(tester);
assertThat(tester.allAnalysisErrors()).isEmpty();
}

@Test
public void checkDescriptorConfiguration() {
void checkDescriptorConfiguration() {
DefaultSensorDescriptor descriptor = new DefaultSensorDescriptor();
sensor.describe(descriptor);
assertThat(descriptor.name()).isEqualTo("HTL");
Expand Down
6 changes: 3 additions & 3 deletions src/test/java/com/vml/aemrules/htl/HtlTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,15 @@
*/
package com.vml.aemrules.htl;

import org.junit.Test;
import org.junit.jupiter.api.Test;

import static org.assertj.core.api.Assertions.assertThat;


public class HtlTest {
class HtlTest {

@Test
public void shouldReturnEmptyArrayOfDefaultFileSuffixes() {
void shouldReturnEmptyArrayOfDefaultFileSuffixes() {
Htl htl = new Htl();
assertThat(htl.getFileSuffixes()).isEmpty();
}
Expand Down
Loading

0 comments on commit 6c39760

Please sign in to comment.