/
ImmutableFeatureDefinitionIdentifierTest.java
175 lines (144 loc) · 6.76 KB
/
ImmutableFeatureDefinitionIdentifierTest.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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
/*
* Copyright (c) 2017 Bosch Software Innovations GmbH.
*
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v2.0
* which accompanies this distribution, and is available at
* https://www.eclipse.org/org/documents/epl-2.0/index.php
*
* Contributors:
* Bosch Software Innovations GmbH - initial contribution
*/
package org.eclipse.ditto.model.things;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
import static org.assertj.core.api.Assertions.assertThatIllegalArgumentException;
import static org.assertj.core.api.Assertions.assertThatNullPointerException;
import static org.mutabilitydetector.unittesting.MutabilityAssert.assertInstancesOf;
import static org.mutabilitydetector.unittesting.MutabilityMatchers.areImmutable;
import org.junit.Test;
import nl.jqno.equalsverifier.EqualsVerifier;
/**
* Unit test for {@link ImmutableFeatureDefinitionIdentifier}.
*/
public final class ImmutableFeatureDefinitionIdentifierTest {
private static final String NAMESPACE = "org.eclipse.ditto";
private static final String NAME = "vorto";
private static final String VERSION = "0.1.0";
private static final String VALID_IDENTIFIER_STRING = NAMESPACE + ":" + NAME + ":" + VERSION;
@Test
public void assertImmutability() {
assertInstancesOf(ImmutableFeatureDefinitionIdentifier.class, areImmutable());
}
@Test
public void testHashCodeAndEquals() {
EqualsVerifier.forClass(ImmutableFeatureDefinitionIdentifier.class)
.usingGetClass()
.withIgnoredFields("stringRepresentation") // as it is only derived from other properties
.verify();
}
@Test
public void tryToGetInstanceWithNullNamespace() {
assertThatNullPointerException()
.isThrownBy(() -> ImmutableFeatureDefinitionIdentifier.getInstance(null, NAME, VERSION))
.withMessage("The %s must not be null!", "namespace")
.withNoCause();
}
@Test
public void tryToGetInstanceWithEmptyNamespace() {
assertThatIllegalArgumentException()
.isThrownBy(() -> ImmutableFeatureDefinitionIdentifier.getInstance("", NAME, VERSION))
.withMessage("The argument '%s' must not be empty!", "namespace")
.withNoCause();
}
@Test
public void tryToGetInstanceWithNullName() {
assertThatNullPointerException()
.isThrownBy(() -> ImmutableFeatureDefinitionIdentifier.getInstance(NAMESPACE, null, VERSION))
.withMessage("The %s must not be null!", "name")
.withNoCause();
}
@Test
public void tryToGetInstanceWithEmptyName() {
assertThatIllegalArgumentException()
.isThrownBy(() -> ImmutableFeatureDefinitionIdentifier.getInstance(NAMESPACE, "", VERSION))
.withMessage("The argument '%s' must not be empty!", "name")
.withNoCause();
}
@Test
public void tryToGetInstanceWithNullVersion() {
assertThatNullPointerException()
.isThrownBy(() -> ImmutableFeatureDefinitionIdentifier.getInstance(NAMESPACE, NAME, null))
.withMessage("The %s must not be null!", "version")
.withNoCause();
}
@Test
public void tryToGetInstanceWithEmptyVersion() {
assertThatIllegalArgumentException()
.isThrownBy(() -> ImmutableFeatureDefinitionIdentifier.getInstance(NAMESPACE, NAME, ""))
.withMessage("The argument '%s' must not be empty!", "version")
.withNoCause();
}
@Test
public void getNamespaceReturnsExpected() {
final ImmutableFeatureDefinitionIdentifier underTest =
ImmutableFeatureDefinitionIdentifier.getInstance(NAMESPACE, NAME, VERSION);
assertThat(underTest.getNamespace()).isEqualTo(NAMESPACE);
}
@Test
public void getNameReturnsExpected() {
final ImmutableFeatureDefinitionIdentifier underTest =
ImmutableFeatureDefinitionIdentifier.getInstance(NAMESPACE, NAME, VERSION);
assertThat(underTest.getName()).isEqualTo(NAME);
}
@Test
public void getVersionReturnsExpected() {
final ImmutableFeatureDefinitionIdentifier underTest =
ImmutableFeatureDefinitionIdentifier.getInstance(NAMESPACE, NAME, VERSION);
assertThat(underTest.getVersion()).isEqualTo(VERSION);
}
@Test
public void toStringReturnsExpected() {
final ImmutableFeatureDefinitionIdentifier underTest =
ImmutableFeatureDefinitionIdentifier.getInstance(NAMESPACE, NAME, VERSION);
assertThat(underTest.toString()).isEqualTo(VALID_IDENTIFIER_STRING);
}
@Test
public void tryToParseNullIdentifierString() {
assertThatNullPointerException()
.isThrownBy(() -> ImmutableFeatureDefinitionIdentifier.ofParsed(null))
.withMessage("The %s must not be null!", "CharSequence-representation of the identifier")
.withNoCause();
}
@Test
public void tryToParseEmptyIdentifierString() {
assertThatExceptionOfType(FeatureDefinitionIdentifierInvalidException.class)
.isThrownBy(() -> ImmutableFeatureDefinitionIdentifier.ofParsed(""))
.withMessage("FeatureDefinition Identifier <> is invalid!")
.withNoCause();
}
@Test
public void tryToParseIdentifierStringWithEmptyNameSegment() {
final String invalidString = NAMESPACE + "::" + VERSION;
assertThatExceptionOfType(FeatureDefinitionIdentifierInvalidException.class)
.isThrownBy(() -> ImmutableFeatureDefinitionIdentifier.ofParsed(invalidString))
.withMessage("FeatureDefinition Identifier <%s> is invalid!", invalidString)
.withNoCause();
}
@Test
public void tryToParseIdentifierStringWithIllegalChar() {
final String invalidString = "org/eclipse/ditto" + ":" + NAME + ":" + VERSION;
assertThatExceptionOfType(FeatureDefinitionIdentifierInvalidException.class)
.isThrownBy(() -> ImmutableFeatureDefinitionIdentifier.ofParsed(invalidString))
.withMessage("FeatureDefinition Identifier <%s> is invalid!", invalidString)
.withNoCause();
}
@Test
public void parseValidIdentifierString() {
final ImmutableFeatureDefinitionIdentifier actual =
ImmutableFeatureDefinitionIdentifier.ofParsed(VALID_IDENTIFIER_STRING);
final ImmutableFeatureDefinitionIdentifier expected =
ImmutableFeatureDefinitionIdentifier.getInstance(NAMESPACE, NAME, VERSION);
assertThat(actual).isEqualTo(expected);
}
}