### Question:
Environment { public static Environment getEnvironment() { final BackendNodePrincipal principal = JaasUtils.getPrincipal(BackendNodePrincipal.class); final String environmentName = principal.getEnvironmentName(); if (environmentName == null) { throw new NullPointerException("Environment name cannot be null."); } if (StringUtils.isBlank(environmentName)) { throw new IllegalArgumentException("Environment name cannot be blank."); } final String normalizedName = environmentName.toLowerCase(Locale.getDefault()); if (CACHE.containsKey(normalizedName)) { return CACHE.get(normalizedName); } final Environment env = new Environment(environmentName); CACHE.put(normalizedName, env); return env; } Environment(final String environmentName); static Environment getEnvironment(); String getCclSource(); String getCclUserDir(); String getCerInstall(); String getCerProc(); String getCerTemp(); String getEnvironmentName();  }### Answer:
@Test public void testGetEnvironmentCached() throws Exception { final Environment env = Environment.getEnvironment(); final Environment otherEnv = Environment.getEnvironment(); assertThat(env).isSameAs(otherEnv); }
@Test public void testGetEnvironmentNullName() { final BackendNodePrincipal badPrincipal = mock(BackendNodePrincipal.class); when(JaasUtils.getPrincipal(BackendNodePrincipal.class)).thenReturn(badPrincipal); NullPointerException e = assertThrows(NullPointerException.class, () -> { Environment.getEnvironment(); }); assertThat(e.getMessage()).isEqualTo("Environment name cannot be null."); }
@Test public void testSkipEnvset() throws Exception { final TerminalProperties terminalProperties = TerminalProperties.getNewBuilder() .setOsPromptPattern("osPromptPattern").setSkipEnvset(true).build(); mockStatic(TerminalProperties.class); when(TerminalProperties.getGlobalTerminalProperties()).thenReturn(terminalProperties); final ArgumentCaptor<TerminalProperties> captorTerminalProperties = ArgumentCaptor .forClass(TerminalProperties.class); Environment.getEnvironment(); verify(sshTerminal, times(1)).executeCommandGroups(argumentCaptorCommandExpectationGroupList.capture()); final List<List<CommandExpectationGroup>> commandExpectationsGroupsList = argumentCaptorCommandExpectationGroupList .getAllValues(); assertThat(commandExpectationsGroupsList.size()).isEqualTo(1); for (List<CommandExpectationGroup> commandExpectationsGroups : commandExpectationsGroupsList) { for (CommandExpectationGroup commandExpectationsGroup : commandExpectationsGroups) { for (String command : commandExpectationsGroup.getCommands()) { assertThat(command).doesNotContain("envset"); } } } }
@Test public void testNoSkipEnvset() throws Exception { Environment.getEnvironment(); verify(sshTerminal, times(1)).executeCommandGroups(argumentCaptorCommandExpectationGroupList.capture()); final List<List<CommandExpectationGroup>> commandExpectationsGroupsList = argumentCaptorCommandExpectationGroupList .getAllValues(); assertThat(commandExpectationsGroupsList.size()).isEqualTo(1); assertThat(commandExpectationsGroupsList.get(0).get(0).getCommands().size()).isEqualTo(1); assertThat(commandExpectationsGroupsList.get(0).get(0).getCommands().get(0)).contains("envset"); }