Skip to content

Commit

Permalink
Update OptionTest
Browse files Browse the repository at this point in the history
  • Loading branch information
Glavo committed Jun 30, 2024
1 parent 485be23 commit 31dbb07
Show file tree
Hide file tree
Showing 3 changed files with 110 additions and 59 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
/*
* Copyright 2024 Glavo
*
* 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 kala.collection.base.primitive;

import kala.collection.base.MapIterator;

public interface PrimitiveMapIterator<K, V> extends MapIterator<K, V> {

}
81 changes: 48 additions & 33 deletions src/test/java/kala/control/OptionTest.java
Original file line number Diff line number Diff line change
@@ -1,33 +1,48 @@
package kala.control;

import org.junit.jupiter.api.*;

import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.util.Arrays;

import static org.junit.jupiter.api.Assertions.*;

public class OptionTest {
Option<?>[] opts = new Option<?>[]{
Option.none(),
Option.some("foo"),
Option.some(10),
Option.some(Arrays.asList("A", "B", "C")),
Option.some(null)
};

@Test
public void serializationTest() {
assertAll(Arrays.stream(opts).map(opt -> () -> {
ByteArrayOutputStream out = new ByteArrayOutputStream(512);
new ObjectOutputStream(out).writeObject(opt);
byte[] buffer = out.toByteArray();
ByteArrayInputStream in = new ByteArrayInputStream(buffer);
Object obj = new ObjectInputStream(in).readObject();
assertEquals(opt, obj);
}));
}
}
/*
* Copyright 2024 Glavo
*
* 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 kala.control;

import org.junit.jupiter.api.*;

import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.util.Arrays;

import static org.junit.jupiter.api.Assertions.*;

public class OptionTest {
Option<?>[] opts = new Option<?>[]{
Option.none(),
Option.some("foo"),
Option.some(10),
Option.some(Arrays.asList("A", "B", "C")),
Option.some(null)
};

@Test
public void serializationTest() {
assertAll(Arrays.stream(opts).map(opt -> () -> {
ByteArrayOutputStream out = new ByteArrayOutputStream(512);
new ObjectOutputStream(out).writeObject(opt);
byte[] buffer = out.toByteArray();
ByteArrayInputStream in = new ByteArrayInputStream(buffer);
Object obj = new ObjectInputStream(in).readObject();
assertEquals(opt, obj);
}));
}
}
66 changes: 40 additions & 26 deletions src/test/java/kala/control/primitive/BooleanOptionTest.java
Original file line number Diff line number Diff line change
@@ -1,26 +1,40 @@
package kala.control.primitive;

import kala.control.primitive.BooleanOption;
import org.junit.jupiter.api.Test;

import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.util.stream.Stream;

import static org.junit.jupiter.api.Assertions.*;

public class BooleanOptionTest {
@Test
public void serializationTest() {
assertAll(Stream.of(BooleanOption.True, BooleanOption.False, BooleanOption.None).map(opt -> () -> {
ByteArrayOutputStream out = new ByteArrayOutputStream(512);
new ObjectOutputStream(out).writeObject(opt);
byte[] buffer = out.toByteArray();
ByteArrayInputStream in = new ByteArrayInputStream(buffer);
Object obj = new ObjectInputStream(in).readObject();
assertSame(opt, obj);
}));
}
}
/*
* Copyright 2024 Glavo
*
* 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 kala.control.primitive;

import org.junit.jupiter.api.Test;

import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.util.stream.Stream;

import static org.junit.jupiter.api.Assertions.*;

public class BooleanOptionTest {
@Test
public void serializationTest() {
assertAll(Stream.of(BooleanOption.True, BooleanOption.False, BooleanOption.None).map(opt -> () -> {
ByteArrayOutputStream out = new ByteArrayOutputStream(512);
new ObjectOutputStream(out).writeObject(opt);
byte[] buffer = out.toByteArray();
ByteArrayInputStream in = new ByteArrayInputStream(buffer);
Object obj = new ObjectInputStream(in).readObject();
assertSame(opt, obj);
}));
}
}

0 comments on commit 31dbb07

Please sign in to comment.