Pr/1235 Review (#1250)

* Add simple implementation for strangler pattern.

* Add strangler pattern in pom.xml.

* change package name

* Revert "change package name"

This reverts commit 430bd9073e.

* Code review for strangler

Delete final of method parameters.
Add final to private members.
Change package name.

* Revert "Code review for strangler"

This reverts commit d506356708.

* Revert "Revert "Code review for strangler""

This reverts commit c8fd65fda7.

* Remove unnecessary files
This commit is contained in:
ZhouSky
2020-07-04 17:05:46 +08:00
committed by GitHub
parent 5192beb5dd
commit 6fe219d644
19 changed files with 927 additions and 0 deletions

View File

@ -0,0 +1,69 @@
/*
* The MIT License
* Copyright © 2014-2019 Ilkka Seppälä
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
package com.iluwatar.strangler;
/**
*
* <p>The Strangler pattern is a software design pattern that incrementally migrate a legacy
* system by gradually replacing specific pieces of functionality with new applications and
* services. As features from the legacy system are replaced, the new system eventually
* replaces all of the old system's features, strangling the old system and allowing you
* to decommission it.</p>
*
* <p>This pattern is not only about updating but also enhancement.</p>
*
* <p>In this example, {@link OldArithmetic} indicates old system and its implementation depends
* on its source ({@link OldSource}). Now we tend to update system with new techniques and
* new features. In reality, the system may too complex, so usually need gradual migration.
* {@link HalfArithmetic} indicates system in the process of migration, its implementation
* depends on old one ({@link OldSource}) and under development one ({@link HalfSource}). The
* {@link HalfSource} covers part of {@link OldSource} and add new functionality. You can release
* this version system with new features, which also supports old version system functionalities.
* After whole migration, the new system ({@link NewArithmetic}) only depends on new source
* ({@link NewSource}).</p>
*
*/
public class App {
/**
* Program entry point.
* @param args command line args
*/
public static void main(final String[] args) {
final var nums = new int[]{1, 2, 3, 4, 5};
//Before migration
final var oldSystem = new OldArithmetic(new OldSource());
oldSystem.sum(nums);
oldSystem.mul(nums);
//In process of migration
final var halfSystem = new HalfArithmetic(new HalfSource(), new OldSource());
halfSystem.sum(nums);
halfSystem.mul(nums);
halfSystem.ifHasZero(nums);
//After migration
final var newSystem = new NewArithmetic(new NewSource());
newSystem.sum(nums);
newSystem.mul(nums);
newSystem.ifHasZero(nums);
}
}

View File

@ -0,0 +1,74 @@
/*
* The MIT License
* Copyright © 2014-2019 Ilkka Seppälä
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
package com.iluwatar.strangler;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/**
* System under migration. Depends on old version source ({@link OldSource}) and
* developing one ({@link HalfSource}).
*/
public class HalfArithmetic {
private static final Logger LOGGER = LoggerFactory.getLogger(HalfArithmetic.class);
private static final String VERSION = "1.5";
private final HalfSource newSource;
private final OldSource oldSource;
public HalfArithmetic(HalfSource newSource, OldSource oldSource) {
this.newSource = newSource;
this.oldSource = oldSource;
}
/**
* Accumulate sum.
* @param nums numbers need to add together
* @return accumulate sum
*/
public int sum(int... nums) {
LOGGER.info("Arithmetic sum {}", VERSION);
return newSource.accumulateSum(nums);
}
/**
* Accumulate multiplication.
* @param nums numbers need to multiply together
* @return accumulate multiplication
*/
public int mul(int... nums) {
LOGGER.info("Arithmetic mul {}", VERSION);
return oldSource.accumulateMul(nums);
}
/**
* Chech if has any zero.
* @param nums numbers need to check
* @return if has any zero, return true, else, return false
*/
public boolean ifHasZero(int... nums) {
LOGGER.info("Arithmetic check zero {}", VERSION);
return !newSource.ifNonZero(nums);
}
}

View File

@ -0,0 +1,54 @@
/*
* The MIT License
* Copyright © 2014-2019 Ilkka Seppälä
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
package com.iluwatar.strangler;
import java.util.Arrays;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/**
* Source under development. Replace part of old source and has added some new features.
*/
public class HalfSource {
private static final Logger LOGGER = LoggerFactory.getLogger(HalfSource.class);
private static final String VERSION = "1.5";
/**
* Implement accumulate sum with new technique.
* Replace old one in {@link OldSource}
*/
public int accumulateSum(int... nums) {
LOGGER.info("Source module {}", VERSION);
return Arrays.stream(nums).reduce(0, Integer::sum);
}
/**
* Check if all number is not zero.
* New feature.
*/
public boolean ifNonZero(int... nums) {
LOGGER.info("Source module {}", VERSION);
return Arrays.stream(nums).allMatch(num -> num != 0);
}
}

View File

@ -0,0 +1,71 @@
/*
* The MIT License
* Copyright © 2014-2019 Ilkka Seppälä
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
package com.iluwatar.strangler;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/**
* System after whole migration. Only depends on new version source ({@link NewSource}).
*/
public class NewArithmetic {
private static final Logger LOGGER = LoggerFactory.getLogger(NewArithmetic.class);
private static final String VERSION = "2.0";
private final NewSource source;
public NewArithmetic(NewSource source) {
this.source = source;
}
/**
* Accumulate sum.
* @param nums numbers need to add together
* @return accumulate sum
*/
public int sum(int... nums) {
LOGGER.info("Arithmetic sum {}", VERSION);
return source.accumulateSum(nums);
}
/**
* Accumulate multiplication.
* @param nums numbers need to multiply together
* @return accumulate multiplication
*/
public int mul(int... nums) {
LOGGER.info("Arithmetic mul {}", VERSION);
return source.accumulateMul(nums);
}
/**
* Chech if has any zero.
* @param nums numbers need to check
* @return if has any zero, return true, else, return false
*/
public boolean ifHasZero(int... nums) {
LOGGER.info("Arithmetic check zero {}", VERSION);
return !source.ifNonZero(nums);
}
}

View File

@ -0,0 +1,56 @@
/*
* The MIT License
* Copyright © 2014-2019 Ilkka Seppälä
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
package com.iluwatar.strangler;
import java.util.Arrays;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/**
* New source. Completely covers functionalities of old source with new techniques
* and also has some new features.
*/
public class NewSource {
private static final Logger LOGGER = LoggerFactory.getLogger(NewSource.class);
private static final String VERSION = "2.0";
public int accumulateSum(int... nums) {
LOGGER.info("Source module {}", VERSION);
return Arrays.stream(nums).reduce(0, Integer::sum);
}
/**
* Implement accumulate multiply with new technique.
* Replace old one in {@link OldSource}
*/
public int accumulateMul(int... nums) {
LOGGER.info("Source module {}", VERSION);
return Arrays.stream(nums).reduce(1, (a, b) -> a * b);
}
public boolean ifNonZero(int... nums) {
LOGGER.info("Source module {}", VERSION);
return Arrays.stream(nums).allMatch(num -> num != 0);
}
}

View File

@ -0,0 +1,61 @@
/*
* The MIT License
* Copyright © 2014-2019 Ilkka Seppälä
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
package com.iluwatar.strangler;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/**
* Old version system depends on old version source ({@link OldSource}).
*/
public class OldArithmetic {
private static final Logger LOGGER = LoggerFactory.getLogger(OldArithmetic.class);
private static final String VERSION = "1.0";
private final OldSource source;
public OldArithmetic(OldSource source) {
this.source = source;
}
/**
* Accumulate sum.
* @param nums numbers need to add together
* @return accumulate sum
*/
public int sum(int... nums) {
LOGGER.info("Arithmetic sum {}", VERSION);
return source.accumulateSum(nums);
}
/**
* Accumulate multiplication.
* @param nums numbers need to multiply together
* @return accumulate multiplication
*/
public int mul(int... nums) {
LOGGER.info("Arithmetic mul {}", VERSION);
return source.accumulateMul(nums);
}
}

View File

@ -0,0 +1,59 @@
/*
* The MIT License
* Copyright © 2014-2019 Ilkka Seppälä
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
package com.iluwatar.strangler;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/**
* Old source with techniques out of date.
*/
public class OldSource {
private static final Logger LOGGER = LoggerFactory.getLogger(OldSource.class);
private static final String VERSION = "1.0";
/**
* Implement accumulate sum with old technique.
*/
public int accumulateSum(int... nums) {
LOGGER.info("Source module {}", VERSION);
var sum = 0;
for (final var num : nums) {
sum += num;
}
return sum;
}
/**
* Implement accumulate multiply with old technique.
*/
public int accumulateMul(int... nums) {
LOGGER.info("Source module {}", VERSION);
var sum = 1;
for (final var num : nums) {
sum *= num;
}
return sum;
}
}

View File

@ -0,0 +1,36 @@
/*
* The MIT License
* Copyright © 2014-2019 Ilkka Seppälä
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
package com.iluwatar.strangler;
import org.junit.jupiter.api.Test;
/**
* Application test
*/
public class AppTest {
@Test
public void test() {
App.main(new String[]{});
}
}

View File

@ -0,0 +1,50 @@
/*
* The MIT License
* Copyright © 2014-2019 Ilkka Seppälä
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
package com.iluwatar.strangler;
import org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.*;
/**
* Test methods in HalfArithmetic
*/
class HalfArithmeticTest {
private static final HalfArithmetic arithmetic = new HalfArithmetic(new HalfSource(), new OldSource());
@Test
public void testSum() {
assertEquals(0, arithmetic.sum(-1, 0, 1));
}
@Test
public void testMul() {
assertEquals(0, arithmetic.mul(-1, 0, 1));
}
@Test
public void testIfHasZero() {
assertTrue(arithmetic.ifHasZero(-1, 0, 1));
}
}

View File

@ -0,0 +1,47 @@
/*
* The MIT License
* Copyright © 2014-2019 Ilkka Seppälä
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
package com.iluwatar.strangler;
import org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertEquals;
/**
* Test methods in HalfSource
*/
public class HalfSourceTest {
private static final HalfSource source = new HalfSource();
@Test
public void testAccumulateSum() {
assertEquals(0, source.accumulateSum(-1, 0, 1));
}
@Test
public void testIfNonZero() {
assertFalse(source.ifNonZero(-1, 0, 1));
}
}

View File

@ -0,0 +1,50 @@
/*
* The MIT License
* Copyright © 2014-2019 Ilkka Seppälä
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
package com.iluwatar.strangler;
import org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.*;
/**
* Test methods in NewArithmetic
*/
class NewArithmeticTest {
private static final NewArithmetic arithmetic = new NewArithmetic(new NewSource());
@Test
public void testSum() {
assertEquals(0, arithmetic.sum(-1, 0, 1));
}
@Test
public void testMul() {
assertEquals(0, arithmetic.mul(-1, 0, 1));
}
@Test
public void testIfHasZero() {
assertTrue(arithmetic.ifHasZero(-1, 0, 1));
}
}

View File

@ -0,0 +1,51 @@
/*
* The MIT License
* Copyright © 2014-2019 Ilkka Seppälä
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
package com.iluwatar.strangler;
import org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;
/**
* Test methods in NewSource
*/
public class NewSourceTest {
private static final NewSource source = new NewSource();
@Test
public void testAccumulateSum() {
assertEquals(0, source.accumulateSum(-1, 0, 1));
}
@Test
public void testAccumulateMul() {
assertEquals(0, source.accumulateMul(-1, 0, 1));
}
@Test
public void testIfNonZero() {
assertFalse(source.ifNonZero(-1, 0, 1));
}
}

View File

@ -0,0 +1,45 @@
/*
* The MIT License
* Copyright © 2014-2019 Ilkka Seppälä
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
package com.iluwatar.strangler;
import org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.*;
/**
* Test methods in OldArithmetic
*/
class OldArithmeticTest {
private static final OldArithmetic arithmetic = new OldArithmetic(new OldSource());
@Test
public void testSum() {
assertEquals(0, arithmetic.sum(-1, 0, 1));
}
@Test
public void testMul() {
assertEquals(0, arithmetic.mul(-1, 0, 1));
}
}

View File

@ -0,0 +1,45 @@
/*
* The MIT License
* Copyright © 2014-2019 Ilkka Seppälä
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
package com.iluwatar.strangler;
import org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.assertEquals;
/**
* Test methods in OldSource
*/
public class OldSourceTest {
private static final OldSource source = new OldSource();
@Test
public void testAccumulateSum() {
assertEquals(0, source.accumulateSum(-1, 0, 1));
}
@Test
public void testAccumulateMul() {
assertEquals(0, source.accumulateMul(-1, 0, 1));
}
}