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

simplified some assertions by using #containsExactly #68

Merged
merged 1 commit into from
Feb 18, 2016
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
Expand Up @@ -245,8 +245,7 @@ public void testConvertShouldReturnOneElementForObjectArrayArrayWithOneElement()
List<Object[]> result = underTest.convert(data, false, parameterTypes, dataProvider);

// Then:
assertThat(result).hasSize(1);
assertThat(result.get(0)).isEqualTo(data[0]);
assertThat(result).containsExactly(data[0]);
}

@Test
Expand All @@ -259,10 +258,7 @@ public void testConvertShouldReturnMultipleElementsForObjectArrayArrayWithMultip
List<Object[]> result = underTest.convert(data, false, parameterTypes, dataProvider);

// Then:
assertThat(result).hasSize(3);
assertThat(result.get(0)).isEqualTo(data[0]);
assertThat(result.get(1)).isEqualTo(data[1]);
assertThat(result.get(2)).isEqualTo(data[2]);
assertThat(result).containsExactly(data[0], data[1], data[2]);
}

@Test
Expand All @@ -276,8 +272,7 @@ public void testConvertShouldReturnOneElementForListOfListOfObjectWithOneElement
List<Object[]> result = underTest.convert(data, false, parameterTypes, dataProvider);

// Then:
assertThat(result).hasSize(1);
assertThat(result.get(0)).isEqualTo(data.get(0).toArray());
assertThat(result).containsExactly(data.get(0).toArray());
}

@Test
Expand All @@ -291,10 +286,7 @@ public void testConvertShouldReturnMultipleElementsForListOfListOfObjectWithMult
List<Object[]> result = underTest.convert(data, false, parameterTypes, dataProvider);

// Then:
assertThat(result).hasSize(3);
assertThat(result.get(0)).isEqualTo(data.get(0).toArray());
assertThat(result.get(1)).isEqualTo(data.get(1).toArray());
assertThat(result.get(2)).isEqualTo(data.get(2).toArray());
assertThat(result).containsExactly(data.get(0).toArray(), data.get(1).toArray(), data.get(2).toArray());
}

@Test(expected = IllegalArgumentException.class)
Expand Down Expand Up @@ -323,8 +315,7 @@ public void testConvertShouldReturnOneElementForStringArrayWithOneElementSplitBy
List<Object[]> result = underTest.convert(data, false, parameterTypes, dataProvider);

// Then:
assertThat(result).hasSize(1);
assertThat(result.get(0)).isEqualTo(new Object[] { "foo", true });
assertThat(result).containsExactly(new Object[] { "foo", true });
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe we cloud use a helper for creating the array instead of using new Object[] { ... } over and over.
Do you also think that it would be better for the test cases above to write down the data explicitly instead of reusing the test data somehow?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm a fan of creating helper methods for tests. So if it's possible to come up with a descriptive method name I'm for adding it. Maybe something like assertContainsOnlyObjectArrayWithValues(List, values...)?

I agree that it would be better to write down the data explicitly in the test above.

}

@Test
Expand All @@ -339,8 +330,7 @@ public void testConvertShouldReturnOneElementForStringArrayWithOneElementSplitBy
List<Object[]> result = underTest.convert(data, false, parameterTypes, dataProvider);

// Then:
assertThat(result).hasSize(1);
assertThat(result.get(0)).isEqualTo(new Object[] { "bar", false });
assertThat(result).containsExactly(new Object[] { "bar", false });
}

@Test
Expand All @@ -355,8 +345,7 @@ public void testConvertShouldReturnOneElementForStringArrayWithOneElementSplitBy
List<Object[]> result = underTest.convert(data, false, parameterTypes, dataProvider);

// Then:
assertThat(result).hasSize(1);
assertThat(result.get(0)).isEqualTo(new Object[] { "baz", 2 });
assertThat(result).containsExactly(new Object[] { "baz", 2 });
}

@Test
Expand All @@ -372,9 +361,7 @@ public void testConvertShouldReturnMultipleElementsForStringArrayWithMultipleEle
List<Object[]> result = underTest.convert(data, false, parameterTypes, dataProvider);

// Then:
assertThat(result).hasSize(2);
assertThat(result.get(0)).isEqualTo(new Object[] { (byte) 1, 2, 3l, 4.0, 'e' });
assertThat(result.get(1)).isEqualTo(new Object[] { (byte) 6, 7, 8l, 9.0, 'i' });
assertThat(result).containsExactly(new Object[] { (byte) 1, 2, 3l, 4.0, 'e' }, new Object[] { (byte) 6, 7, 8l, 9.0, 'i' });
}

