|
| 1 | +package com.devonfw.tools.ide.os; |
| 2 | + |
| 3 | +import java.util.ArrayList; |
| 4 | +import java.util.List; |
| 5 | + |
| 6 | +import org.junit.jupiter.api.Test; |
| 7 | + |
| 8 | +import com.devonfw.tools.ide.context.AbstractIdeContextTest; |
| 9 | +import com.devonfw.tools.ide.context.AbstractIdeTestContext; |
| 10 | +import com.devonfw.tools.ide.context.IdeSlf4jContext; |
| 11 | + |
| 12 | +/** |
| 13 | + * Tests for {@link WindowsHelperImpl}. |
| 14 | + */ |
| 15 | +public class WindowsHelperImplTest extends AbstractIdeContextTest { |
| 16 | + |
| 17 | + /** |
| 18 | + * Tests if the USER_PATH registry entry can be parsed properly. |
| 19 | + */ |
| 20 | + @Test |
| 21 | + public void testWindowsHelperParseRegString() { |
| 22 | + // arrange |
| 23 | + AbstractIdeTestContext context = new IdeSlf4jContext(); |
| 24 | + WindowsHelperImpl helper = new WindowsHelperImpl(context); |
| 25 | + List<String> output = new ArrayList<>(); |
| 26 | + output.add(""); |
| 27 | + output.add("HKEY_CURRENT_USER\\Environment"); |
| 28 | + output.add(" PATH REG_SZ D:\\projects\\_ide\\installation\\bin;"); |
| 29 | + output.add(""); |
| 30 | + // act |
| 31 | + String regString = helper.retrieveRegString("PATH", output); |
| 32 | + // assert |
| 33 | + assertThat(regString).isEqualTo("D:\\projects\\_ide\\installation\\bin;"); |
| 34 | + } |
| 35 | + |
| 36 | + /** |
| 37 | + * Tests if an empty list of outputs will result in null. |
| 38 | + */ |
| 39 | + @Test |
| 40 | + public void testWindowsHelperParseEmptyRegStringReturnsNull() { |
| 41 | + // arrange |
| 42 | + AbstractIdeTestContext context = new IdeSlf4jContext(); |
| 43 | + WindowsHelperImpl helper = new WindowsHelperImpl(context); |
| 44 | + List<String> output = new ArrayList<>(); |
| 45 | + // act |
| 46 | + String regString = helper.retrieveRegString("PATH", output); |
| 47 | + // assert |
| 48 | + assertThat(regString).isNull(); |
| 49 | + } |
| 50 | + |
| 51 | +} |
0 commit comments