-
Notifications
You must be signed in to change notification settings - Fork 134
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refaster rules for checks that maps do not contain a specific key (#935)
Refaster rules for checks that maps do not contain a specific key
- Loading branch information
1 parent
8862dac
commit e4a15fe
Showing
18 changed files
with
740 additions
and
10 deletions.
There are no files selected for viewing
39 changes: 39 additions & 0 deletions
39
...ter-rules/src/main/java/com/palantir/baseline/refaster/AssertjBooleanNegationIsFalse.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,39 @@ | ||
/* | ||
* (c) Copyright 2019 Palantir Technologies Inc. All rights reserved. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package com.palantir.baseline.refaster; | ||
|
||
import static org.assertj.core.api.Assertions.assertThat; | ||
|
||
import com.google.errorprone.refaster.ImportPolicy; | ||
import com.google.errorprone.refaster.annotation.AfterTemplate; | ||
import com.google.errorprone.refaster.annotation.BeforeTemplate; | ||
import com.google.errorprone.refaster.annotation.UseImportPolicy; | ||
|
||
public final class AssertjBooleanNegationIsFalse { | ||
|
||
@BeforeTemplate | ||
void before(boolean input) { | ||
assertThat(!input).isFalse(); | ||
} | ||
|
||
@AfterTemplate | ||
@UseImportPolicy(ImportPolicy.STATIC_IMPORT_ALWAYS) | ||
void after(boolean input) { | ||
assertThat(input).isTrue(); | ||
} | ||
|
||
} |
39 changes: 39 additions & 0 deletions
39
...ain/java/com/palantir/baseline/refaster/AssertjBooleanNegationIsFalseWithDescription.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,39 @@ | ||
/* | ||
* (c) Copyright 2019 Palantir Technologies Inc. All rights reserved. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package com.palantir.baseline.refaster; | ||
|
||
import static org.assertj.core.api.Assertions.assertThat; | ||
|
||
import com.google.errorprone.refaster.ImportPolicy; | ||
import com.google.errorprone.refaster.annotation.AfterTemplate; | ||
import com.google.errorprone.refaster.annotation.BeforeTemplate; | ||
import com.google.errorprone.refaster.annotation.Repeated; | ||
import com.google.errorprone.refaster.annotation.UseImportPolicy; | ||
|
||
public final class AssertjBooleanNegationIsFalseWithDescription { | ||
|
||
@BeforeTemplate | ||
void before(boolean input, String description, @Repeated Object descriptionArgs) { | ||
assertThat(!input).describedAs(description, descriptionArgs).isFalse(); | ||
} | ||
|
||
@AfterTemplate | ||
@UseImportPolicy(ImportPolicy.STATIC_IMPORT_ALWAYS) | ||
void after(boolean input, String description, @Repeated Object descriptionArgs) { | ||
assertThat(input).describedAs(description, descriptionArgs).isTrue(); | ||
} | ||
} |
39 changes: 39 additions & 0 deletions
39
...ster-rules/src/main/java/com/palantir/baseline/refaster/AssertjBooleanNegationIsTrue.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,39 @@ | ||
/* | ||
* (c) Copyright 2019 Palantir Technologies Inc. All rights reserved. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package com.palantir.baseline.refaster; | ||
|
||
import static org.assertj.core.api.Assertions.assertThat; | ||
|
||
import com.google.errorprone.refaster.ImportPolicy; | ||
import com.google.errorprone.refaster.annotation.AfterTemplate; | ||
import com.google.errorprone.refaster.annotation.BeforeTemplate; | ||
import com.google.errorprone.refaster.annotation.UseImportPolicy; | ||
|
||
public final class AssertjBooleanNegationIsTrue { | ||
|
||
@BeforeTemplate | ||
void before(boolean input) { | ||
assertThat(!input).isTrue(); | ||
} | ||
|
||
@AfterTemplate | ||
@UseImportPolicy(ImportPolicy.STATIC_IMPORT_ALWAYS) | ||
void after(boolean input) { | ||
assertThat(input).isFalse(); | ||
} | ||
|
||
} |
39 changes: 39 additions & 0 deletions
39
...main/java/com/palantir/baseline/refaster/AssertjBooleanNegationIsTrueWithDescription.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,39 @@ | ||
/* | ||
* (c) Copyright 2019 Palantir Technologies Inc. All rights reserved. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package com.palantir.baseline.refaster; | ||
|
||
import static org.assertj.core.api.Assertions.assertThat; | ||
|
||
import com.google.errorprone.refaster.ImportPolicy; | ||
import com.google.errorprone.refaster.annotation.AfterTemplate; | ||
import com.google.errorprone.refaster.annotation.BeforeTemplate; | ||
import com.google.errorprone.refaster.annotation.Repeated; | ||
import com.google.errorprone.refaster.annotation.UseImportPolicy; | ||
|
||
public final class AssertjBooleanNegationIsTrueWithDescription { | ||
|
||
@BeforeTemplate | ||
void before(boolean input, String description, @Repeated Object descriptionArgs) { | ||
assertThat(!input).describedAs(description, descriptionArgs).isTrue(); | ||
} | ||
|
||
@AfterTemplate | ||
@UseImportPolicy(ImportPolicy.STATIC_IMPORT_ALWAYS) | ||
void after(boolean input, String description, @Repeated Object descriptionArgs) { | ||
assertThat(input).describedAs(description, descriptionArgs).isFalse(); | ||
} | ||
} |
55 changes: 55 additions & 0 deletions
55
baseline-refaster-rules/src/main/java/com/palantir/baseline/refaster/AssertjIsNull.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,55 @@ | ||
/* | ||
* (c) Copyright 2019 Palantir Technologies Inc. All rights reserved. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package com.palantir.baseline.refaster; | ||
|
||
import static org.assertj.core.api.Assertions.assertThat; | ||
|
||
import com.google.errorprone.refaster.ImportPolicy; | ||
import com.google.errorprone.refaster.annotation.AfterTemplate; | ||
import com.google.errorprone.refaster.annotation.BeforeTemplate; | ||
import com.google.errorprone.refaster.annotation.UseImportPolicy; | ||
import java.util.Objects; | ||
|
||
public final class AssertjIsNull { | ||
|
||
@BeforeTemplate | ||
void before1(Object input) { | ||
assertThat(input == null).isTrue(); | ||
} | ||
|
||
@BeforeTemplate | ||
void before2(Object input) { | ||
assertThat(input != null).isFalse(); | ||
} | ||
|
||
@BeforeTemplate | ||
void before3(Object input) { | ||
assertThat(Objects.isNull(input)).isTrue(); | ||
} | ||
|
||
@BeforeTemplate | ||
void before4(Object input) { | ||
assertThat(Objects.nonNull(input)).isFalse(); | ||
} | ||
|
||
@AfterTemplate | ||
@UseImportPolicy(ImportPolicy.STATIC_IMPORT_ALWAYS) | ||
void after(Object input) { | ||
assertThat(input).isNull(); | ||
} | ||
|
||
} |
56 changes: 56 additions & 0 deletions
56
...ster-rules/src/main/java/com/palantir/baseline/refaster/AssertjIsNullWithDescription.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,56 @@ | ||
/* | ||
* (c) Copyright 2019 Palantir Technologies Inc. All rights reserved. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package com.palantir.baseline.refaster; | ||
|
||
import static org.assertj.core.api.Assertions.assertThat; | ||
|
||
import com.google.errorprone.refaster.ImportPolicy; | ||
import com.google.errorprone.refaster.annotation.AfterTemplate; | ||
import com.google.errorprone.refaster.annotation.BeforeTemplate; | ||
import com.google.errorprone.refaster.annotation.Repeated; | ||
import com.google.errorprone.refaster.annotation.UseImportPolicy; | ||
import java.util.Objects; | ||
|
||
public final class AssertjIsNullWithDescription { | ||
|
||
@BeforeTemplate | ||
void before1(Object input, String description, @Repeated Object descriptionArgs) { | ||
assertThat(input == null).describedAs(description, descriptionArgs).isTrue(); | ||
} | ||
|
||
@BeforeTemplate | ||
void before2(Object input, String description, @Repeated Object descriptionArgs) { | ||
assertThat(input != null).describedAs(description, descriptionArgs).isFalse(); | ||
} | ||
|
||
@BeforeTemplate | ||
void before3(Object input, String description, @Repeated Object descriptionArgs) { | ||
assertThat(Objects.isNull(input)).describedAs(description, descriptionArgs).isTrue(); | ||
} | ||
|
||
@BeforeTemplate | ||
void before4(Object input, String description, @Repeated Object descriptionArgs) { | ||
assertThat(Objects.nonNull(input)).describedAs(description, descriptionArgs).isFalse(); | ||
} | ||
|
||
@AfterTemplate | ||
@UseImportPolicy(ImportPolicy.STATIC_IMPORT_ALWAYS) | ||
void after(Object input, String description, @Repeated Object descriptionArgs) { | ||
assertThat(input).describedAs(description, descriptionArgs).isNull(); | ||
} | ||
|
||
} |
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
50 changes: 50 additions & 0 deletions
50
...aster-rules/src/main/java/com/palantir/baseline/refaster/AssertjMapDoesNotContainKey.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,50 @@ | ||
/* | ||
* (c) Copyright 2019 Palantir Technologies Inc. All rights reserved. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package com.palantir.baseline.refaster; | ||
|
||
import static org.assertj.core.api.Assertions.assertThat; | ||
|
||
import com.google.errorprone.refaster.ImportPolicy; | ||
import com.google.errorprone.refaster.annotation.AfterTemplate; | ||
import com.google.errorprone.refaster.annotation.BeforeTemplate; | ||
import com.google.errorprone.refaster.annotation.UseImportPolicy; | ||
import java.util.Map; | ||
|
||
public final class AssertjMapDoesNotContainKey<K, V> { | ||
|
||
@BeforeTemplate | ||
void before1(Map<K, V> things, K key) { | ||
assertThat(things.containsKey(key)).isFalse(); | ||
} | ||
|
||
@BeforeTemplate | ||
void before2(Map<K, V> things, K key) { | ||
assertThat(things.get(key)).isNull(); | ||
} | ||
|
||
@BeforeTemplate | ||
@SuppressWarnings("RedundantCollectionOperation") // It's what we're fixing | ||
void before3(Map<K, V> things, K key) { | ||
assertThat(things.keySet().contains(key)).isFalse(); | ||
} | ||
|
||
@AfterTemplate | ||
@UseImportPolicy(ImportPolicy.STATIC_IMPORT_ALWAYS) | ||
void after(Map<K, V> things, K key) { | ||
assertThat(things).doesNotContainKey(key); | ||
} | ||
} |
51 changes: 51 additions & 0 deletions
51
.../main/java/com/palantir/baseline/refaster/AssertjMapDoesNotContainKeyWithDescription.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,51 @@ | ||
/* | ||
* (c) Copyright 2019 Palantir Technologies Inc. All rights reserved. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package com.palantir.baseline.refaster; | ||
|
||
import static org.assertj.core.api.Assertions.assertThat; | ||
|
||
import com.google.errorprone.refaster.ImportPolicy; | ||
import com.google.errorprone.refaster.annotation.AfterTemplate; | ||
import com.google.errorprone.refaster.annotation.BeforeTemplate; | ||
import com.google.errorprone.refaster.annotation.Repeated; | ||
import com.google.errorprone.refaster.annotation.UseImportPolicy; | ||
import java.util.Map; | ||
|
||
public final class AssertjMapDoesNotContainKeyWithDescription<K, V> { | ||
|
||
@BeforeTemplate | ||
void before1(Map<K, V> things, K key, String description, @Repeated Object descriptionArgs) { | ||
assertThat(things.containsKey(key)).describedAs(description, descriptionArgs).isFalse(); | ||
} | ||
|
||
@BeforeTemplate | ||
void before2(Map<K, V> things, K key, String description, @Repeated Object descriptionArgs) { | ||
assertThat(things.get(key)).describedAs(description, descriptionArgs).isNull(); | ||
} | ||
|
||
@BeforeTemplate | ||
@SuppressWarnings("RedundantCollectionOperation") // It's what we're fixing | ||
void before3(Map<K, V> things, K key, String description, @Repeated Object descriptionArgs) { | ||
assertThat(things.keySet().contains(key)).describedAs(description, descriptionArgs).isFalse(); | ||
} | ||
|
||
@AfterTemplate | ||
@UseImportPolicy(ImportPolicy.STATIC_IMPORT_ALWAYS) | ||
void after(Map<K, V> things, K key, String description, @Repeated Object descriptionArgs) { | ||
assertThat(things).describedAs(description, descriptionArgs).doesNotContainKey(key); | ||
} | ||
} |
Oops, something went wrong.