// -- methods used as Method objects -------------------------------------------------------------------------------
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public void testConvertShouldCreateEmptyVarargsArrayForMissingOnlyVarargsArgumen
Object[] result = underTest.convert(data, true, parameterTypes);

// Then:
assertThat(result).isEqualTo(new Object[] { new int[0] });
assertThat(result).containsExactly(new int[0]);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here I really prefer the isEqualTo to check for the Object[] which is wrapping the real result. This is in my humble opinion clearer. Though, this is just a gut feeling ...

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I more or less did a mechanical replacement. I agree, if the Object[] is the focus of these test it's better not to hide that. So either revert or use a helper method with an intention revealing name, maybe something like assertIsObjectArrayWithValues(result, values...).

Of course it up to you, as it's your project. 😄

}

@Test
Expand All @@ -51,7 +51,7 @@ public void testConvertShouldCreateEmptyVarargsArrayForLastMissingVarargsArgumen
Object[] result = underTest.convert(data, true, parameterTypes);

// Then:
assertThat(result).isEqualTo(new Object[] { "test", new int[0] });
assertThat(result).containsExactly("test", new int[0]);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same here

}

@Test
Expand All @@ -64,7 +64,7 @@ public void testConvertShouldCreateVarargsArrayForOneOnlyVarargsArguments() {
Object[] result = underTest.convert(data, true, parameterTypes);

// Then:
assertThat(result).isEqualTo(new Object[] { new double[] { 1.0 } });
assertThat(result).containsExactly(new double[] { 1.0 });
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

and here

}

@Test
Expand All @@ -77,7 +77,7 @@ public void testConvertShouldCreateVarargsArrayForOneLastVarargsArguments() {
Object[] result = underTest.convert(data, true, parameterTypes);

// Then:
assertThat(result).isEqualTo(new Object[] { 'a', (byte) 2, new double[] { 1.0 } });
assertThat(result).containsExactly('a', (byte) 2, new double[] { 1.0 });
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

here

}

@Test
Expand All @@ -90,7 +90,7 @@ public void testConvertShouldCreateVarargsArrayForMultipleOnlyVarargsArguments()
Object[] result = underTest.convert(data, true, parameterTypes);

// Then:
assertThat(result).isEqualTo(new Object[] { new long[] { 1, 2, 3 } });
assertThat(result).containsExactly(new long[] { 1, 2, 3 });
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

as well as here

}

@Test
Expand All @@ -103,7 +103,7 @@ public void testConvertShouldCreateVarargsArrayForMultipleLastVarargsArguments()
Object[] result = underTest.convert(data, true, parameterTypes);

// Then:
assertThat(result).isEqualTo(new Object[] { "foobar", new long[] { 1, 2, 3 } });
assertThat(result).containsExactly("foobar", new long[] { 1, 2, 3 });
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

and here ...

}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ public void testConvertShouldCorrectlyParseAllPrimitiveTypes() {
Object[] result = underTest.convert(data, false, parameterTypes, dataProvider, 10);

// Then:
assertThat(result).isEqualTo(new Object[] { true, (byte) 1, 'c', (short) 2, 3, 4L, 5.5f, 6.6d });
assertThat(result).containsExactly(true, (byte) 1, 'c', (short) 2, 3, 4L, 5.5f, 6.6d);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

here

}

@Test
Expand All @@ -96,7 +96,7 @@ public void testConvertShouldCorrectlyParseAllPrimitiveTypesAsJavaString() {
Object[] result = underTest.convert(data, false, parameterTypes, dataProvider, 11);

// Then:
assertThat(result).isEqualTo(new Object[] { -5, 2014l, -1.234567f, -0.901d });
assertThat(result).containsExactly(-5, 2014l, -1.234567f, -0.901d);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

here

}

@Test
Expand All @@ -111,7 +111,7 @@ public void testConvertShouldNotTrimValuesIfSettingsTrimIsFalse() {
Object[] result = underTest.convert(data, false, parameterTypes, dataProvider, 12);

// Then:
assertThat(result).isEqualTo(new Object[] { " foo", " bar ", "baz " });
assertThat(result).containsExactly(" foo", " bar ", "baz ");
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

here

}

@Test
Expand All @@ -128,7 +128,7 @@ public void testConvertShouldTrimAndParseAllPrimitiveTypesIfSettingsTrimIsTrue()
Object[] result = underTest.convert(data, false, parameterTypes, dataProvider, 13);

