Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

AssertJ refaster migrations support string descriptions #891

Merged
merged 2 commits into from
Sep 25, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
/*
* (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.Collection;

public final class AssertjCollectionHasSizeExactlyWithDescription<T> {

@BeforeTemplate
void bad1(Collection<T> things, int size, String description) {
assertThat(things.size() == size).describedAs(description).isTrue();
}

@BeforeTemplate
void bad2(Collection<T> things, int size, String description) {
assertThat(things.size()).describedAs(description).isEqualTo(size);
}

@AfterTemplate
@UseImportPolicy(ImportPolicy.STATIC_IMPORT_ALWAYS)
void after(Collection<T> things, int size, String description) {
assertThat(things).describedAs(description).hasSize(size);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,15 @@
public final class AssertjCollectionHasSizeGreaterThan<T> {

@BeforeTemplate
void before(Collection<T> things, int size) {
void before1(Collection<T> things, int size) {
assertThat(things.size() > size).isTrue();
}

@BeforeTemplate
void before2(Collection<T> things, int size) {
assertThat(things.size()).isGreaterThan(size);
}

@AfterTemplate
@UseImportPolicy(ImportPolicy.STATIC_IMPORT_ALWAYS)
void after(Collection<T> things, int size) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
/*
* (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.Collection;

public final class AssertjCollectionHasSizeGreaterThanWithDescription<T> {

@BeforeTemplate
void before1(Collection<T> things, int size, String description) {
assertThat(things.size() > size).describedAs(description).isTrue();
}

@BeforeTemplate
void before2(Collection<T> things, int size, String description) {
assertThat(things.size()).describedAs(description).isGreaterThan(size);
}

@AfterTemplate
@UseImportPolicy(ImportPolicy.STATIC_IMPORT_ALWAYS)
void after(Collection<T> things, int size, String description) {
assertThat(things).describedAs(description).hasSizeGreaterThan(size);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
/*
* (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.common.collect.ImmutableList;
import com.google.common.collect.ImmutableSet;
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.Collection;
import java.util.Collections;

public final class AssertjCollectionIsEmptyWithDescription<T> {

@BeforeTemplate
void bad1(Collection<T> things, String description) {
assertThat(things.size() == 0).describedAs(description).isTrue();
}

@BeforeTemplate
void bad2(Collection<T> things, String description) {
assertThat(things.isEmpty()).describedAs(description).isTrue();
}

@BeforeTemplate
void bad3(Collection<T> things, String description) {
assertThat(things.size()).describedAs(description).isZero();
}

@BeforeTemplate
void bad4(Iterable<T> things, String description) {
assertThat(things).describedAs(description).isEqualTo(Collections.emptyList());
}

@BeforeTemplate
void bad5(Iterable<T> things, String description) {
assertThat(things).describedAs(description).isEqualTo(Collections.emptySet());
}

@BeforeTemplate
void bad6(Iterable<T> things, String description) {
assertThat(things).describedAs(description).isEqualTo(ImmutableList.of());
}

@BeforeTemplate
void bad7(Iterable<T> things, String description) {
assertThat(things).describedAs(description).isEqualTo(ImmutableSet.of());
}

@BeforeTemplate
void bad8(Iterable<T> things, String description) {
assertThat(things).describedAs(description).hasSize(0);
}

@BeforeTemplate
void bad9(Collection<T> things, String description) {
assertThat(things.size()).describedAs(description).isEqualTo(0);
}

@AfterTemplate
@UseImportPolicy(ImportPolicy.STATIC_IMPORT_ALWAYS)
void after(Iterable<T> things, String description) {
assertThat(things).describedAs(description).isEmpty();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
/*
* (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.common.collect.ImmutableList;
import com.google.common.collect.ImmutableSet;
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.Collection;
import java.util.Collections;

public final class AssertjCollectionIsNotEmptyWithDescription<T> {

@BeforeTemplate
void bad1(Collection<T> things, String description) {
assertThat(things.size() != 0).describedAs(description).isTrue();
}

@BeforeTemplate
void bad2(Collection<T> things, String description) {
assertThat(things.size() == 0).describedAs(description).isFalse();
}

@BeforeTemplate
void bad3(Collection<T> things, String description) {
assertThat(things.size()).describedAs(description).isNotEqualTo(0);
}

@BeforeTemplate
void bad4(Collection<T> things, String description) {
assertThat(things.isEmpty()).describedAs(description).isFalse();
}

@BeforeTemplate
void bad5(Collection<T> things, String description) {
assertThat(!things.isEmpty()).describedAs(description).isTrue();
}

@BeforeTemplate
void bad6(Collection<T> things, String description) {
assertThat(things).describedAs(description).isNotEqualTo(Collections.emptyList());
}

@BeforeTemplate
void bad7(Collection<T> things, String description) {
assertThat(things).describedAs(description).isNotEqualTo(Collections.emptySet());
}

@BeforeTemplate
void bad8(Collection<T> things, String description) {
assertThat(things).describedAs(description).isNotEqualTo(ImmutableList.of());
}

@BeforeTemplate
void bad9(Collection<T> things, String description) {
assertThat(things).describedAs(description).isNotEqualTo(ImmutableSet.of());
}

@AfterTemplate
@UseImportPolicy(ImportPolicy.STATIC_IMPORT_ALWAYS)
void after(Collection<T> things, String description) {
assertThat(things).describedAs(description).isNotEmpty();
}
}
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;
import java.util.Optional;

public final class AssertjOptionalIsPresentWithDescription<T> {

@BeforeTemplate
void before(Optional<T> thing, String description) {
assertThat(thing.isPresent()).describedAs(description).isTrue();
}

@AfterTemplate
@UseImportPolicy(ImportPolicy.STATIC_IMPORT_ALWAYS)
void after(Optional<T> thing, String description) {
assertThat(thing).describedAs(description).isPresent();
}
}
Loading