Skip to content

Commit

Permalink
#1109 Improve Pit Coverage. Add new tests.
Browse files Browse the repository at this point in the history
  • Loading branch information
goldbal330 committed Aug 16, 2021
1 parent 58922e1 commit e728959
Show file tree
Hide file tree
Showing 17 changed files with 649 additions and 4 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
/*
* Copyright (c) 2021 The Bank of New York Mellon.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* and Eclipse Distribution License v. 1.0 which accompany this distribution.
* The Eclipse Public License is available at http://www.eclipse.org/legal/epl-v10.html
* and the Eclipse Distribution License is available at
* http://www.eclipse.org/org/documents/edl-v10.php.
*/

package org.eclipse.collections.impl.block.procedure;

import org.eclipse.collections.api.block.procedure.primitive.ObjectIntProcedure;
import org.junit.Assert;
import org.junit.Test;

public class AdaptObjectIntProcedureToProcedureTest
{
@Test
public void value()
{
MockObjectIntProcedure mockObjectIntProcedure = new MockObjectIntProcedure();
AdaptObjectIntProcedureToProcedure<Integer> procedure =
new AdaptObjectIntProcedureToProcedure<>(mockObjectIntProcedure);
procedure.value(1);
Assert.assertEquals(1, mockObjectIntProcedure.getEachValue());
Assert.assertEquals(0, mockObjectIntProcedure.getParameterValue());

procedure.value(2);
Assert.assertEquals(2, mockObjectIntProcedure.getEachValue());
Assert.assertEquals(1, mockObjectIntProcedure.getParameterValue());

procedure.value(3);
Assert.assertEquals(3, mockObjectIntProcedure.getEachValue());
Assert.assertEquals(2, mockObjectIntProcedure.getParameterValue());
}

private static class MockObjectIntProcedure
implements ObjectIntProcedure<Integer>
{
private int eachValue;
private int parameterValue;

@Override
public void value(Integer each, int parameter)
{
this.eachValue = each;
this.parameterValue = parameter;
}

public int getEachValue()
{
return this.eachValue;
}

public int getParameterValue()
{
return this.parameterValue;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@

import org.eclipse.collections.api.bag.MutableBag;
import org.eclipse.collections.api.factory.Bags;
import org.eclipse.collections.impl.utility.StringIterate;
import org.junit.Assert;
import org.junit.Test;

Expand Down Expand Up @@ -46,4 +47,14 @@ public void basicCaseUsingFactoryMethod()
Assert.assertEquals(3, procedure.getResult().occurrencesOf("mary"));
Assert.assertEquals(0, procedure.getResult().occurrencesOf("other"));
}

@Test
public void toStringTest()
{
MutableBag<String> targetCollection = Bags.mutable.empty();
BagAddOccurrencesProcedure<String> procedure = BagAddOccurrencesProcedure.on(targetCollection);
String toString = procedure.toString();
Assert.assertNotNull(toString);
Assert.assertTrue(StringIterate.notEmptyOrWhitespace(toString));
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2021 Goldman Sachs.
* Copyright (c) 2021 Goldman Sachs and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* and Eclipse Distribution License v. 1.0 which accompany this distribution.
Expand Down Expand Up @@ -29,7 +29,7 @@ public void noopCaseAndThenDefault()
CaseProcedure<String> procedure = new CaseProcedure<>();
strings.each(procedure);
Verify.assertEmpty(result);
procedure.setDefault(result::add);
Verify.assertSame(procedure, procedure.setDefault(result::add));
strings.each(procedure);
Assert.assertEquals(result, strings);
Verify.assertContains("CaseProcedure", procedure.toString());
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2021 Goldman Sachs.
* Copyright (c) 2021 Goldman Sachs and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* and Eclipse Distribution License v. 1.0 which accompany this distribution.
Expand All @@ -15,6 +15,7 @@
import org.eclipse.collections.impl.factory.Lists;
import org.eclipse.collections.impl.list.mutable.FastList;
import org.eclipse.collections.impl.utility.Iterate;
import org.eclipse.collections.impl.utility.StringIterate;
import org.junit.Assert;
import org.junit.Test;

Expand All @@ -35,4 +36,13 @@ public void procedure()
Assert.assertEquals(list, list1);
Assert.assertEquals(list, list2);
}

@Test
public void toStringTest()
{
Procedure<String> procedure = new CollectionAddProcedure<>(Lists.mutable.of());
String s = procedure.toString();
Assert.assertNotNull(s);
Assert.assertTrue(StringIterate.notEmptyOrWhitespace(s));
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
/*
* Copyright (c) 2021 The Bank of New York Mellon.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* and Eclipse Distribution License v. 1.0 which accompany this distribution.
* The Eclipse Public License is available at http://www.eclipse.org/legal/epl-v10.html
* and the Eclipse Distribution License is available at
* http://www.eclipse.org/org/documents/edl-v10.php.
*/

package org.eclipse.collections.impl.block.procedure;

import org.eclipse.collections.api.factory.Lists;
import org.eclipse.collections.impl.block.factory.Functions;
import org.eclipse.collections.impl.test.Verify;
import org.junit.Test;

public class CollectProcedureTest
{
@Test
public void getCollection()
{
CollectProcedure<Integer, Integer> collectProcedure =
new CollectProcedure<>(Functions.getIntegerPassThru(), Lists.mutable.empty());

Verify.assertEmpty(collectProcedure.getCollection());
collectProcedure.value(1);
Verify.assertContainsAll(collectProcedure.getCollection(), 1);

collectProcedure.value(2);
Verify.assertContainsAll(collectProcedure.getCollection(), 1, 2);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
/*
* Copyright (c) 2021 The Bank of New York Mellon.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* and Eclipse Distribution License v. 1.0 which accompany this distribution.
* The Eclipse Public License is available at http://www.eclipse.org/legal/epl-v10.html
* and the Eclipse Distribution License is available at
* http://www.eclipse.org/org/documents/edl-v10.php.
*/

package org.eclipse.collections.impl.block.procedure;

import org.eclipse.collections.api.factory.Lists;
import org.eclipse.collections.impl.test.Verify;
import org.eclipse.collections.impl.utility.StringIterate;
import org.junit.Assert;
import org.junit.Test;

public class CollectionAddProcedureTest
{
@Test
public void toStringTest()
{
CollectionAddProcedure<Integer> procedure = new CollectionAddProcedure<>(Lists.mutable.empty());
String s = procedure.toString();
Assert.assertNotNull(s);
Assert.assertTrue(StringIterate.notEmptyOrWhitespace(s));
}

@Test
public void getResult()
{
CollectionAddProcedure<Integer> procedure = CollectionAddProcedure.on(Lists.mutable.empty());
Verify.assertEmpty(procedure.getResult());
procedure.value(1);
Verify.assertSize(1, procedure.getResult());
Verify.assertContainsAll(procedure.getResult(), 1);

procedure.value(2);
Verify.assertSize(2, procedure.getResult());
Verify.assertContainsAll(procedure.getResult(), 1, 2);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
/*
* Copyright (c) 2021 The Bank of New York Mellon.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* and Eclipse Distribution License v. 1.0 which accompany this distribution.
* The Eclipse Public License is available at http://www.eclipse.org/legal/epl-v10.html
* and the Eclipse Distribution License is available at
* http://www.eclipse.org/org/documents/edl-v10.php.
*/

package org.eclipse.collections.impl.block.procedure;

import org.eclipse.collections.api.factory.Lists;
import org.eclipse.collections.impl.test.Verify;
import org.eclipse.collections.impl.utility.StringIterate;
import org.junit.Assert;
import org.junit.Test;

public class CollectionRemoveProcedureTest
{
@Test
public void getResult()
{
CollectionRemoveProcedure<Integer> procedure = CollectionRemoveProcedure.on(Lists.mutable.with(1, 2));
Verify.assertContainsAll(procedure.getResult(), 1, 2);
procedure.value(5);
Verify.assertContainsAll(procedure.getResult(), 1, 2);
procedure.value(1);
Verify.assertSize(1, procedure.getResult());
Verify.assertContainsAll(procedure.getResult(), 2);
}

public void toStringTest()
{
CollectionRemoveProcedure<Integer> procedure = CollectionRemoveProcedure.on(Lists.mutable.with(1, 2));
String s = procedure.toString();
Assert.assertNotNull(s);
Assert.assertTrue(StringIterate.notEmptyOrWhitespace(s));
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
/*
* Copyright (c) 2021 The Bank of New York Mellon.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* and Eclipse Distribution License v. 1.0 which accompany this distribution.
* The Eclipse Public License is available at http://www.eclipse.org/legal/epl-v10.html
* and the Eclipse Distribution License is available at
* http://www.eclipse.org/org/documents/edl-v10.php.
*/

package org.eclipse.collections.impl.block.procedure;

import org.eclipse.collections.api.block.procedure.Procedure;
import org.eclipse.collections.impl.utility.StringIterate;
import org.junit.Assert;
import org.junit.Test;

public class CounterProcedureTest
{
@Test
public void getCount()
{
MockProcedure mockProcedure = new MockProcedure();
CounterProcedure<Integer> procedure = new CounterProcedure<>(mockProcedure);
Assert.assertNull(mockProcedure.getValue());
Assert.assertEquals(0, procedure.getCount());
procedure.value(1);
Assert.assertEquals(1, (int) mockProcedure.getValue());
Assert.assertEquals(1, procedure.getCount());

procedure.value(2);
Assert.assertEquals(2, (int) mockProcedure.getValue());
Assert.assertEquals(2, procedure.getCount());
}

@Test
public void toStringTest()
{
MockProcedure mockProcedure = new MockProcedure();
CounterProcedure<Integer> procedure = new CounterProcedure<>(mockProcedure);
String s = procedure.toString();
Assert.assertNotNull(s);
Assert.assertTrue(StringIterate.notEmptyOrWhitespace(s));
}

private static class MockProcedure implements Procedure<Integer>
{
private Integer value;

@Override
public void value(Integer each)
{
this.value = each;
}

public Integer getValue()
{
return this.value;
}
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2021 Goldman Sachs.
* Copyright (c) 2021 Goldman Sachs and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* and Eclipse Distribution License v. 1.0 which accompany this distribution.
Expand All @@ -16,6 +16,7 @@
import org.eclipse.collections.impl.list.mutable.FastList;
import org.eclipse.collections.impl.test.Verify;
import org.eclipse.collections.impl.utility.Iterate;
import org.eclipse.collections.impl.utility.StringIterate;
import org.junit.Assert;
import org.junit.Test;
import org.slf4j.Logger;
Expand All @@ -39,4 +40,15 @@ public void procedure()
Assert.assertEquals(1, list2.size());
Verify.assertContains("2", list2);
}

@Test
public void toStringTest()
{
MutableList<String> list1 = Lists.mutable.of();
MutableList<String> list2 = Lists.mutable.of();
Procedure<String> ifProcedure = new IfProcedure<>("1"::equals, list1::add, list2::add);
String s = ifProcedure.toString();
Assert.assertNotNull(s);
Assert.assertTrue(StringIterate.notEmptyOrWhitespace(s));
}
}
Loading

0 comments on commit e728959

Please sign in to comment.