• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Protocol Buffers - Google's data interchange format
2 // Copyright 2008 Google Inc.  All rights reserved.
3 //
4 // Use of this source code is governed by a BSD-style
5 // license that can be found in the LICENSE file or at
6 // https://developers.google.com/open-source/licenses/bsd
7 
8 // Test that Kokoro is using the expected version of Java.
9 import static com.google.common.truth.Truth.assertWithMessage;
10 
11 import org.junit.Test;
12 import org.junit.runner.RunWith;
13 import org.junit.runners.JUnit4;
14 
15 @RunWith(JUnit4.class)
16 public class JavaVersionTest {
17   @Test
testJavaVersion()18   public void testJavaVersion() throws Exception {
19     String exp = System.getenv("KOKORO_JAVA_VERSION");
20     if(exp == null || exp.isEmpty()) {
21       System.err.println("No kokoro java version found, skipping check");
22       return;
23     }
24     // Java 8's version is read as "1.8"
25     if (exp.equals("8")) exp = "1.8";
26     String version = System.getProperty("java.version");
27     assertWithMessage("Expected Java " + exp + " but found Java " + version)
28         .that(version.startsWith(exp))
29         .isTrue();
30   }
31 }
32