|
19 | 19 | public class StringConversionTest { |
20 | 20 |
|
21 | 21 | @Test |
22 | | - public void givenString_whenConvertedToint_thenCorrect() { |
23 | | - String str = "1"; |
24 | | - assertEquals(Integer.parseInt(str), 1); |
| 22 | + public void whenConvertedToint_thenCorrect() { |
| 23 | + assertEquals(Integer.parseInt("1"), 1); |
25 | 24 | } |
26 | 25 |
|
27 | 26 | @Test |
28 | | - public void givenString_whenConvertedToInteger_thenCorrect() { |
29 | | - String str = "12"; |
30 | | - Integer number = Integer.valueOf(str); |
31 | | - assertEquals(number.intValue(), 12); |
| 27 | + public void whenConvertedToInteger_thenCorrect() { |
| 28 | + assertEquals(Integer.valueOf("12").equals(12), true); |
32 | 29 | } |
33 | 30 |
|
34 | 31 | @Test |
35 | | - public void givenString_whenConvertedTolong_thenCorrect() { |
36 | | - String str = "12345"; |
37 | | - assertEquals(Long.parseLong(str), 12345); |
| 32 | + public void whenConvertedTolong_thenCorrect() { |
| 33 | + assertEquals(Long.parseLong("12345"), 12345); |
38 | 34 | } |
39 | 35 |
|
40 | 36 | @Test |
41 | | - public void givenString_whenConvertedToLong_thenCorrect() { |
42 | | - String str = "14567"; |
43 | | - Long number = Long.valueOf(str); |
44 | | - assertEquals(number.longValue(), 14567); |
| 37 | + public void whenConvertedToLong_thenCorrect() { |
| 38 | + assertEquals(Long.valueOf("14567").equals(14567L), true); |
45 | 39 | } |
46 | 40 |
|
47 | 41 | @Test |
48 | | - public void givenString_whenConvertedTodouble_thenCorrect() { |
49 | | - String str = "1.4"; |
50 | | - assertEquals(Double.parseDouble(str), 1.4, 0.0); |
| 42 | + public void whenConvertedTodouble_thenCorrect() { |
| 43 | + assertEquals(Double.parseDouble("1.4"), 1.4, 0.0); |
51 | 44 | } |
52 | 45 |
|
53 | 46 | @Test |
54 | | - public void givenString_whenConvertedToDouble_thenCorrect() { |
55 | | - String str = "145.67"; |
56 | | - Double number = Double.valueOf(str); |
57 | | - assertEquals(number.doubleValue(), 145.67, 0.0); |
| 47 | + public void whenConvertedToDouble_thenCorrect() { |
| 48 | + assertEquals(Double.valueOf("145.67").equals(145.67d), true); |
58 | 49 | } |
59 | 50 |
|
60 | 51 | @Test |
61 | | - public void givenString_whenConvertedToByteArray_thenCorrect() throws UnsupportedEncodingException { |
| 52 | + public void whenConvertedToByteArray_thenCorrect() throws UnsupportedEncodingException { |
62 | 53 | byte[] byteArray1 = new byte[] { 'a', 'b', 'c' }; |
63 | | - String str = new String(byteArray1, "UTF-8"); |
64 | | - assertEquals(Arrays.equals(str.getBytes(), byteArray1), true); |
| 54 | + String string = new String(byteArray1, "UTF-8"); |
| 55 | + |
| 56 | + assertEquals(Arrays.equals(string.getBytes(), byteArray1), true); |
65 | 57 | } |
66 | 58 |
|
67 | 59 | @Test |
68 | | - public void givenString_whenConvertedToboolean_thenCorrect() { |
69 | | - String str = "true"; |
70 | | - assertEquals(Boolean.parseBoolean(str), true); |
| 60 | + public void whenConvertedToboolean_thenCorrect() { |
| 61 | + assertEquals(Boolean.parseBoolean("true"), true); |
71 | 62 | } |
72 | 63 |
|
73 | 64 | @Test |
74 | | - public void givenString_whenConvertedToBoolean_thenCorrect() { |
75 | | - String str = "true"; |
76 | | - assertEquals(Boolean.valueOf(str), true); |
| 65 | + public void whenConvertedToBoolean_thenCorrect() { |
| 66 | + assertEquals(Boolean.valueOf("true"), true); |
77 | 67 | } |
78 | 68 |
|
79 | 69 | @Test |
80 | | - public void givenString_whenConvertedToCharArray_thenCorrect() { |
| 70 | + public void whenConvertedToCharArray_thenCorrect() { |
81 | 71 | String str = "hello"; |
82 | 72 | char[] charArray = { 'h', 'e', 'l', 'l', 'o' }; |
| 73 | + |
83 | 74 | assertEquals(Arrays.equals(charArray, str.toCharArray()), true); |
84 | 75 | } |
85 | 76 |
|
86 | 77 | @Test |
87 | | - public void givenString_whenConvertedToJava6Date_thenCorrect() throws ParseException { |
| 78 | + public void whenConvertedToJava6Date_thenCorrect() throws ParseException { |
88 | 79 | String str = "15/10/2013"; |
89 | 80 | SimpleDateFormat formatter = new SimpleDateFormat("dd/M/yyyy"); |
90 | 81 | Date date1 = formatter.parse(str); |
91 | 82 | Calendar calendar = new GregorianCalendar(2013, 9, 15); |
92 | 83 | Date date2 = calendar.getTime(); |
| 84 | + |
93 | 85 | assertEquals(date1.compareTo(date2), 0); |
94 | 86 | } |
95 | 87 |
|
96 | 88 | @Test |
97 | | - public void givenString_whenConvertedToJava8Date_thenCorrect() throws ParseException { |
| 89 | + public void whenConvertedToJava8Date_thenCorrect() throws ParseException { |
98 | 90 | String str = "2007-12-03T10:15:30"; |
99 | 91 | LocalDateTime localDateTime = new UseLocalDateTime().getLocalDateTimeUsingParseMethod(str); |
| 92 | + |
100 | 93 | assertEquals(localDateTime.getDayOfMonth(), 3); |
101 | 94 | assertEquals(localDateTime.getMonth(), Month.DECEMBER); |
102 | 95 | assertEquals(localDateTime.getYear(), 2007); |
|
0 commit comments