2012-10-09 28 views
2

今天,目前的番石榴版本似乎是:番石榴TESTLIB未來版本的JAR

release is 13.0.1, August 3, 2012.

,但我檢查了源斷:

git clone https://code.google.com/p/guava-libraries/

,並得到了由好奇什麼看起來像極其對我有用的測試工具:

http://code.google.com/p/guava-libraries/source/browse/guava-testlib/src/com/google/common/testing/NullPointerTester.java

我想確認我所有的方法厭惡null絲毫不亞於Doug Lea的(http://gee.cs.oswego.edu/dl/html/vita.html)似乎做,除非約書亞布洛赫misquotes他(http://www.youtube.com/watch?v=ZeO_J2OcHYM#t=26m35s)在被「空敵意」。

無論如何,NullPointerTester.java似乎是完美的,所以我試圖將其構建到我的項目中。

依賴關係(NullPointerTester - >Invokable<?, ?>, - > ...例如)在我遇到類@since 14.0時基本上屬於未來版本。

建立下一個/未來版本番石榴的獨立JAR的最佳方式是什麼?所有的依賴關係都被照顧好了嗎?注:來源似乎是「全」上git ...


你可以停止閱讀這裏。

我迫不及待地做這樣的東西,這是真的很酷,我認爲:

注:缺少了什麼是「安全檢查」,如「如果構造函數已被設爲私有,請檢查我無法反射 - 無論如何調用它...

如果我是一個更好的編碼器,我會貢獻,但這是我所能做的,它是非常差的,儘管意圖應該清理R'

static boolean isDefaultConstructorDisabled(Class<?> type) { 
    boolean isDefaultConstructorDisabled = false; 
    Constructor<?>[] declaredConstructors = type.getDeclaredConstructors(); 
    Constructor<?> defaultContructor = declaredConstructors[0]; 
    defaultContructor.setAccessible(true); 
    try { 
    defaultContructor.newInstance(); 
    } catch (InvocationTargetException invocationTargetException) { 
    Throwable cause = invocationTargetException.getCause(); 
    if (cause instanceof UnsupportedOperationException 
     && cause.getMessage().contains(
      ErrorMessage.DefaultConstructor.DISABLED)) { 
     isDefaultConstructorDisabled = true; 
    } 
    } catch (Throwable throwable) { 
    throwable.printStackTrace(); 
    } 
    return isDefaultConstructorDisabled; 
} 

回答

1

如果克隆整個番石榴庫,那麼v13.0.1標籤將有番石榴TESTLIB,特別NullPointerTester,爲13.0.1,這應該工作 - 沒有?

2

你試過在Maven看嗎?

http://search.maven.org/#browse%7C-723200679

我覺得番石榴TESTLIB就是包含NullPointerTester。你可以抓住13.0.1罐子。

http://search.maven.org/#browse%7C1590928164

+0

我有'guava-13.0.1.jar'文件,'guava-testlib'的某些依賴關係,它甚至不能在13.0.1中導出,雖然是'@since 14' ...(例如' Invokable')。我必須承認,我不知道如何在基礎之外使用Maven。 – Robottinosino

+0

NullPointerTester已經存在了一段時間。 13.0.1 jar不應該依賴任何@since 14的東西。你在git中看到的是最新的,它包括自13.0.1發佈之後的變化,包括他們讓NullPointerTester使用Invokable(Aug 31)的變化。你是否試圖在你的代碼中使用它,而不是編譯? –

+0

那麼,即使guava-13.0.1.jar在我的項目(或CLI中的類路徑)中,我甚至不會在可訪問的API上「看到」NullPointerTester ... ...您是否曾經使用過類? – Robottinosino