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

Refaster rules for AssertJ tests #898

Merged
merged 2 commits into from
Sep 27, 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,58 @@
/*
* (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;

/**
* We have to guess as to which value is expected and which is the actual result, but either way failures will
* produce significantly more helpful output.
*/
public final class AssertjEquals<T> {

@BeforeTemplate
void before1(T expected, T actual) {
assertThat(actual.equals(expected)).isTrue();
}

@BeforeTemplate
void before2(T expected, T actual) {
assertThat(Objects.equals(actual, expected)).isTrue();
}

@BeforeTemplate
void before3(T expected, T actual) {
assertThat(!actual.equals(expected)).isFalse();
}

@BeforeTemplate
void before4(T expected, T actual) {
assertThat(!Objects.equals(actual, expected)).isFalse();
}

@AfterTemplate
@UseImportPolicy(ImportPolicy.STATIC_IMPORT_ALWAYS)
void after(T expected, T actual) {
assertThat(actual).isEqualTo(expected);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
/*
* (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;

/**
* We have to guess as to which value is expected and which is the actual result, but either way failures will
* produce significantly more helpful output.
*/
public final class AssertjEqualsWithDescription<T> {

@BeforeTemplate
void before1(T expected, T actual, String description) {
assertThat(actual.equals(expected)).describedAs(description).isTrue();
}

@BeforeTemplate
void before2(T expected, T actual, String description) {
assertThat(Objects.equals(actual, expected)).describedAs(description).isTrue();
}

@BeforeTemplate
void before3(T expected, T actual, String description) {
assertThat(!actual.equals(expected)).describedAs(description).isFalse();
}

@BeforeTemplate
void before4(T expected, T actual, String description) {
assertThat(!Objects.equals(actual, expected)).describedAs(description).isFalse();
}

@AfterTemplate
@UseImportPolicy(ImportPolicy.STATIC_IMPORT_ALWAYS)
void after(T expected, T actual, String description) {
assertThat(actual).describedAs(description).isEqualTo(expected);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
/*
* (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.Refaster;
import com.google.errorprone.refaster.annotation.AfterTemplate;
import com.google.errorprone.refaster.annotation.BeforeTemplate;
import com.google.errorprone.refaster.annotation.UseImportPolicy;

/**
* We have to guess as to which value is expected and which is the actual result, but either way failures will
* produce significantly more helpful output.
*/
public final class AssertjInstanceOf<T, E> {

@BeforeTemplate
void before(T input) {
assertThat(Refaster.<E>isInstance(input)).isTrue();
}

@AfterTemplate
@UseImportPolicy(ImportPolicy.STATIC_IMPORT_ALWAYS)
void after(T input) {
assertThat(input).isInstanceOf(Refaster.<E>clazz());
}
}
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.Refaster;
import com.google.errorprone.refaster.annotation.AfterTemplate;
import com.google.errorprone.refaster.annotation.BeforeTemplate;
import com.google.errorprone.refaster.annotation.UseImportPolicy;

public final class AssertjInstanceOfWithDescription<T, E> {

@BeforeTemplate
void before(T input, String description) {
assertThat(Refaster.<E>isInstance(input)).describedAs(description).isTrue();
}

@AfterTemplate
@UseImportPolicy(ImportPolicy.STATIC_IMPORT_ALWAYS)
void after(T input, String description) {
assertThat(input).describedAs(description).isInstanceOf(Refaster.<E>clazz());
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
/*
* (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;

/**
* We have to guess as to which value is expected and which is the actual result, but either way failures will
* produce significantly more helpful output.
*/
public final class AssertjNotEquals<T> {

@BeforeTemplate
void before1(T expected, T actual) {
assertThat(!actual.equals(expected)).isTrue();
}

@BeforeTemplate
void before2(T expected, T actual) {
assertThat(!Objects.equals(actual, expected)).isTrue();
}

@BeforeTemplate
void before3(T expected, T actual) {
assertThat(actual.equals(expected)).isFalse();
}

@BeforeTemplate
void before4(T expected, T actual) {
assertThat(Objects.equals(actual, expected)).isFalse();
}

@AfterTemplate
@UseImportPolicy(ImportPolicy.STATIC_IMPORT_ALWAYS)
void after(T expected, T actual) {
assertThat(actual).isNotEqualTo(expected);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
/*
* (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;

/**
* We have to guess as to which value is expected and which is the actual result, but either way failures will
* produce significantly more helpful output.
*/
public final class AssertjNotEqualsWithDescription<T> {

@BeforeTemplate
void before1(T expected, T actual, String description) {
assertThat(!actual.equals(expected)).describedAs(description).isTrue();
}

@BeforeTemplate
void before2(T expected, T actual, String description) {
assertThat(!Objects.equals(actual, expected)).describedAs(description).isTrue();
}

@BeforeTemplate
void before3(T expected, T actual, String description) {
assertThat(actual.equals(expected)).describedAs(description).isFalse();
}

@BeforeTemplate
void before4(T expected, T actual, String description) {
assertThat(Objects.equals(actual, expected)).describedAs(description).isFalse();
}

@AfterTemplate
@UseImportPolicy(ImportPolicy.STATIC_IMPORT_ALWAYS)
void after(T expected, T actual, String description) {
assertThat(actual).describedAs(description).isNotEqualTo(expected);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
/*
* (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 AssertjStringContains {

@BeforeTemplate
void before1(String input, CharSequence contains) {
assertThat(input.contains(contains)).isTrue();
}

@BeforeTemplate
void before2(String input, CharSequence contains) {
assertThat(!input.contains(contains)).isFalse();
}

@AfterTemplate
@UseImportPolicy(ImportPolicy.STATIC_IMPORT_ALWAYS)
void after(String input, CharSequence contains) {
assertThat(input).contains(contains);
}
}
Loading