Skip to content

Commit

Permalink
Gh-276: AssertJ withFailMessage order fix (#277)
Browse files Browse the repository at this point in the history
* Fix order of withFailMessage so it is never last

* Copyright Update
  • Loading branch information
GCHQDeveloper314 authored May 26, 2022
1 parent d1951a0 commit 12fef1b
Show file tree
Hide file tree
Showing 8 changed files with 53 additions and 54 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2017-2021 Crown Copyright
* Copyright 2017-2022 Crown Copyright
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -17,7 +17,6 @@
package uk.gov.gchq.koryphe.binaryoperator;

import org.junit.jupiter.api.Test;

import uk.gov.gchq.koryphe.Since;
import uk.gov.gchq.koryphe.Summary;
import uk.gov.gchq.koryphe.util.EqualityTest;
Expand Down Expand Up @@ -66,14 +65,14 @@ public void shouldHaveSinceAnnotation() {

// Then
assertThat(annotation)
.isNotNull()
.withFailMessage("Missing Since annotation on class %s", instance.getClass().getName());
.withFailMessage("Missing Since annotation on class %s", instance.getClass().getName())
.isNotNull();
assertThat(annotation.value())
.isNotNull()
.withFailMessage("Missing Since annotation on class %s", instance.getClass().getName());
.withFailMessage("Missing Since annotation on class %s", instance.getClass().getName())
.isNotNull();
assertThat(VersionUtil.validateVersionString(annotation.value()))
.isTrue()
.withFailMessage("%s is not a valid value string.", annotation.value());
.withFailMessage("%s is not a valid value string.", annotation.value())
.isTrue();
}

@Test
Expand All @@ -86,13 +85,13 @@ public void shouldHaveSummaryAnnotation() {

// Then
assertThat(annotation)
.isNotNull()
.withFailMessage("Missing Summary annotation on class %s", instance.getClass().getName());
.withFailMessage("Missing Summary annotation on class %s", instance.getClass().getName())
.isNotNull();
assertThat(annotation.value())
.isNotNull()
.withFailMessage("Missing Summary annotation on class %s", instance.getClass().getName());
.withFailMessage("Missing Summary annotation on class %s", instance.getClass().getName())
.isNotNull();
assertThat(SummaryUtil.validateSummaryString(annotation.value()))
.isTrue()
.withFailMessage("%s is not a valid value string.", annotation.value());
.withFailMessage("%s is not a valid value string.", annotation.value())
.isTrue();
}
}
24 changes: 12 additions & 12 deletions core/src/test/java/uk/gov/gchq/koryphe/function/FunctionTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -72,14 +72,14 @@ public void shouldHaveSinceAnnotation() {

// Then
assertThat(annotation)
.isNotNull()
.withFailMessage("Missing Since annotation on class %s", instance.getClass().getName());
.withFailMessage("Missing Since annotation on class %s", instance.getClass().getName())
.isNotNull();
assertThat(annotation.value())
.isNotNull()
.withFailMessage("Missing Since annotation on class %s", instance.getClass().getName());
.withFailMessage("Missing Since annotation on class %s", instance.getClass().getName())
.isNotNull();
assertThat(VersionUtil.validateVersionString(annotation.value()))
.isTrue()
.withFailMessage("%s is not a valid value string.", annotation.value());
.withFailMessage("%s is not a valid value string.", annotation.value())
.isTrue();
}

@Test
Expand All @@ -92,14 +92,14 @@ public void shouldHaveSummaryAnnotation() {

// Then
assertThat(annotation)
.isNotNull()
.withFailMessage("Missing Summary annotation on class %s", instance.getClass().getName());
.withFailMessage("Missing Summary annotation on class %s", instance.getClass().getName())
.isNotNull();
assertThat(annotation.value())
.isNotNull()
.withFailMessage("Missing Summary annotation on class %s", instance.getClass().getName());
.withFailMessage("Missing Summary annotation on class %s", instance.getClass().getName())
.isNotNull();
assertThat(SummaryUtil.validateSummaryString(annotation.value()))
.isTrue()
.withFailMessage("%s is not a valid value string.", annotation.value());
.withFailMessage("%s is not a valid value string.", annotation.value())
.isTrue();
}

