Skip to content

Commit ae217f1

Browse files
committed
fix: hide typeInfo in KubeResourceInfo but allow access to apiGroup, kind
Signed-off-by: Andre Dietisheim <[email protected]>
1 parent ed4d82a commit ae217f1

File tree

2 files changed

+63
-0
lines changed

2 files changed

+63
-0
lines changed

src/main/java/com/redhat/devtools/intellij/common/validation/KubernetesResourceInfo.java

+14
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,20 @@ private void setTypeInfo(KubernetesTypeInfo typeInfo) {
102102
this.typeInfo = typeInfo;
103103
}
104104

105+
public String getApiGroup() {
106+
if (typeInfo == null) {
107+
return null;
108+
}
109+
return typeInfo.getApiGroup();
110+
}
111+
112+
public String getKind() {
113+
if (typeInfo == null) {
114+
return null;
115+
}
116+
return typeInfo.getKind();
117+
}
118+
105119
@Override
106120
public boolean equals(Object o) {
107121
if (this == o) return true;

src/test/java/com/redhat/devtools/intellij/common/validation/KubernetesResourceInfoTest.java

+49
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
import static org.mockito.Mockito.doAnswer;
3636
import static org.mockito.Mockito.mock;
3737
import static org.mockito.Mockito.mockStatic;
38+
import static org.mockito.Mockito.verify;
3839
import static org.mockito.Mockito.when;
3940

4041
public class KubernetesResourceInfoTest {
@@ -297,6 +298,54 @@ public void create_returns_empty_info_for_unsupported_file_type() {
297298
assertThat(resourceInfo.getNamespace()).isNull();
298299
}
299300

301+
@Test
302+
public void getApiGroup_returns_apiGroup_of_typeInfo() {
303+
// given
304+
KubernetesResourceInfo info = new KubernetesResourceInfo("obiwan", "stewjon", typeInfo);
305+
306+
// when
307+
info.getApiGroup();
308+
309+
// then
310+
verify(typeInfo).getApiGroup();
311+
}
312+
313+
@Test
314+
public void getApiGroup_returns_null_given_typeInfo_is_null() {
315+
// given
316+
KubernetesResourceInfo info = new KubernetesResourceInfo("obiwan", "tatooine", null);
317+
318+
// when
319+
String apiGroup = info.getApiGroup();
320+
321+
// then
322+
assertThat(apiGroup).isNull();
323+
}
324+
325+
@Test
326+
public void getKind_returns_kind_of_typeInfo() {
327+
// given
328+
KubernetesResourceInfo info = new KubernetesResourceInfo("luke", "stewjon", typeInfo);
329+
330+
// when
331+
info.getKind();
332+
333+
// then
334+
verify(typeInfo).getKind();
335+
}
336+
337+
@Test
338+
public void getKind_returns_null_given_typeInfo_is_nul() {
339+
// given
340+
KubernetesResourceInfo info = new KubernetesResourceInfo("luke", "stewjon", nul);
341+
342+
// when
343+
String kind = info.getKind();
344+
345+
// then
346+
assertThat(kind).isNull();
347+
}
348+
300349
private void mockCreateKubernetesTypeInfo(KubernetesTypeInfo typeInfo, PsiFile file) {
301350
mockStatic.when(() -> KubernetesTypeInfo.create(file))
302351
.thenReturn(typeInfo);

0 commit comments

Comments
 (0)