Skip to content

Commit d701bd5

Browse files
Tom-WillemsenDominicOram
authored andcommitted
Add test
1 parent 042e811 commit d701bd5

File tree

3 files changed

+40
-4
lines changed
  • base
    • uk.ac.stfc.isis.ibex.ui.configserver.tests
    • uk.ac.stfc.isis.ibex.ui.configserver/src/uk/ac/stfc/isis/ibex/ui/configserver/editing/iocs/dialog

3 files changed

+40
-4
lines changed

base/uk.ac.stfc.isis.ibex.ui.configserver.tests/META-INF/MANIFEST.MF

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,5 +12,6 @@ Require-Bundle: org.junit;bundle-version="4.11.0",
1212
org.hamcrest.generator;bundle-version="1.3.0",
1313
org.hamcrest.integration;bundle-version="1.3.0",
1414
org.hamcrest.library;bundle-version="1.3.0",
15-
org.hamcrest.text;bundle-version="1.1.0"
15+
org.hamcrest.text;bundle-version="1.1.0",
16+
uk.ac.stfc.isis.ibex.configserver
1617
Automatic-Module-Name: uk.ac.stfc.isis.ibex.ui.configserver.tests

base/uk.ac.stfc.isis.ibex.ui.configserver.tests/src/uk/ac/stfc/isis/ibex/ui/configserver/editing/iocs/tests/TempIocTest.java

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,14 @@
2323

2424
import static org.junit.Assert.*;
2525

26+
import java.util.List;
27+
2628
import org.junit.Before;
2729
import org.junit.Test;
2830

2931
import uk.ac.stfc.isis.ibex.configserver.configuration.Ioc;
32+
import uk.ac.stfc.isis.ibex.configserver.configuration.Macro;
33+
import uk.ac.stfc.isis.ibex.configserver.configuration.Macro.HasDefault;
3034
import uk.ac.stfc.isis.ibex.configserver.configuration.SimLevel;
3135
import uk.ac.stfc.isis.ibex.configserver.editing.EditableIoc;
3236
import uk.ac.stfc.isis.ibex.ui.configserver.editing.iocs.dialog.TempEditableIoc;
@@ -158,4 +162,32 @@ public void GIVEN_ioc_set_WHEN_changing_viewmodel_values_and_saving_ioc_THEN_ioc
158162
// Assert
159163
assertEquals(expected, actual);
160164
}
165+
166+
@Test
167+
public void GIVEN_ioc_set_WHEN_changing_macros_THEN_macros_do_not_write_through_to_underlying_ioc_until_saved() {
168+
var testMacros = List.of(
169+
new Macro("name_ignored", "inital_value", "", "", "", HasDefault.NO)
170+
);
171+
172+
var underlyingIoc = new EditableIoc(new Ioc(""), "");
173+
underlyingIoc.setMacros(testMacros);
174+
175+
var tempEditableIoc = new TempEditableIoc(underlyingIoc);
176+
177+
// Set value in the Temp IOC
178+
for (Macro macro : tempEditableIoc.getMacros()) {
179+
macro.setValue("some_new_value");
180+
}
181+
182+
// Before saving the temp IOC, the value should not have propagated down to the underlying IOC.
183+
for (Macro macro : underlyingIoc.getMacros()) {
184+
assertEquals("inital_value", macro.getValue());
185+
}
186+
187+
// After saving, the new value should be seen in the underlying IOC.
188+
tempEditableIoc.saveIoc();
189+
for (Macro macro : underlyingIoc.getMacros()) {
190+
assertEquals("some_new_value", macro.getValue());
191+
}
192+
}
161193
}

base/uk.ac.stfc.isis.ibex.ui.configserver/src/uk/ac/stfc/isis/ibex/ui/configserver/editing/iocs/dialog/TempEditableIoc.java

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,6 @@
2323

2424
import java.util.ArrayList;
2525
import java.util.Collection;
26-
import java.util.Collections;
27-
import java.util.stream.Collectors;
28-
2926
import uk.ac.stfc.isis.ibex.configserver.configuration.Macro;
3027
import uk.ac.stfc.isis.ibex.configserver.editing.EditableIoc;
3128

@@ -50,11 +47,17 @@ public TempEditableIoc(EditableIoc ioc) {
5047
this.macros = deepCopyMacros(editingIoc.getMacros());
5148
}
5249

50+
/**
51+
* {@inheritDoc}
52+
*/
5353
@Override
5454
public Collection<Macro> getMacros() {
5555
return macros;
5656
}
5757

58+
/**
59+
* {@inheritDoc}
60+
*/
5861
@Override
5962
public void setMacros(final Collection<Macro> macros) {
6063
this.macros = deepCopyMacros(macros);

0 commit comments

Comments
 (0)