package net.oldev.aBrightnessQS;

import org.junit.Test;

import static org.junit.Assert.*;
import static net.oldev.aBrightnessQS.SysBrightnessToUISliderPctConverter.*;

public class SysBrightnessToUISliderPctConverterTest {

    public static class PositiveTest {

        // Test driver for positive tests,
        // starting with uiPct (0 - 100)
        private void tWithUiPct(int uiPctInTest, int sysBrightnessExpected) throws Exception {
            final int sysBrightnessActual = uiPctToSysBrightness(uiPctInTest);
            assertEquals("uiPct to sysBrightness conversion:",  sysBrightnessExpected, sysBrightnessActual);

            // Do reverse conversion test
            //  The exepected result should be the uiPct supplied by the caller
            final int uiPctExpected = uiPctInTest; 
            final int uiPctConverted = sysBrightnessToUiPct(sysBrightnessActual);

            assertEquals("sysBrightness to uiPct conversion:", uiPctExpected, uiPctConverted);

        }

        @Test
        public void uiAt0() throws Exception {
            tWithUiPct(0, 0);
        }

        @Test
        public void uiAt20() throws Exception {
            tWithUiPct(20, 128);
        }

        @Test
        public void uiAt25() throws Exception {
            tWithUiPct(25, 141);
        }
        @Test
        public void uiAt50() throws Exception {
            tWithUiPct(50, 190);
        }

        @Test
        public void uiAt75() throws Exception {
            tWithUiPct(75, 225);
        }

        @Test
        public void uiAt100() throws Exception {
            tWithUiPct(100, 255);
        }
    }
  
    public static class NegativeTest {

        private void negt4UI(int uiPct) throws Exception {
            try {
                int sysBrightnessActual = uiPctToSysBrightness(uiPct);
                fail("Test for illegal uiPct failed. uiPct for test:<" + uiPct + ">.  expected:<IllegalArgumentException> but was:<" +  sysBrightnessActual +">");
            } catch (IllegalArgumentException iae) {
            }
        }

        private void negt4SysBrightness(int sysBrightness) throws Exception {
            try {
                int uiPctActual = sysBrightnessToUiPct(sysBrightness);
                fail("Test for illegal sysBrightness failed. sysBrightness for test:<" + sysBrightness + ">.  expected:<IllegalArgumentException> but was:<" +  sysBrightness +">");
            } catch (IllegalArgumentException iae) {
            }
        }

        @Test
        public void negUIAtNeg() throws Exception {
            negt4UI(-1);
        }

        @Test
        public void negUIAt101() throws Exception {
            negt4UI(101);
        }

        @Test
        public void negSysBrightnessAtNeg() throws Exception {
            negt4SysBrightness(-1);
        }

        @Test
        public void negSysBrightnessAt256() throws Exception {
            negt4SysBrightness(256);
        }
    }

}
@@ -38,22 +38,251 @@
 ort 
-org.junit.Test
+java.util.Arrays;%0Aimport java.util.Collection;%0A%0Aimport org.junit.Test;%0Aimport org.junit.runner.RunWith;%0Aimport org.junit.runners.Parameterized;%0Aimport org.junit.runners.Parameterized.Parameter;%0Aimport org.junit.runners.Parameterized.Parameters
 ;%0A%0Ai
@@ -444,24 +444,58 @@
 rterTest %7B%0A%0A
+    @RunWith(Parameterized.class)%0A
     public s
@@ -534,1363 +534,1186 @@
     
-// Test driver for positive tests,%0A        // starting with uiPct (0 - 100)%0A        private void tWithUiPct(int uiPctInTest, int sysBrightnessExpected) throws Exception %7B%0A            final int sysBrightnessActual = uiPctToSysBrightness(uiPctInTest);%0A            assertEquals(%22uiPct to sysBrightness conversion:%22,  sysBrightnessExpected, sysBrightnessActual);%0A%0A            // Do reverse conversion test%0A            //  The exepected result should be the uiPct supplied by the caller%0A            final int uiPctExpected = uiPctInTest; %0A            final int uiPctConverted = sysBrightnessToUiPct(sysBrightnessActual);%0A%0A            assertEquals(%22sysBrightness to uiPct conversion:%22, uiPctExpected, uiPctConverted);%0A%0A        %7D%0A%0A        @Test%0A        public void uiAt0() throws Exception %7B%0A            tWithUiPct(0, 0);%0A        %7D%0A%0A        @Test%0A        public void uiAt20() throws Exception %7B%0A            tWithUiPct(20, 128);%0A        %7D%0A%0A        @Test%0A        public void uiAt25() throws Exception %7B%0A            tWithUiPct(25, 141);%0A        %7D%0A        @Test%0A        public void uiAt50() throws Exception %7B%0A            tWithUiPct(50, 190);%0A        %7D%0A%0A        @Test%0A        public void uiAt75() throws Exception %7B%0A            tWithUiPct(75, 225);%0A        %7D%0A%0A        @Test%0A        public void uiAt100() throws Exception %7B%0A            tWithUiPct(100, 255);%0A        %7D
+@Parameters(name = %22%7Bindex%7D: uiPctToSysBrightness(%7B0%7D)=%7B1%7D%22)%0A        public static Iterable%3CObject%5B%5D%3E data() %7B%0A            return Arrays.asList(new Object%5B%5D%5B%5D %7B %0A                    %7B 0, 0 %7D, %7B 20, 128 %7D, %7B 25, 141 %7D, %0A                    %7B 50, 190 %7D, %7B 75, 225 %7D, %7B 100, 255 %7D%0A            %7D);%0A        %7D%0A%0A        @Parameter%0A        public int uiPctInTest;%0A%0A        @Parameter(1)%0A        public int sysBrightnessExpected;%0A%0A        // Test driver for positive tests.%0A        // Given a uiPct (0 - 100), convert to sysBrightness;%0A        // then convert it back.%0A        @Test%0A        public void tWithUiPct() throws Exception %7B%0A            final int sysBrightnessActual = uiPctToSysBrightness(uiPctInTest);%0A            assertEquals(%22uiPct to sysBrightness conversion:%22,  sysBrightnessExpected, sysBrightnessActual);%0A%0A            // Do reverse conversion test%0A            //  The exepected result should be the uiPct supplied by the caller%0A            final int uiPctExpected = uiPctInTest; %0A            final int uiPctConverted = sysBrightnessToUiPct(sysBrightnessActual);%0A%0A            assertEquals(%22sysBrightness to uiPct conversion:%22, uiPctExpected, uiPctConverted);%0A%0A        %7D%0A
 %0A   

unit test refactor: parametrize positive test