assertThat(message.l10nParams()[0]).isEqualTo("10");
}
+
@Test
- public void test_text_message() {
+ public void test_toString() {
String errorMessage = "the error";
- Result.Message txtMessage = Result.Message.of(errorMessage);
- Result.Message sameMessage = Result.Message.of(errorMessage);
- Result.Message otherMessage = Result.Message.of("other");
-
- assertThat(txtMessage.toString()).contains(errorMessage);
- assertThat(txtMessage).isEqualTo(txtMessage);
- assertThat(txtMessage).isEqualTo(sameMessage);
- assertThat(txtMessage.hashCode()).isEqualTo(txtMessage.hashCode());
- assertThat(txtMessage.hashCode()).isEqualTo(sameMessage.hashCode());
- assertThat(txtMessage).isNotEqualTo(otherMessage);
+ Result.Message txtMsg = Result.Message.of(errorMessage);
+ assertThat(txtMsg.toString()).contains(errorMessage);
+ assertThat(txtMsg.toString()).isNotEqualTo(errorMessage);
+
+ Result.Message msg = Result.Message.ofL10n("issue.error.123", "10");
+ assertThat(msg.toString()).contains("issue.error.123").contains("10");
+ assertThat(msg.toString()).isNotEqualTo("issue.error.123");
}
@Test
- public void test_l10n_message() {
+ public void test_equals_and_hashCode() {
+ String errorMessage = "the error";
+ Result.Message txtMsg = Result.Message.of(errorMessage);
+ Result.Message sameTxtMsg = Result.Message.of(errorMessage);
+ Result.Message otherTxtMessage = Result.Message.of("other");
+
+ assertThat(txtMsg)
+ .isEqualTo(txtMsg)
+ .isEqualTo(sameTxtMsg)
+ .isNotEqualTo(otherTxtMessage);
+
Result.Message msg = Result.Message.ofL10n("issue.error.123", "10");
Result.Message sameMsg = Result.Message.ofL10n("issue.error.123", "10");
- Result.Message msg2 = Result.Message.ofL10n("issue.error.123", "200");
- Result.Message msg3 = Result.Message.ofL10n("issue.error.50");
+ Result.Message otherMsg1 = Result.Message.ofL10n("issue.error.123", "200");
+ Result.Message otherMsg2 = Result.Message.ofL10n("issue.error.50");
- assertThat(msg.toString()).contains("issue.error.123").contains("10");
- assertThat(msg).isEqualTo(msg);
- assertThat(msg).isEqualTo(sameMsg);
- assertThat(msg.hashCode()).isEqualTo(msg.hashCode());
- assertThat(msg.hashCode()).isEqualTo(sameMsg.hashCode());
-
- assertThat(msg).isNotEqualTo(msg2);
- assertThat(msg).isNotEqualTo(msg3);
- assertThat(msg.text()).isNotEqualTo("issue.error.123");
+ assertThat(msg)
+ .isEqualTo(msg)
+ .isEqualTo(sameMsg)
+ .isNotEqualTo(otherMsg1)
+ .isNotEqualTo(otherMsg2)
+ .hasSameHashCodeAs(msg)
+ .hasSameHashCodeAs(sameMsg);
+ assertThat(msg.hashCode()).isNotEqualTo(otherMsg1.hashCode());
}
}
*/
package org.sonar.api.batch.scm;
+import java.util.Calendar;
import org.junit.Test;
import java.util.Date;
public class BlameLineTest {
@Test
- public void testEqualBlameLine() {
+ public void testBlameLine() {
Date date = new Date();
BlameLine line1 = new BlameLine().date(date).revision("1").author("foo");
- BlameLine line1b = new BlameLine().date(date).revision("1").author("foo");
- BlameLine line2 = new BlameLine().date(null).revision("2").author("foo2");
assertThat(line1.author()).isEqualTo("foo");
assertThat(line1.date()).isEqualTo(date);
assertThat(line1.revision()).isEqualTo("1");
+ assertThat(line1.toString()).isNotEqualTo("foo");
+ assertThat(line1.toString()).contains("revision=1,author=foo");
+ }
- Assertions.assertEquals(line1, line1);
- assertThat(line1).isNotEqualTo(null);
- assertThat(line1).isEqualTo(line1b);
- assertThat(line1.hashCode()).isEqualTo(line1b.hashCode());
- assertThat(line1).isNotEqualTo(line2);
+ @Test
+ public void test_equals_and_hashCode() {
+ Date date = new Date();
+ BlameLine line1 = new BlameLine().date(date).revision("1").author("foo");
+ BlameLine line2 = new BlameLine().date(date).revision("1").author("foo");
+ BlameLine line3 = new BlameLine().date(null).revision("1").author("bar");
+ BlameLine line4 = new BlameLine().date(date).revision("2").author("foo");
+ BlameLine line5 = new BlameLine().date(date).revision("1").author("bar");
- assertThat(line1.toString()).contains("revision=1,author=foo");
+ assertThat(line1)
+ .isEqualTo(line1)
+ .isNotEqualTo(null)
+ .isEqualTo(line2)
+ .isNotEqualTo(line3)
+ .hasSameHashCodeAs(line2);
+ assertThat(line1.hashCode()).isNotEqualTo(line3.hashCode());
+ assertThat(line1.hashCode()).isNotEqualTo(line4.hashCode());
+ assertThat(line1.hashCode()).isNotEqualTo(line5.hashCode());
}
@Test
assertThat(line2.author()).isNull();
assertThat(line3.author()).isEqualTo("foo3");
}
-
}
assertThat(ab).isGreaterThan(aa);
assertThat(aa).isLessThan(ab);
- assertThat(aa).isNotEqualTo(ab);
- assertThat(ab).isNotEqualTo(aa);
- assertThat(aa).isEqualTo(aa);
- assertThat(ab).isEqualTo(ab);
}
}
profile2.done();
NewBuiltInQualityProfile profile3 = c.createBuiltInQualityProfile("Foo1", "xoo2");
profile3.done();
- Assertions.assertEquals(profile1, profile1);
- assertThat(profile1).isNotEqualTo(null);
- assertThat(profile1.name()).isNotEqualTo("Foo");
+
+ assertThat(profile1).isNotNull();
assertThat(profile1).isNotEqualTo(profile2);
assertThat(profile1).isNotEqualTo(profile3);
+
assertThat(profile1.hashCode()).isNotEqualTo(profile2.hashCode());
- assertThat(profile1.toString()).isEqualTo("NewBuiltInQualityProfile{name='Foo1', language='xoo', default='false'}");
- assertThat(rule.toString()).isEqualTo("[repository=repo, key=rule]");
+
+ assertThat(profile1.name()).isNotEqualTo("Foo");
+ assertThat(profile1.toString()).hasToString("NewBuiltInQualityProfile{name='Foo1', language='xoo', default='false'}");
+ assertThat(rule.toString()).hasToString("[repository=repo, key=rule]");
});
+
BuiltInQualityProfile profile1 = profiles.get("xoo").get("Foo1");
BuiltInQualityProfile profile2 = profiles.get("xoo").get("Foo2");
BuiltInQualityProfile profile3 = profiles.get("xoo2").get("Foo1");
- assertThat(profile1).isEqualTo(profile1);
- assertThat(profile1).isNotEqualTo(null);
- assertThat(profile1.name()).isNotEqualTo("Foo");
- assertThat(profile1).isNotEqualTo(profile2);
- assertThat(profile1).isNotEqualTo(profile3);
+
+ assertThat(profile1)
+ .isNotNull()
+ .isNotEqualTo(profile2)
+ .isNotEqualTo(profile3);
assertThat(profile1.hashCode()).isNotEqualTo(profile2.hashCode());
- assertThat(profile1.toString()).isEqualTo("BuiltInQualityProfile{name='Foo1', language='xoo', default='false'}");
- assertThat(profile1.rule(RuleKey.of("repo", "rule")).toString()).isEqualTo("[repository=repo, key=rule]");
+
+ assertThat(profile1.name()).isNotEqualTo("Foo");
+ assertThat(profile1.toString()).hasToString("BuiltInQualityProfile{name='Foo1', language='xoo', default='false'}");
+ assertThat(profile1.rule(RuleKey.of("repo", "rule")).toString()).hasToString("[repository=repo, key=rule]");
}
@Test
import org.sonar.api.impl.server.RulesDefinitionContext;
import static org.assertj.core.api.Assertions.assertThat;
+import static org.assertj.core.api.Assertions.useDefaultDateFormatsOnly;
import static org.junit.Assert.fail;
import static org.junit.jupiter.api.Assertions.assertEquals;
assertThat(checkstyle.name()).isEqualTo("checkstyle");
assertThat(checkstyle.rules()).isEmpty();
assertThat(context.repository("unknown")).isNull();
-
- // test equals() and hashCode()
- assertThat(findbugs).isEqualTo(findbugs).isNotEqualTo(checkstyle).isNotEqualTo("findbugs").isNotEqualTo(null);
- assertThat(findbugs.hashCode()).isEqualTo(findbugs.hashCode());
}
@Test
assertThat(repo.isExternal()).isFalse();
RulesDefinition.Rule rule = repo.rule("NPE");
+ assertThat(rule).isNotNull();
assertThat(rule.scope()).isEqualTo(RuleScope.ALL);
assertThat(rule.key()).isEqualTo("NPE");
assertThat(rule.name()).isEqualTo("Detect NPE");
assertThat(rule.internalKey()).isEqualTo("/something");
assertThat(rule.template()).isFalse();
assertThat(rule.status()).isEqualTo(RuleStatus.BETA);
- assertThat(rule.toString()).isEqualTo("[repository=findbugs, key=NPE]");
+ assertThat(rule.toString()).hasToString("[repository=findbugs, key=NPE]");
assertThat(rule.repository()).isSameAs(repo);
RulesDefinition.Rule otherRule = repo.rule("ABC");
assertThat(repo.isExternal()).isTrue();
RulesDefinition.Rule rule = repo.rule("NPE");
+ assertThat(rule).isNotNull();
assertThat(rule.scope()).isEqualTo(RuleScope.ALL);
assertThat(rule.key()).isEqualTo("NPE");
assertThat(rule.name()).isEqualTo("Detect NPE");
assertThat(rule.internalKey()).isEqualTo("/something");
assertThat(rule.template()).isFalse();
assertThat(rule.status()).isEqualTo(RuleStatus.BETA);
- assertThat(rule.toString()).isEqualTo("[repository=external_eslint, key=NPE]");
+ assertThat(rule.toString()).hasToString("[repository=external_eslint, key=NPE]");
assertThat(rule.repository()).isSameAs(repo);
RulesDefinition.Rule otherRule = repo.rule("ABC");
assertThat(rule.params()).hasSize(2);
RulesDefinition.Param level = rule.param("level");
+ assertThat(level).isNotNull();
assertThat(level.key()).isEqualTo("level");
assertThat(level.name()).isEqualTo("Level");
assertThat(level.description()).isEqualTo("The level");
assertThat(effort.description()).isNull();
assertThat(effort.defaultValue()).isNull();
assertThat(effort.type()).isEqualTo(RuleParamType.STRING);
-
- // test equals() and hashCode()
- assertThat(level).isEqualTo(level).isNotEqualTo(effort).isNotEqualTo("level").isNotEqualTo(null);
- assertThat(level.hashCode()).isEqualTo(level.hashCode());
}
@Test
@DataProvider
public static Object[][] nullOrEmpty() {
- return new Object[][] {
+ return new Object[][]{
{null},
{""}
};