MultiplicationWithoutMultiply { public int calculate(int n1, int n2) { int result = 0; boolean negative = (n1 < 0 && n2 >= 0) || (n2 < 0 && n1 >= 0); boolean positive = !negative; n1 = Math.abs(n1); for (int i = 0; i < n1; i++) { if (negative && n2 > 0 || positive && n2 < 0) result -= n2; else result += n2; } return result; }  int calculate(int n1, int n2);  }
@Test public void anyNumberMultipliedByZeroIsEqualsToZero() { assertEquals(0, multiply.calculate(0, 100)); }
@Test public void anyNumberMultipliedByOneShouldReturnTheSameNumber() { assertEquals(7, multiply.calculate(1, 7)); }
@Test public void fiveTimesElevenEqualsToFiftyFive() { assertEquals(55, multiply.calculate(5, 11)); }
@Test public void shouldTakeIntoAccountNegativeNumbers() { assertEquals(-14, multiply.calculate(-2, 7)); }