// Then:
assertThat(result).isEqualTo(new Object[] { false, (byte) 11, 'z', (short) 22, 33, 44L, 55.55f, 66.66d });
assertThat(result).containsExactly(false, (byte) 11, 'z', (short) 22, 33, 44L, 55.55f, 66.66d);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

and also here because it is really about the Object[]

}

@Test
Expand All @@ -144,7 +144,7 @@ public void testConvertShouldTrimNonSpaceWhitespaceCharsIfSettingsTrimIsTrue() {
Object[] result = underTest.convert(data, false, parameterTypes, dataProvider, 20);

// Then:
assertThat(result).isEqualTo(new Object[] { -1f, -2, 3d });
assertThat(result).containsExactly(-1f, -2, 3d);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

and here

}

@Test
Expand All @@ -160,7 +160,7 @@ public void testConvertShouldNotTrimNonBreakingSpaceEvenIfSettingsTrimIsTrue() {
Object[] result = underTest.convert(data, false, parameterTypes, dataProvider, 21);

// Then:
assertThat(result).isEqualTo(new Object[] { "\u00A0test\u00A0" });
assertThat(result).containsExactly("\u00A0test\u00A0");
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

here

}

@Test
Expand All @@ -176,7 +176,7 @@ public void testConvertShouldCorrectlyHandleLeadingEmptyString() {
Object[] result = underTest.convert(data, false, parameterTypes, dataProvider, 30);

// Then:
assertThat(result).isEqualTo(new Object[] { "", true });
assertThat(result).containsExactly("", true);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

here

}

@Test
Expand All @@ -192,7 +192,7 @@ public void testConvertShouldCorrectlyHandleTrailingEmptyString() {
Object[] result = underTest.convert(data, false, parameterTypes, dataProvider, 31);

// Then:
assertThat(result).isEqualTo(new Object[] { 1, "" });
assertThat(result).containsExactly(1, "");
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

here

}

@Test(expected = IllegalArgumentException.class)
Expand Down Expand Up @@ -264,7 +264,7 @@ public void testConvertShouldCorrectlyParseEnum() {
Object[] result = underTest.convert(data, false, parameterTypes, dataProvider, 50);

// Then:
assertThat(result).isEqualTo(new Object[] { TestEnum.VAL1, TestEnum.VAL2 });
assertThat(result).containsExactly(TestEnum.VAL1, TestEnum.VAL2);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

here

}

@Test(expected = IllegalArgumentException.class)
Expand Down Expand Up @@ -292,7 +292,7 @@ public void testConvertShouldCorrectlyParseEnumIgnoringCase() {
Object[] result = underTest.convert(data, false, parameterTypes, dataProvider, 50);

// Then:
assertThat(result).isEqualTo(new Object[] { TestEnum.VAL1, TestEnum.VAL2 });
assertThat(result).containsExactly(TestEnum.VAL1, TestEnum.VAL2);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

here

}

@Test(expected = IllegalArgumentException.class)
Expand Down Expand Up @@ -322,7 +322,7 @@ public void testConvertShouldCorrectlyParseClass() {
Object[] result = underTest.convert(data, false, parameterTypes, dataProvider, 50);

// Then:
assertThat(result).isEqualTo(new Object[] { Thread.class, DataProviderRunner.class });
assertThat(result).containsExactly(Thread.class, DataProviderRunner.class);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

here

}

@Test(expected = IllegalArgumentException.class)
Expand Down Expand Up @@ -352,9 +352,9 @@ public void testConvertShouldCorrectlyParseAllPrimitiveWrapperTypes() {
Object[] result = underTest.convert(data, false, parameterTypes, dataProvider, 60);

// Then:
assertThat(result).isEqualTo(
new Object[] { Boolean.TRUE, Byte.valueOf((byte) 1), Character.valueOf('c'), Short.valueOf((short) 2),
Integer.valueOf(3), Long.valueOf(4L), Float.valueOf(5.5f), Double.valueOf(6.6d) });
assertThat(result).containsExactly(
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

everywhere here

Boolean.TRUE, Byte.valueOf((byte) 1), Character.valueOf('c'), Short.valueOf((short) 2),
Integer.valueOf(3), Long.valueOf(4L), Float.valueOf(5.5f), Double.valueOf(6.6d));
}

@Test
Expand All @@ -369,7 +369,7 @@ public void testConvertShouldParseNullValuesAsStringIfSettingsConvertNullsIsFals
Object[] result = underTest.convert(data, false, parameterTypes, dataProvider, 70);

