-
Notifications
You must be signed in to change notification settings - Fork 687
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
63486fe
commit 9fcaeb4
Showing
21 changed files
with
1,250 additions
and
60 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
74 changes: 74 additions & 0 deletions
74
java-frontend/src/test/java/org/sonar/java/collections/SECollectionUtilsTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
/* | ||
* SonarQube Java | ||
* Copyright (C) 2012-2024 SonarSource SA | ||
* mailto:info AT sonarsource DOT com | ||
* | ||
* This program is free software; you can redistribute it and/or | ||
* modify it under the terms of the GNU Lesser General Public | ||
* License as published by the Free Software Foundation; either | ||
* version 3 of the License, or (at your option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
* Lesser General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU Lesser General Public License | ||
* along with this program; if not, write to the Free Software Foundation, | ||
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. | ||
*/ | ||
package org.sonar.java.collections; | ||
|
||
import java.util.Arrays; | ||
import java.util.Collections; | ||
import java.util.Iterator; | ||
import java.util.List; | ||
import javax.annotation.Nullable; | ||
import org.junit.jupiter.api.Test; | ||
|
||
import static org.assertj.core.api.Assertions.assertThat; | ||
|
||
final class SECollectionUtilsTest { | ||
|
||
@Test | ||
void test_get_first_String() { | ||
List<String> list = Arrays.asList("A", "B", "Z"); | ||
assertThat(CollectionUtils.getFirst(list, null)).isEqualTo("A"); | ||
} | ||
|
||
@Test | ||
void test_get_first_default_value() { | ||
assertThat(CollectionUtils.getFirst(Collections.emptySet(), "ABC")).isEqualTo("ABC"); | ||
} | ||
|
||
@Test | ||
void test_get_collection_size() { | ||
assertThat(CollectionUtils.size(Arrays.asList("a", "b", "c"))).isEqualTo(3); | ||
} | ||
|
||
@Test | ||
void test_get_iterable_size() { | ||
assertThat(CollectionUtils.size(new SomeIterable<String>())).isEqualTo(3); | ||
} | ||
|
||
private static class SomeIterable<T> implements Iterable<T> { | ||
|
||
@Override | ||
public Iterator<T> iterator() { | ||
return new Iterator<T>() { | ||
private int count = 3; | ||
@Override | ||
public boolean hasNext() { | ||
return count > 0; | ||
} | ||
|
||
@Override | ||
@Nullable | ||
public T next() { | ||
count--; | ||
return null; | ||
} | ||
}; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
24 changes: 24 additions & 0 deletions
24
...ution/java-symbolic-execution-plugin/src/main/java/org/sonar/java/model/package-info.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
/* | ||
* SonarQube Java | ||
* Copyright (C) 2012-2024 SonarSource SA | ||
* mailto:info AT sonarsource DOT com | ||
* | ||
* This program is free software; you can redistribute it and/or | ||
* modify it under the terms of the GNU Lesser General Public | ||
* License as published by the Free Software Foundation; either | ||
* version 3 of the License, or (at your option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
* Lesser General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU Lesser General Public License | ||
* along with this program; if not, write to the Free Software Foundation, | ||
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. | ||
*/ | ||
@javax.annotation.ParametersAreNonnullByDefault | ||
@MethodsAreNonnullByDefault | ||
package org.sonar.java.model; | ||
|
||
import org.sonar.plugins.java.api.tree.MethodsAreNonnullByDefault; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
24 changes: 24 additions & 0 deletions
24
...-execution/java-symbolic-execution-plugin/src/test/files/model/SEExpressionUtilsTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
class SimpleAssignments { | ||
|
||
Integer myField; | ||
|
||
public void mixedReference() { | ||
myField = getSomething(); // Simple | ||
this.myField = getSomething(); // Simple | ||
this.getOtherInstance().myField = getSomething(); // Not simple | ||
this.myField /= getSomething(); // Not simple | ||
|
||
SimpleAssignments simpleAssignments1 = new SimpleAssignments(); | ||
simpleAssignments.myField = getSomething(); | ||
|
||
SimpleAssignments simpleAssignments2 = getOtherInstance(); | ||
} | ||
|
||
public SimpleAssignments getOtherInstance() { | ||
return new SimpleAssignments(); | ||
} | ||
|
||
private int getSomething() { | ||
return 1; | ||
} | ||
} |
Oops, something went wrong.