Skip to content

Commit

Permalink
Refaster rules for checks that maps do not contain a specific key (#935)
Browse files Browse the repository at this point in the history
Refaster rules for checks that maps do not contain a specific key
  • Loading branch information
carterkozak authored and bulldozer-bot[bot] committed Oct 3, 2019
1 parent 8862dac commit e4a15fe
Show file tree
Hide file tree
Showing 18 changed files with 740 additions and 10 deletions.
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();
}

}
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();
}
}
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();
}

}
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();
}
}
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();
}

}
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();
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,11 @@ void before2(Map<K, V> things, K key) {
assertThat(things.keySet().contains(key)).isTrue();
}

@BeforeTemplate
void before3(Map<K, V> things, K key) {
assertThat(things.get(key)).isNotNull();
}

@AfterTemplate
@UseImportPolicy(ImportPolicy.STATIC_IMPORT_ALWAYS)
void after(Map<K, V> things, K key) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,11 @@ void before2(Map<K, V> things, K key, String description, @Repeated Object descr
assertThat(things.keySet().contains(key)).describedAs(description, descriptionArgs).isTrue();
}

@BeforeTemplate
void before3(Map<K, V> things, K key, String description, @Repeated Object descriptionArgs) {
assertThat(things.get(key)).describedAs(description, descriptionArgs).isNotNull();
}

@AfterTemplate
@UseImportPolicy(ImportPolicy.STATIC_IMPORT_ALWAYS)
void after(Map<K, V> things, K key, String description, @Repeated Object descriptionArgs) {
Expand Down
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);
}
}
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);
}
}
Loading

0 comments on commit e4a15fe

Please sign in to comment.