// Then:
assertThat(result).isEqualTo(new Object[] { "null", "null" });
assertThat(result).containsExactly("null", "null");
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

and so on ...

}

@Test
Expand All @@ -385,7 +385,7 @@ public void testConvertShouldParseNullValuesAsNullObjectIfSettingsConvertNullsIs
Object[] result = underTest.convert(data, false, parameterTypes, dataProvider, 71);

// Then:
assertThat(result).isEqualTo(new Object[] { null, null, "foo" });
assertThat(result).containsExactly(null, null, "foo");
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

here, but maybe you have a reason why this does not matter or why my gut feeling maybe betray me ...
I am open minded and this at least looks shorter ... looking forward to your answer/comment

}

@Test
Expand All @@ -400,7 +400,7 @@ public void testConvertShouldCorrectlyUseConstructorWithSingleStringArgForBigInt
Object[] result = underTest.convert(data, false, parameterTypes, dataProvider, 80);

// Then:
assertThat(result).isEqualTo(new Object[] { BigInteger.valueOf(1) });
assertThat(result).containsExactly(BigInteger.ONE);
}

@Test
Expand All @@ -415,7 +415,7 @@ public void testConvertShouldCorrectlyUseConstructorWithSingleStringArgForFile()
Object[] result = underTest.convert(data, false, parameterTypes, dataProvider, 80);

// Then:
assertThat(result).isEqualTo(new Object[] { new File("home/schmida") });
assertThat(result).containsExactly(new File("home/schmida"));
}

@Test
Expand All @@ -430,7 +430,7 @@ public void testConvertShouldCreateEmptyVarargsArrayForMissingOnlyVarargsArgumen
Object[] result = underTest.convert(data, true, parameterTypes, dataProvider, 90);

// Then:
assertThat(result).isEqualTo(new Object[] { new int[0] });
assertThat(result).containsExactly(new int[0]);
}

@Test
Expand All @@ -445,7 +445,7 @@ public void testConvertShouldCreateEmptyVarargsArrayForLastMissingVarargsArgumen
Object[] result = underTest.convert(data, true, parameterTypes, dataProvider, 91);

// Then:
assertThat(result).isEqualTo(new Object[] { "test", new int[0] });
assertThat(result).containsExactly("test", new int[0]);
}

@Test
Expand All @@ -460,7 +460,7 @@ public void testConvertShouldCreateVarargsArrayForOneOnlyVarargsArguments() {
Object[] result = underTest.convert(data, true, parameterTypes, dataProvider, 92);

// Then:
assertThat(result).isEqualTo(new Object[] { new double[] { 1.0 } });
assertThat(result).containsExactly(new double[] { 1.0 });
}

@Test
Expand All @@ -476,7 +476,7 @@ public void testConvertShouldCreateVarargsArrayForOneLastVarargsArguments() {
Object[] result = underTest.convert(data, true, parameterTypes, dataProvider, 93);

// Then:
assertThat(result).isEqualTo(new Object[] { 'a', (byte) 2, new Double[] { 1.0, null } });
assertThat(result).containsExactly('a', (byte) 2, new Double[] { 1.0, null });
}

@Test
Expand All @@ -492,7 +492,7 @@ public void testConvertShouldCreateVarargsArrayForMultipleOnlyVarargsArguments()
Object[] result = underTest.convert(data, true, parameterTypes, dataProvider, 94);

// Then:
assertThat(result).isEqualTo(new Object[] { new long[] { 1, 2, 3 } });
assertThat(result).containsExactly(new long[] { 1, 2, 3 });
}

@Test
Expand All @@ -508,7 +508,7 @@ public void testConvertShouldCreateVarargsArrayForMultipleLastVarargsArguments()
Object[] result = underTest.convert(data, true, parameterTypes, dataProvider, 95);

// Then:
assertThat(result).isEqualTo(new Object[] { "foobar", new long[] { 1, 2, 3 } });
assertThat(result).containsExactly("foobar", new long[] { 1, 2, 3 });
}

@Test
Expand All @@ -523,6 +523,6 @@ public void testConvertShouldNotSplitIfSingleNonVarargArgumentIsRequired() {
Object[] result = underTest.convert(data, false, parameterTypes, dataProvider, 100);

// Then:
assertThat(result).isEqualTo(new Object[] { TestEnum.VAL1 });
assertThat(result).containsExactly(TestEnum.VAL1);
}
}