Skip to content

Commit 727ee64

Browse files
committed
Сделано модульное тестирование
1 parent ca31f76 commit 727ee64

File tree

4 files changed

+110
-31
lines changed

4 files changed

+110
-31
lines changed

pom.xml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,12 @@
4646
<artifactId>annotations</artifactId>
4747
<version>23.0.0</version>
4848
</dependency>
49+
<dependency>
50+
<groupId>junit</groupId>
51+
<artifactId>junit</artifactId>
52+
<version>4.13.2</version>
53+
<scope>test</scope>
54+
</dependency>
4955
</dependencies>
5056

5157
</project>

src/main/java/dev/kalenchukov/stringformat/StringFormat.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,7 @@ public static String format(@NotNull String value, @NotNull final Map<@NotNull S
151151
Objects.requireNonNull(value);
152152
Objects.requireNonNull(params);
153153

154-
for (Map.Entry<@NotNull String, @NotNull String> param : params.entrySet())
154+
for (Map.Entry<String, String> param : params.entrySet())
155155
{
156156
Objects.requireNonNull(param.getKey());
157157
Objects.requireNonNull(param.getValue());

src/main/java/dev/kalenchukov/stringformat/tests/Test.java

Lines changed: 0 additions & 30 deletions
This file was deleted.
Lines changed: 103 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,103 @@
1+
/*
2+
* Copyright © 2022 Алексей Каленчуков
3+
* GitHub: https://github.com/kalenchukov
4+
* E-mail: mailto:aleksey.kalenchukov@yandex.ru
5+
*/
6+
7+
package dev.kalenchukov.stringformat;
8+
9+
import org.junit.Test;
10+
11+
import java.util.HashMap;
12+
import java.util.Map;
13+
14+
import static org.junit.Assert.*;
15+
16+
public class StringFormatTest
17+
{
18+
@Test
19+
public void testFormatInteger()
20+
{
21+
String string = StringFormat.format("Hello %NAME%!", "NAME", 100);
22+
23+
assertEquals("Hello 100!", string);
24+
}
25+
26+
@Test
27+
public void testFormatLong()
28+
{
29+
String string = StringFormat.format("Hello %NAME%!", "NAME", 1000L);
30+
31+
assertEquals("Hello 1000!", string);
32+
}
33+
34+
@Test
35+
public void testFormatShort()
36+
{
37+
String string = StringFormat.format("Hello %NAME%!", "NAME", 100.6);
38+
39+
assertEquals("Hello 100.6!", string);
40+
}
41+
42+
@Test
43+
public void testFormatFloat()
44+
{
45+
String string = StringFormat.format("Hello %NAME%!", "NAME", 10.4F);
46+
47+
assertEquals("Hello 10.4!", string);
48+
}
49+
50+
@Test
51+
public void testFormatDouble()
52+
{
53+
String string = StringFormat.format("Hello %NAME%!", "NAME", 1000.78D);
54+
55+
assertEquals("Hello 1000.78!", string);
56+
}
57+
58+
@Test
59+
public void testFormatByte()
60+
{
61+
String string = StringFormat.format("Hello %NAME%!", "NAME", 120);
62+
63+
assertEquals("Hello 120!", string);
64+
}
65+
66+
@Test
67+
public void testFormatCharacter()
68+
{
69+
String string = StringFormat.format("Hello %NAME%!", "NAME", 'A');
70+
71+
assertEquals("Hello A!", string);
72+
}
73+
74+
@Test
75+
public void testFormatObject()
76+
{
77+
Object object = "Matrix";
78+
79+
String string = StringFormat.format("Hello %NAME%!", "NAME", object);
80+
81+
assertEquals("Hello Matrix!", string);
82+
}
83+
84+
@Test
85+
public void testFormatString()
86+
{
87+
String string = StringFormat.format("Hello %NAME%!", "NAME", "World");
88+
89+
assertEquals("Hello World!", string);
90+
}
91+
92+
@Test
93+
public void testFormatMap()
94+
{
95+
Map<String, String> params = new HashMap<>();
96+
params.put("NAME", "World");
97+
params.put("LANGUAGE", "Java");
98+
99+
String string = StringFormat.format("Hello %NAME%! It`s %LANGUAGE%!", params);
100+
101+
assertEquals("Hello World! It`s Java!", string);
102+
}
103+
}

0 commit comments

Comments
 (0)