forked from prmr/DesignBook
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTestConcat.java
More file actions
62 lines (54 loc) · 1.6 KB
/
TestConcat.java
File metadata and controls
62 lines (54 loc) · 1.6 KB
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
/*******************************************************************************
* Companion code for the book "Introduction to Software Design with Java"
* by Martin P. Robillard.
*
* Copyright (C) 2019 by Martin P. Robillard
*
* This code is licensed under a Creative Commons
* Attribution-NonCommercial-NoDerivatives 4.0 International License.
*
* See http://creativecommons.org/licenses/by-nc-nd/4.0/
*******************************************************************************/
package chapter5;
import static org.junit.jupiter.api.Assertions.*;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.function.Executable;
public class TestConcat
{
private static final String EMPTY = "";
private static final String NON_EMPTY = "abc";
@Test
public void testConcat_EmptyEmpty()
{
assertSame(EMPTY, EMPTY.concat(""));
}
@Test
public void testConcat_NonEmptyEmpty()
{
assertSame(NON_EMPTY, NON_EMPTY.concat(""));
}
@Test
public void testConcat_EmptyNonEmpty()
{
assertEquals(NON_EMPTY, EMPTY.concat(NON_EMPTY));
}
@Test
public void testConcat_NonEmptyNonEmpty()
{
assertEquals("abcabc", NON_EMPTY.concat(NON_EMPTY));
}
@Test // This test documents that calling concat with a null argument throws an NPE
public void testConcat_Null()
{
assertThrows(NullPointerException.class, new Executable()
{
// A lambda expression would normally be used here, but
// they are not covered until Chapter 9.
@Override
public void execute() throws Throwable
{
NON_EMPTY.concat(null);
}
});
}
}