Skip to content

Commit

Permalink
test: adds test to verify visitables
Browse files Browse the repository at this point in the history
Signed-off-by: Marc Nuri <[email protected]>
  • Loading branch information
manusa committed Oct 27, 2023
1 parent 49f8603 commit e84ccd7
Showing 1 changed file with 52 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
/**
* Copyright (C) 2015 Red Hat, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package io.fabric8.kubernetes.client;

import io.fabric8.kubernetes.api.builder.TypedVisitor;
import io.fabric8.kubernetes.api.model.ContainerBuilder;
import io.fabric8.kubernetes.api.model.KubernetesListBuilder;
import io.fabric8.kubernetes.api.model.apps.DeploymentBuilder;
import org.junit.jupiter.api.Disabled;
import org.junit.jupiter.api.Test;

import java.util.concurrent.atomic.AtomicInteger;

import static org.assertj.core.api.Assertions.assertThat;

class VisitorTest {

@Test
@Disabled("https://github.com/sundrio/sundrio/issues/438")
void visitorShouldVisitOnlyOnce() {
// Given
final AtomicInteger counter = new AtomicInteger();
final KubernetesListBuilder listBuilder = new KubernetesListBuilder();
listBuilder.addToItems(
new DeploymentBuilder()
.withNewSpec().withNewTemplate().withNewSpec().addNewContainer()
.withImage("foo")
.endContainer().endSpec().endTemplate().endSpec());
// When
listBuilder.accept(new TypedVisitor<ContainerBuilder>() {
@Override
public void visit(ContainerBuilder containerBuilder) {
counter.incrementAndGet();
}
});
// Then
assertThat(counter).hasValue(1);
}
}

0 comments on commit e84ccd7

Please sign in to comment.