@Test
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2017-2020 Crown Copyright
* Copyright 2017-2022 Crown Copyright
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -590,8 +590,8 @@ protected void testValues(final boolean expectedResult, final List<Tuple2<Long,
// Then
for (int i = 0; i < values.size(); i++) {
assertThat(results.get(i))
.isEqualTo(expectedResult)
.withFailMessage("Failed for value: %s", values.get(i));
.withFailMessage("Failed for value: %s", values.get(i))
.isEqualTo(expectedResult);
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2017-2020 Crown Copyright
* Copyright 2017-2022 Crown Copyright
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -632,8 +632,8 @@ protected void testValues(final boolean expectedResult, final List<Long> values,
// Then
for (int i = 0; i < values.size(); i++) {
assertThat(results.get(i))
.isEqualTo(expectedResult)
.withFailMessage("Failed for value: %s", values.get(i));
.withFailMessage("Failed for value: %s", values.get(i))
.isEqualTo(expectedResult);
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2017-2020 Crown Copyright
* Copyright 2017-2022 Crown Copyright
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -454,8 +454,8 @@ protected void testValues(final boolean expectedResult, final List<Tuple2<Long,
// Then
for (int i = 0; i < values.size(); i++) {
assertThat(results.get(i))
.isEqualTo(expectedResult)
.withFailMessage("Failed for value: %s", values.get(i));
.withFailMessage("Failed for value: %s", values.get(i))
.isEqualTo(expectedResult);
}
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2017-2020 Crown Copyright
* Copyright 2017-2022 Crown Copyright
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -237,8 +237,8 @@ protected void testValues(final boolean expectedResult, final List<Long> values,
// Then
for (int i = 0; i < values.size(); i++) {
assertThat(results.get(i))
.isEqualTo(expectedResult)
.withFailMessage("Failed for value: %s", values.get(i));
.withFailMessage("Failed for value: %s", values.get(i))
.isEqualTo(expectedResult);
}
}
}
26 changes: 13 additions & 13 deletions core/src/test/java/uk/gov/gchq/koryphe/predicate/PredicateTest.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2017-2021 Crown Copyright
* Copyright 2017-2022 Crown Copyright
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -57,14 +57,14 @@ public void shouldHaveSinceAnnotation() {

// Then
assertThat(annotation)
.isNotNull()
.withFailMessage("Missing Since annotation on class %s", instance.getClass().getName());
.withFailMessage("Missing Since annotation on class %s", instance.getClass().getName())
.isNotNull();
assertThat(annotation)
.isNotNull()
.withFailMessage("Missing Since annotation on class %s", instance.getClass().getName());
.withFailMessage("Missing Since annotation on class %s", instance.getClass().getName())
.isNotNull();
assertThat(VersionUtil.validateVersionString(annotation.value()))
.isTrue()
.withFailMessage("%s is not a valid value string.", annotation.value());
.withFailMessage("%s is not a valid value string.", annotation.value())
.isTrue();
}

@Test
Expand All @@ -77,13 +77,13 @@ public void shouldHaveSummaryAnnotation() {

// Then
assertThat(annotation)
.isNotNull()
.withFailMessage("Missing Summary annotation on class %s", instance.getClass().getName());
.withFailMessage("Missing Summary annotation on class %s", instance.getClass().getName())
.isNotNull();
assertThat(annotation)
.isNotNull()
.withFailMessage("Missing Summary annotation on class %s", instance.getClass().getName());
.withFailMessage("Missing Summary annotation on class %s", instance.getClass().getName())
.isNotNull();
assertThat(SummaryUtil.validateSummaryString(annotation.value()))
.isTrue()
.withFailMessage("%s is not a valid value string.", annotation.value());
.withFailMessage("%s is not a valid value string.", annotation.value())
.isTrue();
}
}
6 changes: 3 additions & 3 deletions core/src/test/java/uk/gov/gchq/koryphe/util/DateUtilTest.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2016-2020 Crown Copyright
* Copyright 2016-2022 Crown Copyright
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -104,7 +104,7 @@ public void shouldNotParseInvalidDate() {
private void assertDate(final String expected, final String testDate, final String format) throws ParseException {
final Date expectedDate = DateUtils.parseDate(expected, Locale.getDefault(), format);
assertThat(DateUtil.parse(testDate))
.isEqualTo(expectedDate)
.withFailMessage("Failed to parse date: %s", testDate);
.withFailMessage("Failed to parse date: %s", testDate)
.isEqualTo(expectedDate);
}
}

0 comments on commit 12fef1b

Please sign in to comment.