package org.codelabor.example.findbugs;

import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public class IcastIdivCastToDoubleTest {

	private static final Logger logger = LoggerFactory.getLogger(IcastIdivCastToDoubleTest.class);

	@BeforeClass
	public static void setUpBeforeClass() throws Exception {
	}

	@AfterClass
	public static void tearDownAfterClass() throws Exception {
	}

	@Before
	public void setUp() throws Exception {
	}

	@After
	public void tearDown() throws Exception {
	}

	@Test
	public void testRight1() {
		int x = 2;
		int y = 5;
		double value1 = (double) x / y;
		logger.debug("value1: {}", value1);
	}

	@Test
	public void testRight2() {
		int x = 2;
		int y = 5;
		double value1 = x / (double) y;
		logger.debug("value1: {}", value1);
	}

	@Test
	public void testWrong() {
		int x = 2;
		int y = 5;
		double value1 = x / y;
		logger.debug("value1: {}", value1);
	}

}

@@ -233,16 +233,736 @@
 ory;%0D%0A%0D%0A
+/**%0D%0A * %3Ch1%3EICAST_IDIV_CAST_TO_DOUBLE%3C/h1%3E%0D%0A * %3Cp%3E%0D%0A * This code casts the result of an integral division (e.g., int or long division) operation to double or float. Doing division on integers truncates the result%0D%0A * to the integer value closest to zero. The fact that the result was cast to double suggests that this precision should have been retained. What was probably%0D%0A * meant was to cast one or both of the operands to double before performing the division. Here is an example:%0D%0A * %3C/p%3E%0D%0A *%0D%0A * %3Cpre%3E%0D%0A * int x = 2;%0D%0A * int y = 5;%0D%0A * // Wrong: yields result 0.0%0D%0A * double value1 = x / y;%0D%0A *%0D%0A * // Right: yields result 0.4%0D%0A * double value2 = x / (double) y;%0D%0A * %3C/pre%3E%0D%0A *%0D%0A * @author Shin Sang-jae%0D%0A *%0D%0A */%0D%0A
 public c

comment updated.