diff options
Diffstat (limited to 'src/modules/java.rs')
-rw-r--r-- | src/modules/java.rs | 28 |
1 files changed, 27 insertions, 1 deletions
diff --git a/src/modules/java.rs b/src/modules/java.rs index 9fa1789b2..26745d7d5 100644 --- a/src/modules/java.rs +++ b/src/modules/java.rs @@ -91,7 +91,7 @@ fn parse_java_version(java_version: &str) -> Option<String> { #[cfg(test)] mod tests { use super::*; - use crate::test::ModuleRenderer; + use crate::{test::ModuleRenderer, utils::CommandOutput}; use ansi_term::Color; use std::fs::File; use std::io; @@ -180,6 +180,32 @@ mod tests { } #[test] + fn folder_with_java_file_preview() -> io::Result<()> { + let dir = tempfile::tempdir()?; + File::create(dir.path().join("Main.java"))?.sync_all()?; + let actual = ModuleRenderer::new("java").cmd("java -Xinternalversion", Some(CommandOutput { + stdout: "OpenJDK 64-Bit Server VM (16+14) for bsd-aarch64 JRE (16+14), built on Jan 17 2021 07:19:47 by \"brew\" with clang Apple LLVM 12.0.0 (clang-1200.0.32.28)\n".to_owned(), + stderr: "".to_owned() + })).path(dir.path()).collect(); + let expected = Some(format!("via {}", Color::Red.dimmed().paint("☕ v16 "))); + assert_eq!(expected, actual); + dir.close() + } + + #[test] + fn folder_with_java_file_no_java_installed() -> io::Result<()> { + let dir = tempfile::tempdir()?; + File::create(dir.path().join("Main.java"))?.sync_all()?; + let actual = ModuleRenderer::new("java") + .cmd("java -Xinternalversion", None) + .path(dir.path()) + .collect(); + let expected = Some(format!("via {}", Color::Red.dimmed().paint("☕ "))); + assert_eq!(expected, actual); + dir.close() + } + + #[test] fn folder_with_class_file() -> io::Result<()> { let dir = tempfile::tempdir()?; File::create(dir.path().join("Main.class"))?.sync_all()?; |