Code Snippet

Just another Code Snippet site

Random Post :




[JUnit] Parametrized Test

Need Junit 4.11


@RunWith(Parameterized.class)
public class ParametrizedTest {

    /** The Logger. */
    private static final Logger LOGGER = LoggerFactory.getLogger(ParametrizedTest.class);

    /** XML Input Folder. */
    private static File inputFolder = new File("target/classes/input");

    /** XML Target Folder. */
    private static File targetFolder = new File("target/test-classes/output");

    private final File file;
    private final String param;

    /**
     * Default constructor.
     */
    public ParametrizedTest(File file, String param) {
        this.file = file;
        this.param = param;
    }

    /**
     * Prepare env. for test run.
     * 
     * @throws IOException
     */
    public static void initClass() throws IOException {
        LOGGER.info("initClass()");

        targetFolder.delete();
        targetFolder.mkdirs();
    }

    @Parameters(name = "{1}")
    public static Collection<Object[]> data() throws IOException {
        initClass();

        return getAllFiles();
    }

    /**
     * Test to run
     */
    @Test
    public void test_1() {
        LOGGER.warn("------------------------------------------------------------------------");
        LOGGER.warn("Processing : " + param);

        Assert.assertTrue(true);
    }

    /**
     * List files to process.
     * 
     * @return List files to process.
     */
    public static Collection<Object[]> getAllFiles() {
        LOGGER.info("Initialize collection");
        List<Object[]> result = new ArrayList<Object[]>();

        for (File template : targetFolder.listFiles()) {
            result.add(new Object[] { template, template.getName() });
        }

        return result;
    }
}

, ,

Increasing the Base Device Size on Docker Daemon Restart 

Sometime back I wrote a feature for docker to allow expanding Base device size on daemon restart. This feature has been included in Docker 1.10, so you can try it out now.Before we jump further into this article, I would like to point out that this feature is only available for devicemapper storage and does not apply to other storage drivers like overlay, btrfs, aufs, etc.

Source: Increasing the Base Device Size on Docker Daemon Restart — Project Atomic

[JUnit] Test System.err and System.out content

public class TestClass {

    @Rule
    public final StandardErrorStreamLog logErr = new StandardErrorStreamLog();
 
    @Rule
    public final StandardOutputStreamLog log = new StandardOutputStreamLog();

    @Test
    public void test1()  {
	System.err.print("hello world");
	assertEquals("hello world", logErr.getLog());
    }
}

Maven dependency :

<dependency>
  <groupId>com.github.stefanbirkner</groupId>
  <artifactId>system-rules</artifactId>
  <version>1.5.0</version>
</dependency>

Previous Posts Next posts