-
Notifications
You must be signed in to change notification settings - Fork 2
/
ParameterizedWineNameTests.java
76 lines (61 loc) · 2.33 KB
/
ParameterizedWineNameTests.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
package com.designatednerd.wino.model;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.Parameterized;
import java.util.Arrays;
import static org.junit.Assert.assertEquals;
/**
* An example of a parameterized test which runs the same test function over and over with
* different data.
*/
@RunWith(Parameterized.class)
public class ParameterizedWineNameTests {
/*******************
* PARAMETER SETUP *
*******************/
/**
* Create an iterable of object arrays that can be handed over to the test
* as parameters to the constructor.
*
* For example, here we have a constructor that takes 4 items: The wine name,
* the vineyard name, the varietal name, and the expected output string. Each
* of these arrays of strings will be passed in to the constructor in that order.
*/
@Parameterized.Parameters
public static Iterable<Object[]> data() {
return Arrays.asList(new Object[][]{
{"Wine", "Vineyard", "Varietal", "Wine (Varietal, Vineyard)"}, //All info
{"Wine", "Vineyard", null, "Wine (Vineyard)"}, //Missing varietal
{"Wine", null, "Varietal", "Wine (Varietal)"}, //Missing vineyard
{"Wine", null, null, "Wine"}, //Wine Only
{null, null, null, ""} //No info at all
});
}
/*************
* VARIABLES *
*************/
private String mWineName;
private String mVineyardName;
private String mVarietalName;
private String mExpectedFormattedOutput;
/***************
* CONSTRUCTOR *
***************/
public ParameterizedWineNameTests(String aWineName,
String aVineyardName,
String aVarietalName,
String aExpectedFormattedOutput) {
mWineName = aWineName;
mVineyardName = aVineyardName;
mVarietalName = aVarietalName;
mExpectedFormattedOutput = aExpectedFormattedOutput;
}
/***********************
* PARAMETERIZED TESTS *
***********************/
@Test
public void testFormattingWineName() {
String formatted = WineTasting.wineNameFromInfo(mWineName, mVineyardName, mVarietalName);
assertEquals(mExpectedFormattedOutput, formatted);
}
}