diff --git a/thirtyinch/src/test/java/net/grandcentrix/thirtyinch/internal/OneTimeRemovableTest.java b/thirtyinch/src/test/java/net/grandcentrix/thirtyinch/internal/OneTimeRemovableTest.java new file mode 100644 index 00000000..7988586c --- /dev/null +++ b/thirtyinch/src/test/java/net/grandcentrix/thirtyinch/internal/OneTimeRemovableTest.java @@ -0,0 +1,64 @@ +/* + * Copyright (C) 2017 grandcentrix GmbH + * 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 net.grandcentrix.thirtyinch.internal; + + +import org.junit.Test; + +import static org.assertj.core.api.Java6Assertions.assertThat; + +public class OneTimeRemovableTest { + + @Test + public void remove_once_calls_OnRemove() throws Exception { + final int[] called = new int[]{0}; + final OneTimeRemovable removable = new OneTimeRemovable() { + @Override + public void onRemove() { + called[0]++; + } + }; + + assertThat(called[0]).isEqualTo(0); + assertThat(removable.isRemoved()).isFalse(); + + removable.remove(); + assertThat(called[0]).isEqualTo(1); + assertThat(removable.isRemoved()).isTrue(); + } + + @Test + public void remove_twice_calls_OnRemove_once() throws Exception { + final int[] called = new int[]{0}; + final OneTimeRemovable removable = new OneTimeRemovable() { + @Override + public void onRemove() { + called[0]++; + } + }; + + assertThat(called[0]).isEqualTo(0); + assertThat(removable.isRemoved()).isFalse(); + + removable.remove(); + assertThat(called[0]).isEqualTo(1); + assertThat(removable.isRemoved()).isTrue(); + + removable.remove(); + assertThat(called[0]).isEqualTo(1); + assertThat(removable.isRemoved()).isTrue(); + } +} \ No newline at end of file