package com.mars.test.guava;

import com.google.common.base.Preconditions;
import lombok.extern.slf4j.Slf4j;
import org.junit.Test;

/**
 * Created by mars on 2016/5/31.
 */
@Slf4j
public class TestGuavaPreCondition {



    @Test(expected = NullPointerException.class)
    public void testNullPointerException() {
        Preconditions.checkNotNull(null, "Provided parameter is unacceptably null.");
    }

    @Test(expected = IllegalArgumentException.class)
    public void testDivisorNotZeroException() {
        Preconditions.checkArgument(0 != 0, "Zero divisor not allowed.");
    }

    @Test(expected = IndexOutOfBoundsException.class)
    public void testArrayElement() {
        Preconditions.checkElementIndex(3, new String[]{"Dustin", "Java"}.length, "String array index number");
    }

    @Test(expected = IndexOutOfBoundsException.class)
    public void testCheckPositionIndex() {
        Preconditions.checkPositionIndex(3, new String[]{"Dustin", "Java"}.length, "String array index number");
    }

    @Test(expected = IllegalStateException.class)
    public void testCheckState() {
        Preconditions.checkState(isActive(), "Cannot perform action because not initialized.");
    }


    public boolean isActive() {
        return false;
    }
}

@@ -1199,16 +1199,279 @@
     %7D%0A%0A%0A
+    @Test%0A    public void testPrecondition() throws IllegalStateException %7B%0A        try%7B%0A            Preconditions.checkState(false,%22%E6%B5%8B%E8%AF%95%E9%94%99%E8%AF%AFMsg%22);%0A        %7D catch (IllegalStateException ise)%7B%0A            log.info(%22errorMsg = %22 + ise.getMessage());%0A        %7D%0A    %7D%0A%0A%0A
     publ

add demo code